TestKit

org.apache.pekko.testkit.javadsl.TestKit
See theTestKit companion object
class TestKit(system: ActorSystem)

Java API: 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.

Beware of two points:

  • the ActorSystem passed into the constructor needs to be shutdown, otherwise thread pools and memory will be leaked - this trait is not thread-safe (only one actor with one queue, one stack of Within blocks); 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 the dilated method, which uses the TestKitExtension.Settings.TestTimeFactor settable via pekko.conf entry "pekko.test.timefactor".

Attributes

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

Members list

Value members

Concrete methods

def awaitAssert[A](a: Supplier[A]): A

Evaluate the given assert every interval until it does not throw an exception and return the result.

Evaluate the given assert every interval until it does not throw an exception and return the result.

If the max timeout expires the last exception is thrown.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Source
TestKit.scala
def awaitAssert[A](max: Duration, a: Supplier[A]): A

Evaluate the given assert every interval until it does not throw an exception and return the result.

Evaluate the given assert every interval until it does not throw an exception and return the result.

If the max timeout expires the last exception is thrown.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Source
TestKit.scala
def awaitAssert[A](max: Duration, interval: Duration, a: Supplier[A]): A

Evaluate the given assert every interval until it does not throw an exception. If the max timeout expires the last exception is thrown.

Evaluate the given assert every interval until it does not throw an exception. If the max timeout expires the last exception is thrown.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Returns

an arbitrary value that would be returned from awaitAssert if successful, if not interested in such value you can return null.

