org.apache.pekko.testkit

Members list

Type members

Classlikes

Attributes

Companion
class
Source
CallingThreadDispatcher.scala
Supertypes
class Object
trait Matchable
class Any
Self type

Dispatcher which runs invocations on the current thread only. This dispatcher does not create any new threads, but it can be used from different threads concurrently for the same actor. The dispatch strategy is to run on the current thread unless the target actor is either suspendSwitch or already running on the current thread (if it is running on a different thread, then this thread will block until that other invocation is finished); if the invocation is not run, it is queued in a thread-local queue to be executed once the active invocation further up the call stack finishes. This leads to completely deterministic execution order if only one thread is used.

Dispatcher which runs invocations on the current thread only. This dispatcher does not create any new threads, but it can be used from different threads concurrently for the same actor. The dispatch strategy is to run on the current thread unless the target actor is either suspendSwitch or already running on the current thread (if it is running on a different thread, then this thread will block until that other invocation is finished); if the invocation is not run, it is queued in a thread-local queue to be executed once the active invocation further up the call stack finishes. This leads to completely deterministic execution order if only one thread is used.

Suspending and resuming are global actions for one actor, meaning they can affect different threads, which leads to complications. If messages are queued (thread-locally) during the suspendSwitch period, the only thread to run them upon resume is the thread actually calling the resume method. Hence, all thread-local queues which are not currently being drained (possible, since suspend-queue-resume might happen entirely during an invocation on a different thread) are scooped up into the current thread-local queue which is then executed. It is possible to suspend an actor from within its call stack.

Attributes

Since

1.1

Companion
object
Source
CallingThreadDispatcher.scala
Supertypes
trait Executor
class Object
trait Matchable
class Any
Show all

Attributes

Source
CallingThreadDispatcher.scala
Supertypes
class Object
trait Matchable
class Any
class CallingThreadMailbox(_receiver: Cell, val mailboxType: MailboxType)

Attributes

Source
CallingThreadDispatcher.scala
Supertypes
trait Runnable
class ForkJoinTask[Unit]
trait Serializable
trait Future[Unit]
class Object
trait Matchable
class Any
Show all
final case class CustomEventFilter(test: PartialFunction[LogEvent, Boolean])(occurrences: Int) extends EventFilter

Custom event filter when the others do not fit the bill.

Custom event filter when the others do not fit the bill.

If the partial function is defined and returns true, filter the event.

Attributes

Source
TestEventListener.scala
Supertypes
trait Serializable
trait Product
trait Equals
class EventFilter
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Source
TestEventListener.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class DeadLettersFilter(messageClass: Class[_])(occurrences: Int) extends EventFilter

Filter which matches DeadLetter events, if the wrapped message conforms to the given type.

Filter which matches DeadLetter events, if the wrapped message conforms to the given type.

Attributes

Companion
object
Source
TestEventListener.scala
Supertypes
trait Serializable
trait Product
trait Equals
class EventFilter
class Object
trait Matchable
class Any
Show all
final case class DebugFilter(source: Option[String], message: Either[String, Regex], complete: Boolean)(occurrences: Int) extends EventFilter

Filter which matches Debug events, if they satisfy the given criteria:

Filter which matches Debug events, if they satisfy the given criteria:

  • source, if given, applies a filter on the event’s origin

  • message applies a filter on the event’s message (either with String.startsWith or Regex.findFirstIn().isDefined)

If you want to match all Debug events, the most efficient is to use Left("").

Attributes

Source
TestEventListener.scala
Supertypes
trait Serializable
trait Product
trait Equals
class EventFilter
class Object
trait Matchable
class Any
Show all

Attributes

Source
TestKit.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class ErrorFilter(throwable: Class[_], source: Option[String], message: Either[String, Regex], complete: Boolean)(occurrences: Int) extends EventFilter

Filter which matches Error events, if they satisfy the given criteria:

