@Test public void drainQueueIntoTest() { List<TaskWrapper> depositList = new ArrayList<>(2); OneTimeTaskWrapper task = new OneTimeTaskWrapper(DoNothingRunnable.instance(), null, Clock.lastKnownForwardProgressingMillis()); queueSet.executeQueue.add(task); queueSet.drainQueueInto(depositList); assertTrue(depositList.contains(task)); depositList.clear(); queueSet.scheduleQueue.add(task); queueSet.drainQueueInto(depositList); assertTrue(depositList.contains(task)); }
/** * Removes any tasks waiting to be run. Will not interrupt any tasks currently running. But * will avoid additional tasks from being run (unless they are allowed to be added during or * after this call). * <p> * If tasks are added concurrently during this invocation they may or may not be removed. * * @return List of runnables which were waiting in the task queue to be executed (and were now removed) */ public List<Runnable> clearQueue() { List<TaskWrapper> wrapperList = new ArrayList<>(highPriorityQueueSet.queueSize() + lowPriorityQueueSet.queueSize() + starvablePriorityQueueSet.queueSize()); highPriorityQueueSet.drainQueueInto(wrapperList); lowPriorityQueueSet.drainQueueInto(wrapperList); starvablePriorityQueueSet.drainQueueInto(wrapperList); return ContainerHelper.getContainedRunnables(wrapperList); }
/** * Removes any tasks waiting to be run. Will not interrupt any tasks currently running. But * will avoid additional tasks from being run (unless they are allowed to be added during or * after this call). * <p> * If tasks are added concurrently during this invocation they may or may not be removed. * * @return List of runnables which were waiting in the task queue to be executed (and were now removed) */ public List<Runnable> clearQueue() { List<TaskWrapper> wrapperList = new ArrayList<>(highPriorityQueueSet.queueSize() + lowPriorityQueueSet.queueSize() + starvablePriorityQueueSet.queueSize()); highPriorityQueueSet.drainQueueInto(wrapperList); lowPriorityQueueSet.drainQueueInto(wrapperList); starvablePriorityQueueSet.drainQueueInto(wrapperList); return ContainerHelper.getContainedRunnables(wrapperList); }