AbstractHealthEventHandler implements HealthEventHandler { @VisibleForTesting protected void markdown(final AbstractInstanceEvent event) { final RedisInstanceInfo info = event.getInstance().getRedisInstanceInfo(); boolean siteReliable = checker.isSiteHealthy(event); if(siteReliable) { doMarkDown(event); } else { logger.warn("[site-down][not-mark-down] {}", info); } }  @SuppressWarnings("unchecked") @Override void handle(AbstractInstanceEvent event); @VisibleForTesting void setChecker(SiteReliabilityChecker checker);  }
@Test public void testMarkDown() { when(checker.isSiteHealthy(any(AbstractInstanceEvent.class))).thenReturn(false); sickHandler.markdown(new InstanceSick(instance)); verify(finalStateSetterManager, never()).set(any(ClusterShardHostPort.class), anyBoolean()); when(checker.isSiteHealthy(any(AbstractInstanceEvent.class))).thenReturn(true); RedisInstanceInfo info = instance.getRedisInstanceInfo(); when(consoleConfig.getDelayedMarkDownDcClusters()).thenReturn(Sets.newHashSet(new DcClusterDelayMarkDown() .setDcId(info.getDcId()).setClusterId(info.getClusterId()).setDelaySecond(1))); sickHandler.markdown(new InstanceSick(instance)); sleep(1500); verify(finalStateSetterManager, times(1)).set(any(), any()); when(consoleConfig.getDelayedMarkDownDcClusters()).thenReturn(null); when(checker.isSiteHealthy(any(AbstractInstanceEvent.class))).thenReturn(true); sickHandler.markdown(new InstanceSick(instance)); verify(finalStateSetterManager, times(2)).set(any(ClusterShardHostPort.class), anyBoolean()); }
@Test public void testMarkDownForInstanceDown() { when(checker.isSiteHealthy(any(AbstractInstanceEvent.class))).thenReturn(false); downHandler.markdown(new InstanceDown(instance)); verify(finalStateSetterManager, never()).set(any(), anyBoolean()); when(checker.isSiteHealthy(any(AbstractInstanceEvent.class))).thenReturn(true); downHandler.markdown(new InstanceDown(instance)); verify(finalStateSetterManager, times(1)).set(any(), anyBoolean()); }