MemcachedReactiveHealthIndicator extends AbstractReactiveHealthIndicator { @Override protected Mono<Health> doHealthCheck(final Health.Builder builder) { return trySetOperation().zipWith(tryGetOperation(), this::isSuccess) .map(success -> success ? builder.up().build() : builder.outOfService().build()); } MemcachedReactiveHealthIndicator(final MemcachedClient client);   }
@Test void up() throws Exception { doReturn(setFuture).when(client).set("__com.netflix.evcache.server.healthcheck", 300, "Greed is good!"); doReturn(true).when(setFuture).get(5, TimeUnit.SECONDS); doReturn(getFuture).when(client).asyncGet("__com.netflix.evcache.server.healthcheck"); doReturn("Greed is good!").when(getFuture).get(5, TimeUnit.SECONDS); StepVerifier.create(indicator.doHealthCheck(builder)) .expectNext(new Health.Builder().up().build()) .verifyComplete(); }
@Test void should_be_outOfService_when_set_operation_is_false() throws Exception { doReturn(setFuture).when(client).set("__com.netflix.evcache.server.healthcheck", 300, "Greed is good!"); doReturn(false).when(setFuture).get(5, TimeUnit.SECONDS); doReturn(getFuture).when(client).asyncGet("__com.netflix.evcache.server.healthcheck"); doReturn("Greed is good!").when(getFuture).get(5, TimeUnit.SECONDS); StepVerifier.create(indicator.doHealthCheck(builder)) .expectNext(new Health.Builder().outOfService().build()) .verifyComplete(); }
@Test void should_be_outOfService_when_get_value_is_not_matched() throws Exception { doReturn(setFuture).when(client).set("__com.netflix.evcache.server.healthcheck", 300, "Greed is good!"); doReturn(true).when(setFuture).get(5, TimeUnit.SECONDS); doReturn(getFuture).when(client).asyncGet("__com.netflix.evcache.server.healthcheck"); doReturn("").when(getFuture).get(5, TimeUnit.SECONDS); StepVerifier.create(indicator.doHealthCheck(builder)) .expectNext(new Health.Builder().outOfService().build()) .verifyComplete(); }