Class ManuallyTriggeredScheduledExecutorService
- java.lang.Object
-
- net.shibboleth.oidc.metadata.cache.impl.ManuallyTriggeredScheduledExecutorService
-
- All Implemented Interfaces:
Executor,ExecutorService,ScheduledExecutorService
public class ManuallyTriggeredScheduledExecutorService extends Object implements ScheduledExecutorService
This code is copied verbatim from org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorServiceSimple
ScheduledExecutorServiceimplementation for testing purposes. It spawns no threads, but lets you trigger the execution of tasks manually.This class is helpful when implementing tests tasks synchronous and control when they run, which would otherwise asynchronous and require complex triggers and latches to test.
-
-
Field Summary
Fields Modifier and Type Field Description private ConcurrentLinkedQueue<ScheduledTask<?>>nonPeriodicScheduledTasksprivate ConcurrentLinkedQueue<ScheduledTask<?>>periodicScheduledTasksprivate ArrayDeque<Runnable>queuedRunnablesprivate booleanshutdown
-
Constructor Summary
Constructors Constructor Description ManuallyTriggeredScheduledExecutorService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, TimeUnit unit)voidexecute(Runnable command)Collection<ScheduledFuture<?>>getActiveNonPeriodicScheduledTask()Collection<ScheduledFuture<?>>getActivePeriodicScheduledTask()Collection<ScheduledFuture<?>>getActiveScheduledTasks()List<ScheduledFuture<?>>getAllNonPeriodicScheduledTask()List<ScheduledFuture<?>>getAllPeriodicScheduledTask()List<ScheduledFuture<?>>getAllScheduledTasks()private ScheduledFuture<?>insertNonPeriodicTask(Runnable command, long delay, TimeUnit unit)private <V> ScheduledFuture<V>insertNonPeriodicTask(Callable<V> callable, long delay, TimeUnit unit)private ScheduledFuture<?>insertPeriodicRunnable(Runnable command, long delay, long period, TimeUnit unit)<T> List<Future<T>>invokeAll(Collection<? extends Callable<T>> tasks)<T> List<Future<T>>invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)<T> TinvokeAny(Collection<? extends Callable<T>> tasks)<T> TinvokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)booleanisShutdown()booleanisTerminated()intnumQueuedRunnables()Gets the number of Runnables currently queued.ScheduledFuture<?>schedule(Runnable command, long delay, TimeUnit unit)<V> ScheduledFuture<V>schedule(Callable<V> callable, long delay, TimeUnit unit)ScheduledFuture<?>scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)ScheduledFuture<?>scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)voidshutdown()List<Runnable>shutdownNow()Future<?>submit(Runnable task)<T> Future<T>submit(Runnable task, T result)<T> Future<T>submit(Callable<T> task)voidtrigger()Triggers the next queued runnable and executes it synchronously.voidtriggerAll()Triggers allqueuedRunnables.voidtriggerAllNonPeriodicTasks()Executes all runnable and scheduled non-periodic tasks until none are left to run.voidtriggerNonPeriodicScheduledTask()Triggers a single non-periodically scheduled task.voidtriggerNonPeriodicScheduledTasks()voidtriggerNonPeriodicScheduledTasksWithRecursion()Triggers all non-periodically scheduled tasks.voidtriggerPeriodicScheduledTasks()voidtriggerScheduledTasks()Triggers all registered tasks.
-
-
-
Field Detail
-
queuedRunnables
private final ArrayDeque<Runnable> queuedRunnables
-
nonPeriodicScheduledTasks
private final ConcurrentLinkedQueue<ScheduledTask<?>> nonPeriodicScheduledTasks
-
periodicScheduledTasks
private final ConcurrentLinkedQueue<ScheduledTask<?>> periodicScheduledTasks
-
shutdown
private boolean shutdown
-
-
Method Detail
-
schedule
public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit)
- Specified by:
schedulein interfaceScheduledExecutorService
-
schedule
public <V> ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit)
- Specified by:
schedulein interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit)
- Specified by:
scheduleAtFixedRatein interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit)
- Specified by:
scheduleWithFixedDelayin interfaceScheduledExecutorService
-
shutdown
public void shutdown()
- Specified by:
shutdownin interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNowin interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit)- Specified by:
awaitTerminationin interfaceExecutorService
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submitin interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submitin interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submitin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
- Specified by:
invokeAllin interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
- Specified by:
invokeAllin interfaceExecutorService
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
- Specified by:
invokeAnyin interfaceExecutorService
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
- Specified by:
invokeAnyin interfaceExecutorService
-
triggerAllNonPeriodicTasks
public void triggerAllNonPeriodicTasks()
Executes all runnable and scheduled non-periodic tasks until none are left to run. This is essentially a combination oftriggerAll()andtriggerNonPeriodicScheduledTasks()that allows making a test agnostic of how exactly a runnable is passed to the executor.
-
triggerAll
public void triggerAll()
Triggers allqueuedRunnables.
-
trigger
public void trigger()
Triggers the next queued runnable and executes it synchronously. This method throws an exception if no Runnable is currently queued.
-
numQueuedRunnables
public int numQueuedRunnables()
Gets the number of Runnables currently queued.
-
getActiveScheduledTasks
public Collection<ScheduledFuture<?>> getActiveScheduledTasks()
-
getActivePeriodicScheduledTask
public Collection<ScheduledFuture<?>> getActivePeriodicScheduledTask()
-
getActiveNonPeriodicScheduledTask
public Collection<ScheduledFuture<?>> getActiveNonPeriodicScheduledTask()
-
getAllScheduledTasks
public List<ScheduledFuture<?>> getAllScheduledTasks()
-
getAllPeriodicScheduledTask
public List<ScheduledFuture<?>> getAllPeriodicScheduledTask()
-
getAllNonPeriodicScheduledTask
public List<ScheduledFuture<?>> getAllNonPeriodicScheduledTask()
-
triggerScheduledTasks
public void triggerScheduledTasks()
Triggers all registered tasks.
-
triggerNonPeriodicScheduledTask
public void triggerNonPeriodicScheduledTask()
Triggers a single non-periodically scheduled task.- Throws:
NoSuchElementException- If there is no such task.
-
triggerNonPeriodicScheduledTasksWithRecursion
public void triggerNonPeriodicScheduledTasksWithRecursion()
Triggers all non-periodically scheduled tasks. In contrast totriggerNonPeriodicScheduledTasks(), if such a task schedules another non-periodically schedule task, then this new task will also be triggered.
-
triggerNonPeriodicScheduledTasks
public void triggerNonPeriodicScheduledTasks()
-
triggerPeriodicScheduledTasks
public void triggerPeriodicScheduledTasks()
-
insertPeriodicRunnable
private ScheduledFuture<?> insertPeriodicRunnable(Runnable command, long delay, long period, TimeUnit unit)
-
insertNonPeriodicTask
private ScheduledFuture<?> insertNonPeriodicTask(Runnable command, long delay, TimeUnit unit)
-
insertNonPeriodicTask
private <V> ScheduledFuture<V> insertNonPeriodicTask(Callable<V> callable, long delay, TimeUnit unit)
-
-