MemcachedHealthIndicator extends AbstractHealthIndicator { @Override protected void doHealthCheck(final Health.Builder builder) throws Exception { if (isAvailableSetOperation() && isValidValue()) { builder.up(); } else { builder.outOfService(); } } MemcachedHealthIndicator(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); indicator.doHealthCheck(builder); verify(builder).up(); }
@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); indicator.doHealthCheck(builder); verify(builder).outOfService(); }
@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); indicator.doHealthCheck(builder); verify(builder, never()).up(); }