FakeScheduledExecutorService


public class FakeScheduledExecutorService extends AbstractExecutorService implements ScheduledExecutorService, AutoCloseable


Fake implementation of ScheduledExecutorService that lets tests control when tasks are executed.

Summary

Public constructors

Public methods

boolean
awaitTermination(long timeout, @Nullable TimeUnit unit)
void
void
boolean

Returns true if the execute queue contains at least one runnable.

boolean

Returns whether any runnable is in the execute or schedule queue.

boolean
boolean
void

Runs all of the runnables that execute enqueued.

void

Runs the next runnable in the execute queue.

@NonNull ScheduledFuture<V>
<V> schedule(
    @Nullable Callable<V> callable,
    long delay,
    @Nullable TimeUnit unit
)
@NonNull ScheduledFuture<Object>
schedule(@Nullable Runnable command, long delay, @Nullable TimeUnit unit)
@NonNull ScheduledFuture<Object>
scheduleAtFixedRate(
    @Nullable Runnable command,
    long initialDelay,
    long period,
    @Nullable TimeUnit unit
)
@NonNull ScheduledFuture<Object>
scheduleWithFixedDelay(
    @Nullable Runnable command,
    long initialDelay,
    long delay,
    @Nullable TimeUnit unit
)
void
@NonNull List<Runnable>
void

Executes tasks from the schedule queue until the given amount of simulated time has passed.

boolean

Simulates sleeping as long as necessary before executing the next scheduled task.

boolean

Simulates sleeping up to the given timeout before executing the next scheduled task, if any.

Inherited methods

From java.util.concurrent.AbstractExecutorService
List<Future<T>>
<T> invokeAll(Collection<Callable<T>> tasks)
T
<T> invokeAny(Collection<Callable<T>> tasks)
RunnableFuture<T>
<T> newTaskFor(Runnable runnable, T value)
Future<Object>
Future<T>
<T> submit(Runnable task, T result)

Public constructors

FakeScheduledExecutorService

Added in 1.0.0-alpha01
public FakeScheduledExecutorService()

Public methods

awaitTermination

Added in 1.0.0-alpha01
public boolean awaitTermination(long timeout, @Nullable TimeUnit unit)

close

Added in 1.0.0-alpha01
public void close()

execute

Added in 1.0.0-alpha01
public void execute(@Nullable Runnable command)

hasNext

Added in 1.0.0-alpha01
public boolean hasNext()

Returns true if the execute queue contains at least one runnable.

isEmpty

Added in 1.0.0-alpha01
@CheckReturnValue
public boolean isEmpty()

Returns whether any runnable is in the execute or schedule queue.

isShutdown

Added in 1.0.0-alpha01
public boolean isShutdown()

isTerminated

Added in 1.0.0-alpha01
public boolean isTerminated()

runAll

Added in 1.0.0-alpha01
public void runAll()

Runs all of the runnables that execute enqueued.

runNext

Added in 1.0.0-alpha01
public void runNext()

Runs the next runnable in the execute queue.

schedule

Added in 1.0.0-alpha01
public @NonNull ScheduledFuture<V> <V> schedule(
    @Nullable Callable<V> callable,
    long delay,
    @Nullable TimeUnit unit
)

schedule

Added in 1.0.0-alpha01
public @NonNull ScheduledFuture<Objectschedule(@Nullable Runnable command, long delay, @Nullable TimeUnit unit)

scheduleAtFixedRate

Added in 1.0.0-alpha01
public @NonNull ScheduledFuture<ObjectscheduleAtFixedRate(
    @Nullable Runnable command,
    long initialDelay,
    long period,
    @Nullable TimeUnit unit
)

scheduleWithFixedDelay

Added in 1.0.0-alpha01
public @NonNull ScheduledFuture<ObjectscheduleWithFixedDelay(
    @Nullable Runnable command,
    long initialDelay,
    long delay,
    @Nullable TimeUnit unit
)

shutdown

Added in 1.0.0-alpha01
public void shutdown()

shutdownNow

Added in 1.0.0-alpha01
public @NonNull List<RunnableshutdownNow()

simulateSleepExecutingAllTasks

Added in 1.0.0-alpha01
public void simulateSleepExecutingAllTasks(@NonNull Duration duration)

Executes tasks from the schedule queue until the given amount of simulated time has passed.

simulateSleepExecutingAtMostOneTask

Added in 1.0.0-alpha01
public boolean simulateSleepExecutingAtMostOneTask()

Simulates sleeping as long as necessary before executing the next scheduled task. Does nothing if the schedule queue is empty.

simulateSleepExecutingAtMostOneTask

Added in 1.0.0-alpha01
public boolean simulateSleepExecutingAtMostOneTask(@NonNull Duration duration)

Simulates sleeping up to the given timeout before executing the next scheduled task, if any.