Filter which matches Error events, if they satisfy the given criteria:

  • throwable applies an upper bound on the type of exception contained in the Error event

  • source, if given, applies a filter on the event’s origin

  • message applies a filter on the event’s message (either with String.startsWith or Regex.findFirstIn().isDefined); if the message itself does not match, the match is retried with the contained Exception’s message; if both are null, the filter always matches if at the same time the Exception’s stack trace is empty (this catches JVM-omitted “fast-throw” exceptions)

If you want to match all Error events, the most efficient is to use Left("").

Attributes

Source
TestEventListener.scala
Supertypes
trait Serializable
trait Product
trait Equals
class EventFilter
class Object
trait Matchable
class Any
Show all
abstract class EventFilter(occurrences: Int)

Facilities for selectively filtering out expected events from logging so that you can keep your test run’s console output clean and do not miss real error messages.

Facilities for selectively filtering out expected events from logging so that you can keep your test run’s console output clean and do not miss real error messages.

See the companion object for convenient factory methods.

If the occurrences is set to Int.MaxValue, no tracking is done.

Attributes

Companion
object
Source
TestEventListener.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object EventFilter

Facilities for selectively filtering out expected events from logging so that you can keep your test run’s console output clean and do not miss real error messages.

Facilities for selectively filtering out expected events from logging so that you can keep your test run’s console output clean and do not miss real error messages.

'''Also have a look at the org.apache.pekko.testkit package object’s filterEvents and filterException methods.'''

The source filters do accept Class[_] arguments, matching any object which is an instance of the given class, e.g.

EventFilter.info(source = classOf[MyActor]) // will match Info events from any MyActor instance

The message object will be converted to a string before matching ("null" if it is null).

Attributes

Companion
class
Source
TestEventListener.scala
Supertypes
class Object
trait Matchable
class Any
Self type
class ExplicitlyTriggeredScheduler(config: Config, log: LoggingAdapter, tf: ThreadFactory) extends Scheduler

For testing: scheduler that does not look at the clock, but must be progressed manually by calling timePasses.

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

Attributes

Source
ExplicitlyTriggeredScheduler.scala
Supertypes
trait Scheduler
class Object
trait Matchable
class Any

Attributes

Source
TestKit.scala
Supertypes
class Object
trait Matchable
class Any
Self type
final case class InfoFilter(source: Option[String], message: Either[String, Regex], complete: Boolean)(occurrences: Int) extends EventFilter

Filter which matches Info events, if they satisfy the given criteria:

Filter which matches Info events, if they satisfy the given criteria:

  • source, if given, applies a filter on the event’s origin

  • message applies a filter on the event’s message (either with String.startsWith or Regex.findFirstIn().isDefined)

If you want to match all Info events, the most efficient is to use Left("").

Attributes

Source
TestEventListener.scala
Supertypes
trait Serializable
trait Product
trait Equals
class EventFilter
class Object
trait Matchable
class Any
Show all
trait JavaSerializable extends Serializable

Marker trait for test messages that will use Java serialization via org.apache.pekko.testkit.TestJavaSerializer

Marker trait for test messages that will use Java serialization via org.apache.pekko.testkit.TestJavaSerializer

Attributes

Source
JavaSerializable.scala
Supertypes
trait Serializable
class Object
trait Matchable
class Any
object SocketUtil

Utilities to get free socket address.

Utilities to get free socket address.

Attributes

Source
SocketUtil.scala
Supertypes
class Object
trait Matchable
class Any
Self type
SocketUtil.type
object TestActor

Attributes

Companion
class
Source
TestKit.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestActor.type
class TestActor(queue: BlockingDeque[Message]) extends Actor

Attributes

Companion
object
Source
TestKit.scala
Supertypes
trait Actor
class Object
trait Matchable
class Any
class TestActorRef[T <: Actor](_system: ActorSystem, _props: Props, _supervisor: ActorRef, name: String)

