DefaultSiteReliabilityChecker implements SiteReliabilityChecker { @Override public boolean isSiteHealthy(AbstractInstanceEvent event) { if(config.isConsoleSiteUnstable()) { return false; } RedisInstanceInfo info = event.getInstance().getRedisInstanceInfo(); List<HostPort> totalRedis = metaCache.getAllActiveRedisOfDc(FoundationService.DEFAULT.getDataCenter(), info.getDcId()); int errorRedis = getErrorRedis(totalRedis); return errorRedis < totalRedis.size()/2; }  @Override boolean isSiteHealthy(AbstractInstanceEvent event); @VisibleForTesting DefaultSiteReliabilityChecker setMetaCache(MetaCache metaCache);  }
@Test public void testCheckWithSiteDown() throws Exception { when(defaultDelayPingActionCollector.getState(any(HostPort.class))).thenReturn(HEALTH_STATE.DOWN); boolean result = checker.isSiteHealthy(new InstanceDown(instance)); Assert.assertFalse(result); }
@Test public void testConfigSetConsoleSiteUnstable() { when(defaultDelayPingActionCollector.getState(any(HostPort.class))).thenReturn(HEALTH_STATE.INSTANCEUP); when(consoleConfig.isConsoleSiteUnstable()).thenReturn(true).thenReturn(false); Assert.assertFalse(checker.isSiteHealthy(new InstanceDown(instance))); Assert.assertTrue(checker.isSiteHealthy(new InstanceDown(instance))); }
@Test public void testCheckWithSiteOk() { when(defaultDelayPingActionCollector.getState(any(HostPort.class))).thenReturn(HEALTH_STATE.HEALTHY); Assert.assertTrue(checker.isSiteHealthy(new InstanceDown(instance))); }