@Override public void run() { Iterator<Watchdog> it = cachedDogs.values().iterator(); while (it.hasNext()) { if (! it.next().isActive()) { it.remove(); } } // must set unscheduled before checking if we need to reschedule cleanerScheduled.set(false); if (! cachedDogs.isEmpty()) { maybeScheduleCleaner(); } } }
@Override public void run() { Iterator<Watchdog> it = cachedDogs.values().iterator(); while (it.hasNext()) { if (! it.next().isActive()) { it.remove(); } } // must set unscheduled before checking if we need to reschedule cleanerScheduled.set(false); if (! cachedDogs.isEmpty()) { maybeScheduleCleaner(); } } }
@Test public void isActiveTest() { assertFalse(watchdog.isActive()); ListenableFuture<?> future = FutureUtils.immediateResultFuture(null); watchdog.watch(future); assertFalse(watchdog.isActive()); SettableListenableFuture<?> slf = new SettableListenableFuture<>(); watchdog.watch(slf); assertTrue(watchdog.isActive()); TestUtils.blockTillClockAdvances(); assertEquals(1, scheduler.tick(null)); assertFalse(watchdog.isActive()); }