Package org.apache.pekko.testkit
Class ExplicitlyTriggeredScheduler
- java.lang.Object
-
- org.apache.pekko.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 org.apache.pekko.actor.Scheduler
Scheduler.AtomicCancellable, 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 longcurrentTimeMs()The scheduler need to expose its internal time for testing.doublemaxFrequency()The maximum supported task frequency of this scheduler, i.e.Cancellableschedule(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).CancellablescheduleOnce(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.voidtimePasses(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 org.apache.pekko.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:SchedulerThe 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:
maxFrequencyin 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:SchedulerDeprecated 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:SchedulerScala 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:
scheduleOncein 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.
-
-