This special ActorRef is exclusively for use during unit testing in a single-threaded environment. Therefore, it overrides the dispatcher to CallingThreadDispatcher and sets the receiveTimeout to None. Otherwise, it acts just like a normal ActorRef. You may retrieve a reference to the underlying actor to test internal logic.

This special ActorRef is exclusively for use during unit testing in a single-threaded environment. Therefore, it overrides the dispatcher to CallingThreadDispatcher and sets the receiveTimeout to None. Otherwise, it acts just like a normal ActorRef. You may retrieve a reference to the underlying actor to test internal logic.

Attributes

Since

1.1

Companion
object
Source
TestActorRef.scala
Supertypes
class ActorRef
trait Serializable
trait Comparable[ActorRef]
class Object
trait Matchable
class Any
Show all
Known subtypes
class TestFSMRef[S, D, T]
object TestActorRef

Attributes

Companion
class
Source
TestActorRef.scala
Supertypes
class Object
trait Matchable
class Any
Self type
object TestActors

A collection of common actor patterns used in tests.

A collection of common actor patterns used in tests.

Attributes

Source
TestActors.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestActors.type
object TestBarrier

A cyclic barrier wrapper for use in testing. It always uses a timeout when waiting and timeouts are specified as durations. Timeouts will always throw an exception. The default timeout is 5 seconds. Timeouts are multiplied by the testing time factor for Jenkins builds.

A cyclic barrier wrapper for use in testing. It always uses a timeout when waiting and timeouts are specified as durations. Timeouts will always throw an exception. The default timeout is 5 seconds. Timeouts are multiplied by the testing time factor for Jenkins builds.

Attributes

Companion
class
Source
TestBarrier.scala
Supertypes
class Object
trait Matchable
class Any
Self type
class TestBarrier(count: Int)

Attributes

Companion
object
Source
TestBarrier.scala
Supertypes
class Object
trait Matchable
class Any
class TestBarrierTimeoutException(message: String) extends RuntimeException

Attributes

Source
TestBarrier.scala
Supertypes
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
final implicit class TestDuration(val duration: FiniteDuration) extends AnyVal

Scala API. Scale timeouts (durations) during tests with the configured 'pekko.test.timefactor'. Implicit class providing dilated method.

Scala API. Scale timeouts (durations) during tests with the configured 'pekko.test.timefactor'. Implicit class providing dilated method.

import scala.concurrent.duration._
import org.apache.pekko.testkit._
10.milliseconds.dilated

Corresponding Java API is available in JavaTestKit.dilated()

Attributes

Source
package.scala
Supertypes
class AnyVal
trait Matchable
class Any
sealed trait TestEvent

Implementation helpers of the EventFilter facilities: send Mute to the TestEventListener to install a filter, and UnMute to uninstall it.

Implementation helpers of the EventFilter facilities: send Mute to the TestEventListener to install a filter, and UnMute to uninstall it.

You should always prefer the filter methods in the package object (see org.apache.pekko.testkit filterEvents and filterException) or on the EventFilter implementations.

Attributes

Companion
object
Source
TestEventListener.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Mute
class UnMute
object TestEvent

Implementation helpers of the EventFilter facilities: send Mute to the TestEventFilter to install a filter, and UnMute to uninstall it.

Implementation helpers of the EventFilter facilities: send Mute to the TestEventFilter to install a filter, and UnMute to uninstall it.

You should always prefer the filter methods in the package object (see org.apache.pekko.testkit filterEvents and filterException) or on the EventFilter implementations.

Attributes

Companion
trait
Source
TestEventListener.scala
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
TestEvent.type

EventListener for running tests, which allows selectively filtering out expected messages. To use it, include something like this into pekko.test.conf and run your tests with system property "pekko.mode" set to "test":

EventListener for running tests, which allows selectively filtering out expected messages. To use it, include something like this into pekko.test.conf and run your tests with system property "pekko.mode" set to "test":


pekko {
 loggers = ["org.apache.pekko.testkit.TestEventListener"]
}

Attributes

