public void fail() { healthService.checkIn("no exist", HealthStatus.PASS); }
@Test public void transitionFromPassToFail() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); assertTrue("foo is found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); healthService.checkIn("foo", HealthStatus.FAIL); assertTrue("foo is NOT found among the healthy ", !healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); }
@Test public void allOk() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); healthService.register("bar", 1, TimeUnit.SECONDS); healthService.checkIn("bar", HealthStatus.PASS); healthService.register("baz", 1, TimeUnit.SECONDS); healthService.checkIn("baz", HealthStatus.PASS); assertTrue(healthService.ok()); healthService.checkIn("baz", HealthStatus.FAIL); assertTrue(!healthService.ok()); }
@Test public void testCheckInOkUsingCheckIn() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); assertTrue("foo is found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); }
@Test public void forceTTLExpireThenRecover() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); assertTrue("foo is found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); timer.setTime(); timer.minutes(1); healthService.callProcess(); assertTrue("foo is NOT found among the healthy ", !healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); healthService.checkIn("foo", HealthStatus.FAIL); assertTrue("foo is NOT found among the healthy ", !healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); healthService.checkIn("foo", HealthStatus.PASS); healthService.callProcess(); assertTrue("foo is found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); }
@Test public void forceTTLExpire() throws Exception { healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); assertTrue("foo is found among the healthy ", healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); timer.setTime(); timer.minutes(1); healthService.callProcess(); assertTrue("foo is NOT found among the healthy ", !healthService.findHealthyNodes().stream().anyMatch(s -> s.equals("foo"))); }