PingAction extends AbstractHealthCheckAction<PingActionContext> { @Override public void doTask() { instance.getRedisSession().ping(new PingCallback() { @Override public void pong(String pongMsg) { notifyListeners(new PingActionContext(instance, PingCommand.PONG.equalsIgnoreCase(pongMsg))); } @Override public void fail(Throwable th) { notifyListeners(new PingActionContext(instance, false)); } }); } PingAction(ScheduledExecutorService scheduled, RedisHealthCheckInstance instance, ExecutorService executors); @Override void doTask();  }
@Test public void testDoScheduledTask() throws TimeoutException { when(session.ping(any(PingCallback.class))).thenAnswer(new Answer<PingCallback>() { @Override public PingCallback answer(InvocationOnMock invocation) throws Throwable { PingCallback callback = invocation.getArgumentAt(0, PingCallback.class); callback.pong("PONG"); return null; } }); AtomicBoolean result = new AtomicBoolean(false); action.addListener(new HealthCheckActionListener() { @Override public void onAction(ActionContext context) { PingActionContext pingActionContext = (PingActionContext) context; logger.info("[context] {}: {}", DateTimeUtils.timeAsString(context.getRecvTimeMilli()), context.getResult()); result.set(pingActionContext.getResult()); } @Override public boolean worksfor(ActionContext t) { return t instanceof PingActionContext; } @Override public void stopWatch(HealthCheckAction action) { } }); action.doTask(); waitConditionUntilTimeOut(()->result.get(), 1000); }