ReScheduleSupport { public synchronized void reschedulePoll(Function<MetricFilter, Object> function) { if (taskResults != null) { for (TaskResult result : taskResults) { result.close(); } } Set<TaskResult> tasks = new HashSet<TaskResult>(3); tasks.add(schedulePoll(PRIORITY.NORMAL, config.stepMillis(PRIORITY.NORMAL), new PriorityMetricFilter(PRIORITY.NORMAL), function)); tasks.add(schedulePoll(PRIORITY.HIGH, config.stepMillis(PRIORITY.HIGH), new PriorityMetricFilter(PRIORITY.HIGH), function)); tasks.add(schedulePoll(PRIORITY.LOW, config.stepMillis(PRIORITY.LOW), new PriorityMetricFilter(PRIORITY.LOW), function)); this.taskResults = tasks; } ReScheduleSupport(ScheduledService scheduler, LookoutConfig config, Clock clock); synchronized void reschedulePoll(Function<MetricFilter, Object> function); TaskResult schedulePoll(final PRIORITY priority, final long stepMillis,
                                   final MetricFilter metricFilter,
                                   final Function<MetricFilter, Object> function);  }
@Test public void testReschedule() throws NoSuchFieldException, IllegalAccessException { ScheduledService scheduler = new MeasurableScheduler(NoopRegistry.INSTANCE, "poller", 2); LookoutConfig lookoutConfig = new LookoutConfig(); lookoutConfig.setStepInterval(PRIORITY.HIGH, 1000); lookoutConfig.setStepInterval(PRIORITY.NORMAL, 1000); lookoutConfig.setStepInterval(PRIORITY.LOW, 1000); ReScheduleSupport support = new ReScheduleSupport(scheduler, lookoutConfig, Clock.SYSTEM); support.reschedulePoll(function); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Field field = ReScheduleSupport.class.getDeclaredField("taskResults"); field.setAccessible(true); Set<ReScheduleSupport.TaskResult> set = (Set<ReScheduleSupport.TaskResult>) field .get(support); phase++; support.reschedulePoll(function); for (ReScheduleSupport.TaskResult result : set) { Assert.assertTrue(result.getFuture().isCancelled()); Assert.assertFalse(result.getEnable().get()); } Assert.assertTrue(phase1Counter.get() > 0); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } Assert.assertTrue(phase2Counter.get() > 0); }