Source
TestEventListener.scala
Supertypes
trait StdOutLogger
trait Actor
class Object
trait Matchable
class Any
Show all
final case class TestException(message: String) extends RuntimeException, NoStackTrace

A predefined exception that can be used in tests. It doesn't include a stack trace.

A predefined exception that can be used in tests. It doesn't include a stack trace.

Attributes

Source
TestException.scala
Supertypes
trait Product
trait Equals
trait NoStackTrace
class RuntimeException
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Show all
class TestFSMRef[S, D, T <: Actor](system: ActorSystem, props: Props, supervisor: ActorRef, name: String)(implicit ev: T <:< FSM[S, D]) extends TestActorRef[T]

This is a specialized form of the TestActorRef with support for querying and setting the state of a FSM. Use a LoggingFSM with this class if you also need to inspect event traces.

This is a specialized form of the TestActorRef with support for querying and setting the state of a FSM. Use a LoggingFSM with this class if you also need to inspect event traces.


val fsm = TestFSMRef(new Actor with LoggingFSM[Int, Null] {
   override def logDepth = 12
   startWith(1, null)
   when(1) {
     case Event("hello", _) => goto(2)
   }
   when(2) {
     case Event("world", _) => goto(1)
   }
 })
assert (fsm.stateName == 1)
fsm ! "hallo"
assert (fsm.stateName == 2)
assert (fsm.underlyingActor.getLog == IndexedSeq(FSMLogEntry(1, null, "hallo")))

Attributes

Since

1.2

Companion
object
Source
TestFSMRef.scala
Supertypes
class TestActorRef[T]
class ActorRef
trait Serializable
trait Comparable[ActorRef]
class Object
trait Matchable
class Any
Show all
object TestFSMRef

Attributes

Companion
class
Source
TestFSMRef.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestFSMRef.type

This Serializer uses standard Java Serialization and is useful for tests where ad-hoc messages are created and sent between actor systems. It needs to be explicitly enabled in the config (or through ActorSystemSetup) like so:

This Serializer uses standard Java Serialization and is useful for tests where ad-hoc messages are created and sent between actor systems. It needs to be explicitly enabled in the config (or through ActorSystemSetup) like so:

pekko.actor.serialization-bindings {
 "my.test.AdHocMessage" = java-test
}

Attributes

Source
TestJavaSerializer.scala
Supertypes
trait Serializer
class Object
trait Matchable
class Any
class TestKit(_system: ActorSystem) extends TestKitBase

Test kit for testing actors. Inheriting from this class enables reception of replies from actors, which are queued by an internal actor and can be examined using the expectMsg... methods. Assertions and bounds concerning timing are available in the form of within blocks.

Test kit for testing actors. Inheriting from this class enables reception of replies from actors, which are queued by an internal actor and can be examined using the expectMsg... methods. Assertions and bounds concerning timing are available in the form of within blocks.

class Test extends TestKit(ActorSystem()) {
 try {

   val test = system.actorOf(Props[SomeActor])

     within (1.second) {
       test ! SomeWork
       expectMsg(Result1) // bounded to 1 second
       expectMsg(Result2) // bounded to the remainder of the 1 second
     }

   } finally {
     system.terminate()
   }

 } finally {
   system.terminate()
 }
}

Beware of two points:

  • the ActorSystem passed into the constructor needs to be shutdown, otherwise thread pools and memory will be leaked
  • this class is not thread-safe (only one actor with one queue, one stack of within blocks); it is expected that the code is executed from a constructor as shown above, which makes this a non-issue, otherwise take care not to run tests within a single test class instance in parallel.

It should be noted that for CI servers and the like all maximum Durations are scaled using their Duration.dilated method, which uses the TestKitExtension.Settings.TestTimeFactor settable via pekko.conf entry "pekko.test.timefactor".

Attributes

Since

1.1

Companion
object
Source
TestKit.scala
Supertypes
trait TestKitBase
class Object
trait Matchable
class Any
Known subtypes
class TestProbe
object TestKit

