Class ExplicitlyTriggeredScheduler

java.lang.Object
org.apache.pekko.testkit.ExplicitlyTriggeredScheduler
All Implemented Interfaces:
Scheduler

public class ExplicitlyTriggeredScheduler extends Object implements Scheduler
For testing: scheduler that does not look at the clock, but must be progressed manually by calling timePasses.

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'.

  • Constructor Details

    • ExplicitlyTriggeredScheduler

      public ExplicitlyTriggeredScheduler(com.typesafe.config.Config config, LoggingAdapter log, ThreadFactory tf)
  • Method Details

    • 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 interface Scheduler
    • schedule

      public Cancellable schedule(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, Runnable runnable, scala.concurrent.ExecutionContext executor)
      Specified by:
      schedule in interface Scheduler
    • scheduleOnce

      public Cancellable scheduleOnce(scala.concurrent.duration.FiniteDuration delay, 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 interface Scheduler
    • 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.