Evaluate the given assert every interval
until it does not throw an exception.
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 "akka.test.timefactor".
an arbitrary value that would be returned from awaitAssert if successful, if not interested in such value you can return null.
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 "akka.test.timefactor".
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 "akka.test.timefactor".
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 "akka.test.timefactor".
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 "akka.test.timefactor".
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 "akka.test.timefactor".
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 "akka.test.timefactor".
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 a stopping supervisor strategy, 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.
Spawns an actor as a child of this test actor, and returns the child's ActorRef.
Java timeouts (durations) during tests with the configured
Receive one message from the test actor and assert that it equals the given object.
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.
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.
Same as expectMsg(remainingOrDefault, obj)
, but correctly treating the timeFactor.
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.
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.
Same as expectMsgAllOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAllOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.
Receive one message from the test actor and assert that it conforms to one of the given classes.
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.
Same as expectMsgAnyClassOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAnyClassOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.
Receive one message from the test actor and assert that it equals one of the given objects.
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.
Same as expectMsgAnyOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAnyOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.
Receive one message from the test actor and assert that it conforms to the given class.
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.
Same as expectMsgClass(remainingOrDefault, c)
, but correctly treating the timeFactor.
Receive one message from the test actor and assert that it equals the given object.
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.
the received object
Same as expectMsg(remainingOrDefault, obj)
, but correctly treating the timeFactor.
Receive one message from the test actor and assert that the given partial function accepts it.
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.
Receive one message from the test actor and assert that the given partial function accepts it.
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.
Receive one message from the test actor and assert that the given partial function accepts it.
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.
Assert that no message is received for the specified time.
Assert that no message is received for the specified time. Supplied value is not dilated.
Same as expectNoMessage(remainingOrDefault)
, but correctly treating the timeFactor.
Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef.
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.
the actor ref expected to be Terminated
the received Terminated message
Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef.
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.
wait no more than max time, otherwise throw AssertionFailure
the actor ref expected to be Terminated
the received Terminated message
Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef.
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.
wait no more than max time, otherwise throw AssertionFailure
the actor ref expected to be Terminated
the received Terminated message
Hybrid of expectMsgPF and receiveWhile: receive messages while the partial function matches and returns false.
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.
the last received message, i.e. the first one for which the partial function returned true
Same as fishForMessage
, but gets a different partial function and returns properly typed message.
Forward this message as if in the TestActor's receive method with self.forward.
Get the last sender of the TestProbe
Shorthand to get the testActor.
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 missing that it returns the given 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 "akka.test.single-expect-default").
ActorRef of the test actor.
ActorRef of the test actor. Access is provided to enable e.g. registration as message target.
Ignore all messages in the test actor for which the given partial function returns true.
Stop ignoring messages in the test actor.
Query queue status.
Receive N messages in a row before the given deadline.
Same as receiveN(n, remaining)
but correctly taking into account
Duration.timeFactor.
Receive one message from the internal queue of the TestActor.
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!
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.
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:
Send message to the sender of the last dequeued message.
Send message to an actor while using the probe's TestActor as the sender.
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.
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.
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.
Have the testActor stop watching someone (i.e.
Have the testActor stop watching someone (i.e. context.unwatch(...)
).
Have the testActor watch someone (i.e.
Have the testActor watch someone (i.e. context.watch(...)
).
Execute code block while bounding its execution time between min
and
max
.
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 "akka.test.timefactor", while the min Duration is not.
within(java.time.Duration.ofMillis(50), () -> { test.tell("ping"); return expectMsgClass(String.class); });
Execute code block while bounding its execution time between min
and
max
.
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 "akka.test.timefactor", while the min Duration is not.
within(java.time.Duration.ofMillis(50), () -> { test.tell("ping"); return expectMsgClass(String.class); });
Evaluate the given assert every interval
until it does not throw an exception.
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 "akka.test.timefactor".
an arbitrary value that would be returned from awaitAssert if successful, if not interested in such value you can return null.
(Since version 2.5.13) Use the overloaded one which accepts java.time.Duration instead.
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 "akka.test.timefactor".
(Since version 2.5.13) Use the overloaded one which accepts java.time.Duration instead.
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 "akka.test.timefactor".
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
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 "akka.test.timefactor".
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
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 "akka.test.timefactor".
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Scale timeouts (durations) during tests with the configured
Scale timeouts (durations) during tests with the configured
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the test actor and assert that it equals the given object.
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.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the test actor and assert that it equals the given object.
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.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
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.
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.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the test actor and assert that it conforms to one of the given classes.
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.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the test actor and assert that it equals one of the given objects.
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.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the test actor and assert that it conforms to the given class.
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.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the test actor and assert that it equals the given object.
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.
the received object
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Assert that no message is received for the specified time.
Assert that no message is received for the specified time. Supplied value is not dilated.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Assert that no message is received for the specified time.
Assert that no message is received for the specified time.
(Since version 2.5.10) Use expectNoMessage instead
Same as expectNoMsg(remainingOrDefault)
, but correctly treating the timeFactor.
Same as expectNoMsg(remainingOrDefault)
, but correctly treating the timeFactor.
(Since version 2.5.10) Use expectNoMessage instead
Receive N messages in a row before the given deadline.
Receive N messages in a row before the given deadline.
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Receive one message from the internal queue of the TestActor.
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!
(Since version 2.5.13) Use the overloaded one which accepts java.time.Duration instead.
(Since version 2.5.13) Use the overloaded one which accepts java.time.Duration instead.
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.
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:
(Since version 2.5.13) Use the overloaded one which accepts java.time.Duration instead.
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.
(Since version 2.5.12) Use getRemaining which returns java.time.Duration instead.
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.
(Since version 2.5.12) Use getRemainingOr which returns java.time.Duration instead.
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 "akka.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 "akka.test.single-expect-default").
(Since version 2.5.12) Use getRemainingOrDefault which returns java.time.Duration instead.
Execute code block while bounding its execution time between min
and
max
.
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 "akka.test.timefactor", while the min Duration is not.
within(duration("50 millis"), () -> { test.tell("ping"); return expectMsgClass(String.class); });
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
Execute code block while bounding its execution time between min
and
max
.
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 "akka.test.timefactor", while the min Duration is not.
within(duration("50 millis"), () -> { test.tell("ping"); return expectMsgClass(String.class); });
(Since version 2.5.12) Use the overloaded one which accepts java.time.Duration instead.
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 ofWithin
blocks.Beware of two points:
Within
blocks); take care not to run tests within a single test class instance in parallel.dilated
method, which uses the TestKitExtension.Settings.TestTimeFactor settable via akka.conf entry "akka.test.timefactor".