/** * Read annotation. * * @param callback callback */ @RequestMapping(value = "/all-nodes/", summary = "Finds all nodes that have registered with health system", description = "Finds all service actors and endpoints that are registered with the health system." + "Each node will periodically check in with the health system." + "Nodes can mark themselves unhealthy or just fail to check in", returnDescription = "List of node names") public void findAllNodes(final Callback<List<String>> callback) { healthService.findAllNodes(callback::accept); healthService.clientProxyFlush(); }
@Test public void testRegister() throws Exception { final AtomicBoolean result = new AtomicBoolean(); healthService.register("foo", 1, TimeUnit.SECONDS); final CountDownLatch countDownLatch = new CountDownLatch(1); healthService.findAllNodes(names -> { result.set(names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch.countDown(); } ); countDownLatch.await(10, TimeUnit.SECONDS); assertTrue("foo is found", result.get()); healthService.unregister("foo"); final CountDownLatch countDownLatch2 = new CountDownLatch(1); result.set(false); healthService.findAllNodes(names -> { result.set(!names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch2.countDown(); } ); countDownLatch2.await(10, TimeUnit.SECONDS); }
@Test public void forceTTLExpire() throws Exception { final CountDownLatch countDownLatch = new CountDownLatch(1); final AtomicBoolean result = new AtomicBoolean(); healthService.register("foo", 1, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.PASS); healthService.findAllNodes(names -> { result.set(names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch.countDown(); } ); countDownLatch.await(10, TimeUnit.SECONDS); assertTrue("foo is found", result.get()); timer.setTime(); timer.minutes(1); Sys.sleep(1000); healthService.clientProxyFlush(); final CountDownLatch countDownLatch2 = new CountDownLatch(1); result.set(false); healthService.findHealthyNodes(names -> { result.set(!names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch2.countDown(); } ); countDownLatch2.await(10, TimeUnit.SECONDS); assertTrue("foo should not be found", result.get()); }