Package akka.testkit
Class ExplicitlyTriggeredScheduler
- java.lang.Object
-
- akka.testkit.ExplicitlyTriggeredScheduler
-
- All Implemented Interfaces:
Scheduler
public class ExplicitlyTriggeredScheduler extends java.lang.Object implements Scheduler
For testing: scheduler that does not look at the clock, but must be progressed manually by callingtimePasses
.This allows for faster and less timing-sensitive specs, as jobs will be executed on the test thread instead of using the original {ExecutionContext}. This means recreating specific scenario's becomes easier, but these tests might fail to catch race conditions that only happen when tasks are scheduled in parallel in 'real time'.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface akka.actor.Scheduler
Scheduler.TaskRunOnClose
-
-
Constructor Summary
Constructors Constructor Description ExplicitlyTriggeredScheduler(com.typesafe.config.Config config, LoggingAdapter log, java.util.concurrent.ThreadFactory tf)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
currentTimeMs()
The scheduler need to expose its internal time for testing.double
maxFrequency()
The maximum supported task frequency of this scheduler, i.e.Cancellable
schedule(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, java.lang.Runnable runnable, scala.concurrent.ExecutionContext executor)
Deprecated API: SeeScheduler.scheduleWithFixedDelay(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, java.lang.Runnable, scala.concurrent.ExecutionContext)
orScheduler.scheduleAtFixedRate(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, java.lang.Runnable, scala.concurrent.ExecutionContext)
.Cancellable
scheduleOnce(scala.concurrent.duration.FiniteDuration delay, java.lang.Runnable runnable, scala.concurrent.ExecutionContext executor)
Scala API: Schedules a Runnable to be run once with a delay, i.e.void
timePasses(scala.concurrent.duration.FiniteDuration amount)
Advance the clock by the specified duration, executing all outstanding jobs on the calling thread before returning.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface akka.actor.Scheduler
schedule, schedule, schedule, schedule, schedule$default$6, scheduleAtFixedRate, scheduleAtFixedRate, scheduleAtFixedRate, scheduleAtFixedRate, scheduleAtFixedRate$default$6, scheduleOnce, scheduleOnce, scheduleOnce, scheduleOnce, scheduleOnce$default$5, scheduleWithFixedDelay, scheduleWithFixedDelay, scheduleWithFixedDelay, scheduleWithFixedDelay, scheduleWithFixedDelay$default$6
-
-
-
-
Constructor Detail
-
ExplicitlyTriggeredScheduler
public ExplicitlyTriggeredScheduler(com.typesafe.config.Config config, LoggingAdapter log, java.util.concurrent.ThreadFactory tf)
-
-
Method Detail
-
currentTimeMs
public long currentTimeMs()
The scheduler need to expose its internal time for testing.
-
maxFrequency
public double maxFrequency()
Description copied from interface:Scheduler
The maximum supported task frequency of this scheduler, i.e. the inverse of the minimum time interval between executions of a recurring task, in Hz.- Specified by:
maxFrequency
in interfaceScheduler
-
schedule
public Cancellable schedule(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, java.lang.Runnable runnable, scala.concurrent.ExecutionContext executor)
Description copied from interface:Scheduler
Deprecated API: SeeScheduler.scheduleWithFixedDelay(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, java.lang.Runnable, scala.concurrent.ExecutionContext)
orScheduler.scheduleAtFixedRate(scala.concurrent.duration.FiniteDuration, scala.concurrent.duration.FiniteDuration, java.lang.Runnable, scala.concurrent.ExecutionContext)
.
-
scheduleOnce
public Cancellable scheduleOnce(scala.concurrent.duration.FiniteDuration delay, java.lang.Runnable runnable, scala.concurrent.ExecutionContext executor)
Description copied from interface:Scheduler
Scala API: Schedules a Runnable to be run once with a delay, i.e. a time period that has to pass before the runnable is executed.- Specified by:
scheduleOnce
in interfaceScheduler
-
timePasses
public void timePasses(scala.concurrent.duration.FiniteDuration amount)
Advance the clock by the specified duration, executing all outstanding jobs on the calling thread before returning.We will not add a dilation factor to this amount, since the scheduler API also does not apply dilation. If you want the amount of time passed to be dilated, apply the dilation before passing the delay to this method.
-
-