@Test public void cacheCleanTest() { SettableListenableFuture<Object> slf = new SettableListenableFuture<>(); watchdog.watch(slf, TIMEOUT); assertFalse(watchdog.cachedDogs.isEmpty()); TestUtils.blockTillClockAdvances(); assertEquals(2, scheduler.advance(WatchdogCache.INSPECTION_INTERVAL_MILLIS)); assertTrue(watchdog.cachedDogs.isEmpty()); }
@Test public void blockTillClockAdvancesTest() { long before = Clock.accurateTimeMillis(); TestUtils.blockTillClockAdvances(); assertTrue(Clock.lastKnownTimeMillis() != before); } }
@Test public void getExecutionDelayPercentilesTest() { NoThreadSchedulerStatisticTracker scheduler = new NoThreadSchedulerStatisticTracker(); assertEquals(0, scheduler.getExecutionDelayPercentiles(90).get(90.), 0); scheduler.execute(new ClockUpdateRunnable()); TestUtils.blockTillClockAdvances(); scheduler.tick(null); assertEquals(1, scheduler.getExecutionDelayPercentiles(90).get(90.), SLOW_MACHINE ? 50 : 20); }
protected void getPriorityExecutionDelayPercentilesTest(TaskPriority priority) { NoThreadSchedulerStatisticTracker scheduler = new NoThreadSchedulerStatisticTracker(); assertEquals(0, scheduler.getExecutionDelayPercentiles(90).get(90.), 0); scheduler.execute(new ClockUpdateRunnable(), priority); TestUtils.blockTillClockAdvances(); scheduler.tick(null); assertEquals(1, scheduler.getExecutionDelayPercentiles(90).get(90.), SLOW_MACHINE ? 50 : 20); }
scheduler.execute(DoNothingRunnable.instance(), TaskPriority.Low); TestUtils.blockTillClockAdvances(); scheduler.tick(null); for (int i = 0; i < highPriorityCount; i++) { scheduler.execute(DoNothingRunnable.instance(), TaskPriority.High); TestUtils.blockTillClockAdvances(); scheduler.tick(null);
for (int i = 0; i < lowPriorityCount; i++) { if (lastRunnable != null) { TestUtils.blockTillClockAdvances(); lastRunnable.unblock(); TestUtils.blockTillClockAdvances(); lastRunnable.unblock(); lastRunnable = new BlockingTestRunnable(); scheduler.execute(lastRunnable, TaskPriority.High); TestUtils.blockTillClockAdvances(); lastRunnable.unblock();
@Test public void lastKnownTimeNanosTest() { // verify clock is not updating long before = Clock.lastKnownTimeNanos(); TestUtils.blockTillClockAdvances(); // update clock long newTime = -1; assertTrue((newTime = Clock.accurateTimeNanos()) > before); // verify we get the new time again assertEquals(newTime, Clock.lastKnownTimeNanos()); }
public static void getExecutionDelayPercentilesTest(StatisticPriorityScheduler scheduler) { BlockingTestRunnable btr = new BlockingTestRunnable(); try { assertEquals(0, scheduler.getExecutionDelayPercentiles(90).get(90.), 0); scheduler.execute(btr); scheduler.execute(new ClockUpdateRunnable()); TestUtils.blockTillClockAdvances(); btr.unblock(); assertEquals(2, scheduler.getExecutionDelayPercentiles(90).get(90.), SLOW_MACHINE ? 50 : 20); } finally { btr.unblock(); } }
@Test public void expiredFutureTest() { SettableListenableFuture<?> slf = new SettableListenableFuture<>(); watchdog.watch(slf); TestUtils.blockTillClockAdvances(); assertEquals(1, scheduler.tick(null)); assertTrue(slf.isCancelled()); assertTrue(watchdog.futures.isEmpty()); }
public static void getPriorityExecutionDelayPercentilesTest(StatisticPriorityScheduler scheduler, TaskPriority priority) { BlockingTestRunnable btr = new BlockingTestRunnable(); try { assertEquals(0, scheduler.getExecutionDelayPercentiles(90).get(90.), 0); scheduler.execute(btr); scheduler.execute(new ClockUpdateRunnable(), priority); TestUtils.blockTillClockAdvances(); btr.unblock(); assertEquals(2, scheduler.getExecutionDelayPercentiles(90).get(90.), SLOW_MACHINE ? 50 : 20); } finally { btr.unblock(); } }
@Test public void forwardProgressingDurationTest() { long startTime = Clock.lastKnownForwardProgressingMillis(); assertEquals(0, Clock.forwardProgressingDuration(startTime)); TestUtils.blockTillClockAdvances(); assertTrue(Clock.forwardProgressingDuration(startTime) > 0); }
@Test public void lastKnownForwardProgressingMillisAccurateTimeUpdateTest() { // verify clock is not updating long before = Clock.lastKnownForwardProgressingMillis(); TestUtils.blockTillClockAdvances(); // update clock long newTime = -1; assertTrue((newTime = Clock.accurateForwardProgressingMillis()) > before); // verify we get the new time again assertTrue(newTime == Clock.lastKnownForwardProgressingMillis()); }
@Test public void lastKnownTimeMillisTest() { // verify clock is not updating long before = Clock.lastKnownTimeMillis(); TestUtils.blockTillClockAdvances(); // update clock long newTime = -1; assertTrue((newTime = Clock.accurateTimeMillis()) > before); // verify we get the new time again assertEquals(newTime, Clock.lastKnownTimeMillis()); }
@Test public void expiredFutureTest() { SettableListenableFuture<Object> slf = new SettableListenableFuture<>(); watchdog.watch(slf, TIMEOUT); TestUtils.blockTillClockAdvances(); assertEquals(1, scheduler.tick()); assertTrue(slf.isCancelled()); }
@Test public void verifyCleanupTaskTest() { double permits = .1; Object key = new Object(); limiter.execute(permits, key, new TestRunnable()); assertEquals(2, scheduler.advance(KeyedRateLimiterExecutor.LIMITER_IDLE_TIMEOUT)); assertEquals(1, limiter.getTrackedKeyCount()); assertFalse(limiter.currentLimiters.isEmpty()); if (TEST_PROFILE == TestLoad.Stress) { // too slow for normal tests right now TestUtils.sleep((long)(KeyedRateLimiterExecutor.LIMITER_IDLE_TIMEOUT + (1000 * permits))); TestUtils.blockTillClockAdvances(); assertEquals(1, scheduler.advance(KeyedRateLimiterExecutor.LIMITER_IDLE_TIMEOUT)); assertTrue(limiter.currentLimiters.isEmpty()); assertEquals(0, limiter.getTrackedKeyCount()); } }
@Test public void runTest() { TestTestRunnable ttr = new TestTestRunnable(); long start = Clock.accurateForwardProgressingMillis(); TestUtils.blockTillClockAdvances(); ttr.run(); assertTrue(ttr.handleRunStartCalled); assertTrue(ttr.handleRunFinishCalled); assertTrue(ttr.startCalledBeforeFinish); assertTrue(ttr.ranOnce()); assertEquals(1, ttr.getRunCount()); assertTrue(ttr.getDelayTillFirstRun() > 0); TestUtils.blockTillClockAdvances(); ttr.run(); TestUtils.blockTillClockAdvances(); long now = Clock.accurateForwardProgressingMillis(); assertTrue(ttr.getDelayTillRun(2) <= now - start); assertTrue(ttr.getDelayTillRun(2) > ttr.getDelayTillFirstRun()); }
@Test public void getNextReadyTaskHighPriorityDelayedTest() { TaskWrapper scheduleTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueManager.highPriorityQueueSet.scheduleQueue, Clock.accurateForwardProgressingMillis() + 1000); queueManager.highPriorityQueueSet.addScheduled(scheduleTask); TestUtils.blockTillClockAdvances(); OneTimeTaskWrapper executeTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueManager.lowPriorityQueueSet.executeQueue, Clock.lastKnownForwardProgressingMillis()); queueManager.lowPriorityQueueSet.addExecute(executeTask); assertTrue(executeTask == queueManager.getNextTask()); }
@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()); }
@Test public void getNextReadyTaskExecuteAheadOfScheduledTest() { OneTimeTaskWrapper executeTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueManager.highPriorityQueueSet.executeQueue, Clock.accurateForwardProgressingMillis()); queueManager.highPriorityQueueSet.addExecute(executeTask); TestUtils.blockTillClockAdvances(); TaskWrapper scheduleTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueManager.highPriorityQueueSet.scheduleQueue, Clock.lastKnownForwardProgressingMillis()); queueManager.highPriorityQueueSet.addScheduled(scheduleTask); assertTrue(executeTask == queueManager.getNextTask()); assertTrue(executeTask == queueManager.getNextTask()); // execute task has not been removed yet // this should remove the execute task so we can get the scheduled task assertTrue(executeTask.canExecute(executeTask.getExecuteReference())); assertTrue(scheduleTask == queueManager.getNextTask()); }
@Test public void getNextReadyTaskScheduledAheadOfExecuteTest() { TaskWrapper scheduleTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueManager.highPriorityQueueSet.scheduleQueue, Clock.accurateForwardProgressingMillis()); queueManager.highPriorityQueueSet.addScheduled(scheduleTask); TestUtils.blockTillClockAdvances(); OneTimeTaskWrapper executeTask = new OneTimeTaskWrapper(DoNothingRunnable.instance(), queueManager.highPriorityQueueSet.executeQueue, Clock.lastKnownForwardProgressingMillis()); queueManager.highPriorityQueueSet.addExecute(executeTask); assertTrue(scheduleTask == queueManager.getNextTask()); assertTrue(scheduleTask == queueManager.getNextTask()); // schedule task has not been removed yet // this should remove the schedule task so we can get the execute task assertTrue(scheduleTask.canExecute(executeTask.getExecuteReference())); assertTrue(executeTask == queueManager.getNextTask()); }