AbstractConsoleHealthChecker implements CrossDcLeaderAware { abstract boolean stop();  @Override void isCrossDcLeader(); @Override void notCrossDcLeader(); void startAlert(); void cancelFuture(); void startFuture(); @PreDestroy void whenShutDown();  }
@Test public void testSchedule() { ScheduledExecutorService schedule = Executors.newScheduledThreadPool(1); future = schedule.scheduleAtFixedRate(new Runnable() { @Override public void run() { System.out.println("Run for time - " + (executeTime + 1)); if(stop()) { future.cancel(true); return; } executeTime ++; } }, 0, 1, TimeUnit.SECONDS); while(!future.isDone() || !future.isCancelled()) { try { System.out.println("isCancelled: " + future.isCancelled()); System.out.println("isDone: " + future.isDone()); TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } Assert.assertTrue(future.isCancelled() || future.isDone()); Assert.assertEquals(2, executeTime); }