Source
TestKit.scala
def awaitCond(p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Source
TestKit.scala
def awaitCond(max: Duration, p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Source
TestKit.scala
def awaitCond(max: Duration, interval: Duration, p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Source
TestKit.scala
def awaitCond(max: Duration, interval: Duration, message: String, p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Source
TestKit.scala
def childActorOf(props: Props, name: String, supervisorStrategy: SupervisorStrategy): ActorRef

Spawns an actor as a child of this test actor, and returns the child's ActorRef.

Spawns an actor as a child of this test actor, and returns the child's ActorRef.

Attributes

Source
TestKit.scala
def childActorOf(props: Props, supervisorStrategy: SupervisorStrategy): ActorRef

Spawns an actor as a child of this test actor with an auto-generated name, and returns the child's ActorRef.

Spawns an actor as a child of this test actor with an auto-generated name, and returns the child's ActorRef.

Attributes

Source
TestKit.scala
def childActorOf(props: Props, name: String): ActorRef

Spawns an actor as a child of this test actor with a stopping supervisor strategy, and returns the child's ActorRef.

Spawns an actor as a child of this test actor with a stopping supervisor strategy, and returns the child's ActorRef.

Attributes

Source
TestKit.scala
def childActorOf(props: Props): ActorRef

Spawns an actor as a child of this test actor with an auto-generated name and stopping supervisor strategy, returning the child's ActorRef.

Spawns an actor as a child of this test actor with an auto-generated name and stopping supervisor strategy, returning the child's ActorRef.

Attributes

Source
TestKit.scala
def dilated(duration: Duration): Duration

Java timeouts (durations) during tests with the configured

Java timeouts (durations) during tests with the configured

Attributes

Source
TestKit.scala

Attributes

Source
TestKit.scala
def expectMsg[T](obj: T): T

Same as expectMsg(remainingOrDefault, obj), but correctly treating the timeFactor.

Same as expectMsg(remainingOrDefault, obj), but correctly treating the timeFactor.

Attributes

Source
TestKit.scala
def expectMsg[T](max: Duration, obj: T): T

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Source
TestKit.scala
def expectMsg[T](max: Duration, obj: T, hint: String): T

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Source
TestKit.scala
def expectMsgAllOf[T](objs: T*): List[T]

Same as expectMsgAllOf(remainingOrDefault, obj...), but correctly treating the timeFactor.

Same as expectMsgAllOf(remainingOrDefault, obj...), but correctly treating the timeFactor.

Attributes

Source
TestKit.scala
def expectMsgAllOfWithin[T](max: Duration, objs: T*): List[T]

Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Source
TestKit.scala
def expectMsgAnyClassOf[T](objs: Class[_]*): T

Same as expectMsgAnyClassOf(remainingOrDefault, obj...), but correctly treating the timeFactor.

Same as expectMsgAnyClassOf(remainingOrDefault, obj...), but correctly treating the timeFactor.

Attributes

Source
TestKit.scala
def expectMsgAnyClassOf[T](max: Duration, objs: Class[_]*): T

Receive one message from the test actor and assert that it conforms to one of the given classes. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it conforms to one of the given classes. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Source
TestKit.scala
def expectMsgAnyOf[T](first: T, objs: T*): T

Same as expectMsgAnyOf(remainingOrDefault, obj...), but correctly treating the timeFactor.

Same as expectMsgAnyOf(remainingOrDefault, obj...), but correctly treating the timeFactor.

Attributes

Source
TestKit.scala
def expectMsgAnyOfWithin[T](max: Duration, objs: T*): T

Receive one message from the test actor and assert that it equals one of the given objects. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals one of the given objects. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Source
TestKit.scala
def expectMsgClass[T](c: Class[T]): T

Same as expectMsgClass(remainingOrDefault, c), but correctly treating the timeFactor.

Same as expectMsgClass(remainingOrDefault, c), but correctly treating the timeFactor.

Attributes

Source
TestKit.scala
def expectMsgClass[T](max: Duration, c: Class[T]): T

Receive one message from the test actor and assert that it conforms to the given class. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it conforms to the given class. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Source
TestKit.scala
def expectMsgEquals[T](obj: T): T

Same as expectMsg(remainingOrDefault, obj), but correctly treating the timeFactor.

Same as expectMsg(remainingOrDefault, obj), but correctly treating the timeFactor.

Attributes

Source
TestKit.scala
def expectMsgEquals[T](max: Duration, obj: T): T

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Returns

the received object

Source
TestKit.scala
def expectMsgPF[T](hint: String, f: Function[Any, T]): T

Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Use this variant to implement more complicated or conditional processing.

Attributes

Source
TestKit.scala
def expectMsgPF[T](max: Duration, hint: String, f: Function[Any, T]): T

Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Use this variant to implement more complicated or conditional processing.

Attributes

Source
TestKit.scala

Assert that no message is received. Waits for the default period configured as pekko.actor.testkit.expect-no-message-default. That timeout is scaled using the configuration entry "pekko.actor.testkit.typed.timefactor".

Assert that no message is received. Waits for the default period configured as pekko.actor.testkit.expect-no-message-default. That timeout is scaled using the configuration entry "pekko.actor.testkit.typed.timefactor".

Attributes

Source
TestKit.scala
def expectNoMessage(max: Duration): Unit

Assert that no message is received for the specified time. Supplied value is not dilated.

Assert that no message is received for the specified time. Supplied value is not dilated.

Attributes

Source
TestKit.scala
def expectTerminated(max: Duration, target: ActorRef): Terminated

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Before calling this method, you have to watch the target actor ref. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Before calling this method, you have to watch the target actor ref. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Value parameters

max

wait no more than max time, otherwise throw AssertionFailure

target

the actor ref expected to be Terminated

Attributes

Returns

the received Terminated message

Source
TestKit.scala

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Before calling this method, you have to watch the target actor ref. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Before calling this method, you have to watch the target actor ref. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Value parameters

target

the actor ref expected to be Terminated

Attributes

Returns

the received Terminated message

Source
TestKit.scala
def fishForMessage(max: Duration, hint: String, f: Function[Any, Boolean]): Any

Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false. Use it to ignore certain messages while waiting for a specific message.

Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false. Use it to ignore certain messages while waiting for a specific message.

Attributes

Returns

the last received message, i.e. the first one for which the partial function returned true

Source
TestKit.scala
def fishForSpecificMessage[T](max: Duration, hint: String, f: Function[Any, T]): T

Same as fishForMessage, but gets a different partial function and returns properly typed message.

Same as fishForMessage, but gets a different partial function and returns properly typed message.

Attributes

Source
TestKit.scala
def forward(actor: ActorRef): Unit

Forward this message as if in the TestActor's receive method with self.forward.

Forward this message as if in the TestActor's receive method with self.forward.

Attributes

Source
TestKit.scala

Get the last sender of the TestProbe

Get the last sender of the TestProbe

Attributes

Source
TestKit.scala

Shorthand to get the testActor.

Shorthand to get the testActor.

Attributes

Source
TestKit.scala
def getRemaining: Duration

Obtain time remaining for execution of the innermost enclosing within block or throw an AssertionError if no within block surrounds this call.

Obtain time remaining for execution of the innermost enclosing within block or throw an AssertionError if no within block surrounds this call.

Attributes

Source
TestKit.scala
def getRemainingOr(duration: Duration): Duration

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the given duration.

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the given duration.

Attributes

Source
TestKit.scala
def getRemainingOrDefault: Duration

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the properly dilated default for this case from settings (key "pekko.test.single-expect-default").

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the properly dilated default for this case from settings (key "pekko.test.single-expect-default").

Attributes

Source
TestKit.scala

Attributes

Source
TestKit.scala

ActorRef of the test actor. Access is provided to enable e.g. registration as message target.

ActorRef of the test actor. Access is provided to enable e.g. registration as message target.

Attributes

Source
TestKit.scala
def ignoreMsg(pf: Function[Any, Boolean]): Unit

Ignore all messages in the test actor for which the given partial function returns true.

Ignore all messages in the test actor for which the given partial function returns true.

Attributes

Source
TestKit.scala
def ignoreNoMsg(): Unit

Stop ignoring messages in the test actor.

Stop ignoring messages in the test actor.

Attributes

Source
TestKit.scala

Query queue status.

Query queue status.

Attributes

Source
TestKit.scala
def receiveN(n: Int): List[AnyRef]

Same as receiveN(n, remaining) but correctly taking into account Duration.timeFactor.

Same as receiveN(n, remaining) but correctly taking into account Duration.timeFactor.

Attributes

Source
TestKit.scala
def receiveN(n: Int, max: Duration): List[AnyRef]

Receive N messages in a row before the given deadline.

Receive N messages in a row before the given deadline.

Attributes

Source
TestKit.scala
def receiveOne(max: Duration): AnyRef

Receive one message from the internal queue of the TestActor. If the given duration is zero, the queue is polled (non-blocking).

Receive one message from the internal queue of the TestActor. If the given duration is zero, the queue is polled (non-blocking).

This method does NOT automatically scale its Duration parameter!

Attributes

Source
TestKit.scala
def receiveWhile[T](max: Duration, idle: Duration, messages: Int, f: Function[AnyRef, T]): List[T]

Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Note that it is not an error to hit the max duration in this case.

One possible use of this method is for testing whether messages of certain characteristics are generated at a certain rate:

Attributes

Source
TestKit.scala
def receiveWhile[T](max: Duration, f: Function[AnyRef, T]): List[T]

Attributes

Source
TestKit.scala
def reply(msg: AnyRef): Unit

Send message to the sender of the last dequeued message.

Send message to the sender of the last dequeued message.

Attributes

Source
TestKit.scala
def send(actor: ActorRef, msg: AnyRef): Unit

Send message to an actor while using the probe's TestActor as the sender. Replies will be available for inspection with all of TestKit's assertion methods.

Send message to an actor while using the probe's TestActor as the sender. Replies will be available for inspection with all of TestKit's assertion methods.

Attributes

Source
TestKit.scala
def setAutoPilot(pilot: AutoPilot): Unit

Install an AutoPilot to drive the testActor: the AutoPilot will be run for each received message and can be used to send or forward messages, etc. Each invocation must return the AutoPilot for the next round.

Install an AutoPilot to drive the testActor: the AutoPilot will be run for each received message and can be used to send or forward messages, etc. Each invocation must return the AutoPilot for the next round.

Attributes

Source
TestKit.scala

Have the testActor stop watching someone (i.e. context.unwatch(...)).

Have the testActor stop watching someone (i.e. context.unwatch(...)).

Attributes

Source
TestKit.scala
def watch(ref: ActorRef): ActorRef

Have the testActor watch someone (i.e. context.watch(...)).

Have the testActor watch someone (i.e. context.watch(...)).

Attributes

Source
TestKit.scala
def within[T](min: Duration, max: Duration, f: Supplier[T]): T

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor", while the min Duration is not.


within(java.time.Duration.ofMillis(50), () -> {
  test.tell("ping");
  return expectMsgClass(String.class);
});

Attributes

Source
TestKit.scala
def within[T](max: Duration, f: Supplier[T]): T

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor", while the min Duration is not.


within(java.time.Duration.ofMillis(50), () -> {
  test.tell("ping");
  return expectMsgClass(String.class);
});

Attributes

Source
TestKit.scala

Deprecated methods

def awaitAssert[A](max: Duration, a: Supplier[A]): A

Evaluate the given assert every interval until it does not throw an exception and return the result.

Evaluate the given assert every interval until it does not throw an exception and return the result.

If the max timeout expires the last exception is thrown.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Deprecated
[Since version Akka 2.5.13]
Source
TestKit.scala
def awaitAssert[A](max: Duration, interval: Duration, a: Supplier[A]): A

Evaluate the given assert every interval until it does not throw an exception. If the max timeout expires the last exception is thrown.

Evaluate the given assert every interval until it does not throw an exception. If the max timeout expires the last exception is thrown.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Returns

an arbitrary value that would be returned from awaitAssert if successful, if not interested in such value you can return null.

Deprecated
[Since version Akka 2.5.13]
Source
TestKit.scala
def awaitCond(max: Duration, p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def awaitCond(max: Duration, interval: Duration, p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def awaitCond(max: Duration, interval: Duration, message: String, p: Supplier[Boolean]): Unit

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

Await until the given condition evaluates to true or the timeout expires, whichever comes first.

If no timeout is given, take it from the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor".

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala

Scale timeouts (durations) during tests with the configured

Scale timeouts (durations) during tests with the configured

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsg[T](max: FiniteDuration, obj: T): T

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsg[T](max: FiniteDuration, obj: T, hint: String): T

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsgAllOf[T](max: FiniteDuration, objs: T*): List[T]

Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive a number of messages from the test actor matching the given number of objects and assert that for each given object one is received which equals it and vice versa. This construct is useful when the order in which the objects are received is not fixed. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsgAnyClassOf[T](max: FiniteDuration, objs: Class[_]*): T

Receive one message from the test actor and assert that it conforms to one of the given classes. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it conforms to one of the given classes. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsgAnyOf[T](max: FiniteDuration, objs: T*): T

Receive one message from the test actor and assert that it equals one of the given objects. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals one of the given objects. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsgClass[T](max: FiniteDuration, c: Class[T]): T

Receive one message from the test actor and assert that it conforms to the given class. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it conforms to the given class. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsgEquals[T](max: FiniteDuration, obj: T): T

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it equals the given object. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Attributes

Returns

the received object

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectMsgPF[T](max: Duration, hint: String, f: Function[Any, T]): T

Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that the given partial function accepts it. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Use this variant to implement more complicated or conditional processing.

Attributes

Deprecated
[Since version Akka 2.6.0]
Source
TestKit.scala

Assert that no message is received for the specified time. Supplied value is not dilated.

Assert that no message is received for the specified time. Supplied value is not dilated.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def expectNoMsg(): Unit

Assert that no message is received. Waits for the default period configured as pekko.actor.testkit.expect-no-message-default. That timeout is scaled using the configuration entry "pekko.actor.testkit.typed.timefactor".

Assert that no message is received. Waits for the default period configured as pekko.actor.testkit.expect-no-message-default. That timeout is scaled using the configuration entry "pekko.actor.testkit.typed.timefactor".

Attributes

Deprecated
[Since version Akka 2.5.10] Use expectNoMessage instead
Source
TestKit.scala

Assert that no message is received for the specified time.

Assert that no message is received for the specified time.

Attributes

Deprecated
[Since version Akka 2.5.10] Use expectNoMessage instead
Source
TestKit.scala

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Before calling this method, you have to watch the target actor ref. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef. Before calling this method, you have to watch the target actor ref. Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.

Value parameters

max

wait no more than max time, otherwise throw AssertionFailure

target

the actor ref expected to be Terminated

Attributes

Returns

the received Terminated message

Deprecated
[Since version Akka 2.6.0]
Source
TestKit.scala
def fishForMessage(max: Duration, hint: String, f: Function[Any, Boolean]): Any

Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false. Use it to ignore certain messages while waiting for a specific message.

Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false. Use it to ignore certain messages while waiting for a specific message.

Attributes

Returns

the last received message, i.e. the first one for which the partial function returned true

Deprecated
[Since version Akka 2.6.0]
Source
TestKit.scala
def fishForSpecificMessage[T](max: Duration, hint: String, f: Function[Any, T]): T

Same as fishForMessage, but gets a different partial function and returns properly typed message.

Same as fishForMessage, but gets a different partial function and returns properly typed message.

Attributes

Deprecated
[Since version Akka 2.6.0]
Source
TestKit.scala
def receiveN(n: Int, max: FiniteDuration): List[AnyRef]

Receive N messages in a row before the given deadline.

Receive N messages in a row before the given deadline.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def receiveOne(max: Duration): AnyRef

Receive one message from the internal queue of the TestActor. If the given duration is zero, the queue is polled (non-blocking).

Receive one message from the internal queue of the TestActor. If the given duration is zero, the queue is polled (non-blocking).

This method does NOT automatically scale its Duration parameter!

Attributes

Deprecated
[Since version Akka 2.5.13]
Source
TestKit.scala
def receiveWhile[T](max: Duration, idle: Duration, messages: Int, f: Function[AnyRef, T]): List[T]

Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Receive a series of messages until one does not match the given partial function or the idle timeout is met (disabled by default) or the overall maximum duration is elapsed or expected messages count is reached. Returns the sequence of messages.

Note that it is not an error to hit the max duration in this case.

One possible use of this method is for testing whether messages of certain characteristics are generated at a certain rate:

Attributes

Deprecated
[Since version Akka 2.5.13]
Source
TestKit.scala
def receiveWhile[T](max: Duration, f: Function[AnyRef, T]): List[T]

Attributes

Deprecated
[Since version Akka 2.5.13]
Source
TestKit.scala

Obtain time remaining for execution of the innermost enclosing within block or throw an AssertionError if no within block surrounds this call.

Obtain time remaining for execution of the innermost enclosing within block or throw an AssertionError if no within block surrounds this call.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the given duration.

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the given duration.

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the properly dilated default for this case from settings (key "pekko.test.single-expect-default").

Obtain time remaining for execution of the innermost enclosing within block or missing that it returns the properly dilated default for this case from settings (key "pekko.test.single-expect-default").

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def within[T](min: FiniteDuration, max: FiniteDuration, f: Supplier[T]): T

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor", while the min Duration is not.


within(duration("50 millis"), () -> {
  test.tell("ping");
  return expectMsgClass(String.class);
});

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala
def within[T](max: FiniteDuration, f: Supplier[T]): T

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Execute code block while bounding its execution time between min and max. within blocks may be nested. All methods in this trait which take maximum wait times are available in a version which implicitly uses the remaining time governed by the innermost enclosing within block.

Note that the timeout is scaled using Duration.dilated, which uses the configuration entry "pekko.test.timefactor", while the min Duration is not.


within(duration("50 millis"), () -> {
  test.tell("ping");
  return expectMsgClass(String.class);
});

Attributes

Deprecated
[Since version Akka 2.5.12]
Source
TestKit.scala