private void check() { now = timer.now(); long duration = now - lastCheckTime; if (duration > checkInIntervalMS) { lastCheckTime = now; final boolean failing = healthManager.isFailing(); if (!failing) { healthServiceAsync.checkInOk(serviceName); } else { healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL); } healthServiceAsync.clientProxyFlush(); } }
@Test public void fail() { /* This is why we need to log it. */ healthService.checkIn("no exist", HealthStatus.PASS); }
private void check() { now = timer.now(); long duration = now - lastCheckTime; if (duration > checkInIntervalMS) { lastCheckTime = now; final boolean failing = healthManager.isFailing(); if (!failing) { healthServiceAsync.checkInOk(serviceName); } else { healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL); } healthServiceAsync.clientProxyFlush(); } }
@Test public void transitionFromPassToFail() 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.findHealthyNodes(names -> { result.set(names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch.countDown(); } ); countDownLatch.await(10, TimeUnit.SECONDS); healthService.checkIn("foo", HealthStatus.FAIL); 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 is NOT found among the healthy ", result.get()); }
private void check() { now = timer.now(); long duration = now - lastCheckTime; if (duration > checkInIntervalMS) { lastCheckTime = now; final ServiceQueue serviceQueue = ServiceContext.serviceContext().currentService(); boolean failing = serviceQueue.failing(); if (!failing) { healthServiceAsync.checkInOk(serviceName); } else { healthServiceAsync.checkIn(serviceName, HealthStatus.FAIL); } healthServiceAsync.clientProxyFlush(); } }
@Test public void testCheckInOkUsingCheckIn() 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.findHealthyNodes(names -> { result.set(names.stream().anyMatch(s -> s.equals("foo"))); countDownLatch.countDown(); } ); ServiceProxyUtils.flushServiceProxy(healthService); countDownLatch.await(10, TimeUnit.SECONDS); assertTrue("foo is found among the healthy ", result.get()); }
@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()); }
@Test public void testFindAllHealthyNodes() throws Exception { adminBuilder.getHealthService().checkIn("foo", HealthStatus.FAIL); adminBuilder.getHealthService().clientProxyFlush(); Sys.sleep(1000); HttpTextResponse httpResponse = httpClient.get("/__admin/all-nodes/"); assertTrue(httpResponse.code() == 200); assertEquals("[\"bar\",\"foo\",\"baz\"]", httpResponse.body()); } }