Package org.apache.flink.core.testutils
Class ManuallyTriggeredScheduledExecutorService
java.lang.Object
org.apache.flink.core.testutils.ManuallyTriggeredScheduledExecutorService
- All Implemented Interfaces:
Executor,ExecutorService,ScheduledExecutorService
public class ManuallyTriggeredScheduledExecutorService
extends Object
implements ScheduledExecutorService
Simple
ScheduledExecutorService implementation 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long timeout, TimeUnit unit) voidList<ScheduledFuture<?>>List<ScheduledFuture<?>>List<ScheduledFuture<?>>invokeAll(Collection<? extends Callable<T>> tasks) 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) booleanbooleanintGets the number of Runnables currently queued.<V> ScheduledFuture<V>scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit) voidshutdown()Future<?><T> Future<T><T> Future<T>voidtrigger()Triggers the next task that was submitted for execution.voidTriggers the next task that was submitted for execution.voidTriggers allqueuedRunnables.voidExecutes all runnable and scheduled non-periodic tasks until none are left to run.voidTriggers a single non-periodically scheduled task.voidvoidtriggerNonPeriodicScheduledTasks(Class<?> taskClazz) voidTriggers all non-periodically scheduled tasks.voidvoidTriggers all registered tasks.
-
Constructor Details
-
ManuallyTriggeredScheduledExecutorService
public ManuallyTriggeredScheduledExecutorService()
-
-
Method Details
-
execute
-
schedule
- Specified by:
schedulein interfaceScheduledExecutorService
-
schedule
- 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
- Specified by:
shutdownNowin interfaceExecutorService
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceExecutorService
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceExecutorService
-
awaitTermination
- Specified by:
awaitTerminationin interfaceExecutorService- Throws:
InterruptedException
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
submit
- Specified by:
submitin interfaceExecutorService
-
invokeAll
- 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
- Specified by:
invokeAnyin interfaceExecutorService
-
invokeAny
- 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
Triggers the next task that was submitted for execution. The method blocks the given amount of time if no task is scheduled, yet.- Parameters:
timeout- The time to wait for a new task to be scheduled.- Throws:
IllegalStateException- if no task was scheduled in the given amount of time.
-
trigger
public void trigger()Triggers the next task that was submitted for execution.- Throws:
IllegalStateException- if no task was scheduled before calling this method.
-
numQueuedRunnables
public int numQueuedRunnables()Gets the number of Runnables currently queued. -
getActiveScheduledTasks
-
getActivePeriodicScheduledTask
-
getActiveNonPeriodicScheduledTask
-
getAllScheduledTasks
-
getAllPeriodicScheduledTask
-
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() -
triggerNonPeriodicScheduledTasks
-
triggerPeriodicScheduledTasks
public void triggerPeriodicScheduledTasks()
-