Module net.morimekta.testing
Package net.morimekta.testing.concurrent
Class ImmediateScheduledExecutor
- java.lang.Object
-
- net.morimekta.testing.concurrent.ImmediateScheduledExecutor
-
- All Implemented Interfaces:
Executor
,ExecutorService
,ScheduledExecutorService
,FakeClock.TimeListener
public class ImmediateScheduledExecutor extends Object implements ScheduledExecutorService, FakeClock.TimeListener
A scheduled executor that uses a fake clock as back-bone to the executor. To trigger the executions, callFakeClock.tick(long)
on the fake clock. The executions will be handled in thread of the tick itself.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
ImmediateScheduledExecutor.FakeRecurringTask
A fake recurring task / future.class
ImmediateScheduledExecutor.FakeTask<V>
A fake task / future instance.
-
Constructor Summary
Constructors Constructor Description ImmediateScheduledExecutor(FakeClock clock)
Create a fake scheduled executor.
-
Method Summary
-
-
-
Constructor Detail
-
ImmediateScheduledExecutor
public ImmediateScheduledExecutor(FakeClock clock)
Create a fake scheduled executor.- Parameters:
clock
- Clock to trigger executions.
-
-
Method Detail
-
newCurrentTime
public void newCurrentTime(Instant now)
- Specified by:
newCurrentTime
in interfaceFakeClock.TimeListener
- Parameters:
now
- The new current time value.
-
getDelay
public Duration getDelay(Instant now)
Description copied from interface:FakeClock.TimeListener
Get delay until the next something to be handled. Will return the default max value if nothing else. If something is scheduled to happen immediately,FakeClock.MIN_DELAY
should be returned.- Specified by:
getDelay
in interfaceFakeClock.TimeListener
- Parameters:
now
- The current time when asking.- Returns:
- The time to delay. NULL values,
Duration.ZERO
and negative durations will be ignored.
-
schedule
public ImmediateScheduledExecutor.FakeTask<?> schedule(Runnable runnable, long l, TimeUnit timeUnit)
- Specified by:
schedule
in interfaceScheduledExecutorService
-
schedule
public <V> ImmediateScheduledExecutor.FakeTask<V> schedule(Callable<V> callable, long delay, TimeUnit timeUnit)
- Specified by:
schedule
in interfaceScheduledExecutorService
-
scheduleAtFixedRate
public ImmediateScheduledExecutor.FakeRecurringTask scheduleAtFixedRate(Runnable runnable, long initialDelay, long period, TimeUnit timeUnit)
- Specified by:
scheduleAtFixedRate
in interfaceScheduledExecutorService
-
scheduleWithFixedDelay
public ImmediateScheduledExecutor.FakeRecurringTask scheduleWithFixedDelay(Runnable runnable, long initialDelay, long delay, TimeUnit timeUnit)
- Specified by:
scheduleWithFixedDelay
in interfaceScheduledExecutorService
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long l, TimeUnit timeUnit)
- Specified by:
awaitTermination
in interfaceExecutorService
-
submit
public <T> ImmediateScheduledExecutor.FakeTask<T> submit(Callable<T> callable)
- Specified by:
submit
in interfaceExecutorService
-
submit
public <T> ImmediateScheduledExecutor.FakeTask<T> submit(Runnable runnable, T t)
- Specified by:
submit
in interfaceExecutorService
-
submit
public ImmediateScheduledExecutor.FakeTask<?> submit(Runnable runnable)
- Specified by:
submit
in interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection)
- Specified by:
invokeAll
in interfaceExecutorService
-
invokeAll
public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection, long l, TimeUnit timeUnit)
- Specified by:
invokeAll
in interfaceExecutorService
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> collection) throws ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
ExecutionException
-
invokeAny
public <T> T invokeAny(Collection<? extends Callable<T>> collection, long l, TimeUnit timeUnit) throws ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
ExecutionException
-
-