Attributes

Companion
class
Source
TestKit.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestKit.type
trait TestKitBase

Implementation trait behind the pekko.testkit.TestKit class: you may use this if inheriting from a concrete class is not possible.

Implementation trait behind the pekko.testkit.TestKit class: you may use this if inheriting from a concrete class is not possible.

This trait requires the concrete class mixing it in to provide an pekko.actor.ActorSystem which is available before this traits’s constructor is run. The recommended way is this:

class MyTest extends TestKitBase {
 implicit lazy val system = ActorSystem() // may add arguments here
 ...
}

Attributes

Source
TestKit.scala
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class TestKit
class TestProbe

Attributes

Source
TestKitExtension.scala
Supertypes
class Object
trait Matchable
class Any
Self type
class TestKitSettings(val config: Config) extends Extension

Attributes

Source
TestKitExtension.scala
Supertypes
trait Extension
class Object
trait Matchable
class Any
object TestLatch

A count down latch wrapper for use in testing. It always uses a timeout when waiting and timeouts are specified as durations. There's a default timeout of 5 seconds and the default count is 1. Timeouts will always throw an exception (no need to wrap in assert in tests). Timeouts are multiplied by the testing time factor for Jenkins builds.

A count down latch wrapper for use in testing. It always uses a timeout when waiting and timeouts are specified as durations. There's a default timeout of 5 seconds and the default count is 1. Timeouts will always throw an exception (no need to wrap in assert in tests). Timeouts are multiplied by the testing time factor for Jenkins builds.

Attributes

Companion
class
Source
TestLatch.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestLatch.type
class TestLatch(count: Int)(implicit system: ActorSystem) extends Awaitable[Unit]

Attributes

Companion
object
Source
TestLatch.scala
Supertypes
trait Awaitable[Unit]
class Object
trait Matchable
class Any
class TestProbe(_application: ActorSystem, name: String) extends TestKit

TestKit-based probe which allows sending, reception and reply.

TestKit-based probe which allows sending, reception and reply.

Attributes

Companion
object
Source
TestKit.scala
Supertypes
class TestKit
trait TestKitBase
class Object
trait Matchable
class Any
object TestProbe

Attributes

Companion
class
Source
TestKit.scala
Supertypes
class Object
trait Matchable
class Any
Self type
TestProbe.type
final case class WarningFilter(source: Option[String], message: Either[String, Regex], complete: Boolean)(occurrences: Int) extends EventFilter

Filter which matches Warning events, if they satisfy the given criteria:

Filter which matches Warning events, if they satisfy the given criteria:

  • source, if given, applies a filter on the event’s origin

  • message applies a filter on the event’s message (either with String.startsWith or Regex.findFirstIn().isDefined)

If you want to match all Warning events, the most efficient is to use Left("").

Attributes

Source
TestEventListener.scala
Supertypes
trait Serializable
trait Product
trait Equals
class EventFilter
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def filterEvents[T](eventFilters: Iterable[EventFilter])(block: => T)(implicit system: ActorSystem): T

Attributes

Source
package.scala
def filterEvents[T](eventFilters: EventFilter*)(block: => T)(implicit system: ActorSystem): T

Attributes

Source
package.scala
def filterException[T <: Throwable](block: => Unit)(implicit system: ActorSystem, t: ClassTag[T]): Unit

Attributes

Source
package.scala

Implicits

Implicits

final implicit def TestDuration(duration: FiniteDuration): TestDuration

Scala API. Scale timeouts (durations) during tests with the configured 'pekko.test.timefactor'. Implicit class providing dilated method.

Scala API. Scale timeouts (durations) during tests with the configured 'pekko.test.timefactor'. Implicit class providing dilated method.

import scala.concurrent.duration._
import org.apache.pekko.testkit._
10.milliseconds.dilated

Corresponding Java API is available in JavaTestKit.dilated()

Attributes

Source
package.scala