@Test public void testWarn() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.warnWithError("foo", new Exception("FOO")); assertFalse("foo is not found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); final List<NodeHealthStat> nodeHealthStats = healthService.loadNodes(); assertEquals(1, nodeHealthStats.size()); assertEquals("foo", nodeHealthStats.get(0).getName()); assertEquals(HealthStatus.WARN, nodeHealthStats.get(0).getStatus()); assertEquals(HealthFailReason.ERROR, nodeHealthStats.get(0).getReason()); assertEquals("FOO", nodeHealthStats.get(0).getError().get().getMessage()); }
@Test public void testFail() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.failWithError("foo", new Exception("FOO")); assertFalse("foo is not found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); final List<NodeHealthStat> nodeHealthStats = healthService.loadNodes(); assertEquals(1, nodeHealthStats.size()); assertEquals("foo", nodeHealthStats.get(0).getName()); assertEquals(HealthStatus.FAIL, nodeHealthStats.get(0).getStatus()); assertEquals(HealthFailReason.ERROR, nodeHealthStats.get(0).getReason()); assertEquals("FOO", nodeHealthStats.get(0).getError().get().getMessage()); }
@Test public void testWarnNoError() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.warnWithReason("foo", HealthFailReason.TIMEOUT); assertFalse("foo is not found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); final List<NodeHealthStat> nodeHealthStats = healthService.loadNodes(); assertEquals(1, nodeHealthStats.size()); assertEquals("foo", nodeHealthStats.get(0).getName()); assertEquals(HealthStatus.WARN, nodeHealthStats.get(0).getStatus()); assertEquals(HealthFailReason.TIMEOUT, nodeHealthStats.get(0).getReason()); assertEquals(false, nodeHealthStats.get(0).getError().isPresent()); }