private void mockRehashInProgress(String cacheName, Cache mockedCache, AdvancedCache mockedAdvancedCache, DistributionManager mockedDistributionManager) { when(mockedCacheManager.getCache(cacheName, false)).thenReturn(mockedCache); when(mockedCache.getAdvancedCache()).thenReturn(mockedAdvancedCache); when(mockedCache.getStatus()).thenReturn(INSTANTIATED); when(mockedAdvancedCache.getDistributionManager()).thenReturn(mockedDistributionManager); when(mockedDistributionManager.isRehashInProgress()).thenReturn(true); }
@Test public void testRebalancingStatusOnRebalance() throws Exception { //given CacheImpl<Object, Object> cache = spy(new CacheImpl<>("test")); DistributionManager distributionManagerMock = mock(DistributionManager.class); doReturn(true).when(distributionManagerMock).isRehashInProgress(); doReturn(distributionManagerMock).when(cache).getDistributionManager(); doReturn(ComponentStatus.RUNNING).when(cache).getStatus(); doReturn(AvailabilityMode.AVAILABLE).when(cache).getAvailability(); CacheHealth cacheHealth = new CacheHealthImpl(cache); //when HealthStatus status = cacheHealth.getStatus(); //then assertEquals(status, HealthStatus.REBALANCING); }
@Test public void testHealthyStatus() throws Exception { //given CacheImpl<Object, Object> cache = spy(new CacheImpl<>("test")); DistributionManager distributionManagerMock = mock(DistributionManager.class); doReturn(false).when(distributionManagerMock).isRehashInProgress(); doReturn(distributionManagerMock).when(cache).getDistributionManager(); doReturn(ComponentStatus.RUNNING).when(cache).getStatus(); doReturn(AvailabilityMode.AVAILABLE).when(cache).getAvailability(); CacheHealth cacheHealth = new CacheHealthImpl(cache); //when HealthStatus status = cacheHealth.getStatus(); //then assertEquals(status, HealthStatus.HEALTHY); }
if ((manager != null) && !manager.isRehashInProgress())