TO BE DEFINED BY USER: Defines the number of participants required for starting the test.
TO BE DEFINED BY USER: Defines the number of participants required for starting the test. This might not be equals to the number of nodes available to the test.
Must be a def
:
def initialParticipants = 5
Override this method to do something when the whole test is starting up.
Override this method to do something when the whole test is starting up.
Override this method to do something when the whole test is terminating.
Override this method to do something when the whole test is terminating.
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".
Enrich .await()
onto all Awaitables, using remaining duration from the innermost
enclosing within
block or QueryTimeout.
Enter the named barriers in the order given.
Enter the named barriers in the order given. Use the remaining duration from
the innermost enclosing within
block or the default BarrierTimeout
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(remaining, obj)
, but correctly treating the timeFactor.
Same as expectMsg(remaining, obj)
, but correctly treating the timeFactor.
Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which is of that class (equality, not conformance).
Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which is of that class (equality, not conformance). 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 expectMsgAllClassOf(remaining, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAllClassOf(remaining, obj...)
, but correctly treating the timeFactor.
Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which conforms to that class (and vice versa).
Receive a number of messages from the test actor matching the given number of classes and assert that for each given class one is received which conforms to that class (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.
Beware that one object may satisfy all given class constraints, which may be counter-intuitive.
Same as expectMsgAllConformingOf(remaining, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAllConformingOf(remaining, 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.
dispatcher ! SomeWork1() dispatcher ! SomeWork2() expectMsgAllOf(1 second, Result1(), Result2())
Same as expectMsgAllOf(remaining, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAllOf(remaining, 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.
the received object
Same as expectMsgAnyClassOf(remaining, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAnyClassOf(remaining, 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.
the received object
Same as expectMsgAnyOf(remaining, obj...)
, but correctly treating the timeFactor.
Same as expectMsgAnyOf(remaining, 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.
the received object
Same as expectMsgClass(remaining, c)
, but correctly treating the timeFactor.
Same as expectMsgClass(remaining, c)
, 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.
the received object as transformed by the partial function
Receive one message from the test actor and assert that it conforms to the given type (after erasure).
Receive one message from the test actor and assert that it conforms to the given type (after erasure). Wait time is bounded by the given duration, with an AssertionFailure being thrown in case of timeout.
the received object
Same as expectMsgType[T](remaining)
, but correctly treating the timeFactor.
Same as expectMsgType[T](remaining)
, but correctly treating the timeFactor.
Assert that no message is received for the specified time.
Assert that no message is received for the specified time.
Same as expectNoMsg(remaining)
, but correctly treating the timeFactor.
Same as expectNoMsg(remaining)
, but correctly treating the timeFactor.
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 messsage, i.e. the first one for which the partial function returned true
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.
Stop ignoring messages in the test actor.
Stop ignoring messages in the test actor.
Verify that the running node matches one of the given nodes
Query queue status.
Query queue status.
Call this after the all test cases have run.
Call this after the all test cases have run. NOT after every test case.
Call this before the start of the test run.
Call this before the start of the test run. NOT before every test case.
Query the controller for the transport address of the given node (by role name) and return that as an ActorPath for easy composition:
Query the controller for the transport address of the given node (by role name) and return that as an ActorPath for easy composition:
val serviceA = system.actorFor(node("master") / "user" / "serviceA")
Obtain current time (System.nanoTime
) as Duration.
Obtain current time (System.nanoTime
) as Duration.
Receive N messages in a row before the given deadline.
Receive N messages in a row before the given deadline.
Same as receiveN(n, remaining)
but correctly taking into account
Duration.
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.
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. 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:
test ! ScheduleTicks(100 millis) val series = receiveWhile(750 millis) { case Tick(count) => count } assert(series == (1 to 7).toList)
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.
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 given duration.
Obtain time remaining for execution of the innermost enclosing within
block or missing that it returns the given duration.
All registered roles
Execute the given block of code only on the given nodes (names according
to the roleMap
).
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.
ActorRef of the test actor.
ActorRef of the test actor. Access is provided to enable e.g. registration as message target.
Access to the barriers, failure injection, etc.
Access to the barriers, failure injection, etc. The extension will have been started either in Conductor or Player mode when the constructor of MultiNodeSpec finishes, i.e. do not call the start*() methods yourself!
Have the testActor stop watching someone (i.
Have the testActor stop watching someone (i.e. context.unwatch(...)
).
Override this and return true
to assert that the
shutdown of the ActorSystem
was done properly.
Have the testActor watch someone (i.
Have the testActor watch someone (i.e. context.watch(...)
).
Same as calling within(0 seconds, max)(f)
.
Same as calling within(0 seconds, max)(f)
.
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.
val ret = within(50 millis) { test ! "ping" expectMsgClass(classOf[String]) }
Note: To be able to run tests with everything ignored or excluded by tags you must not use
testconductor
, or helper methods that usetestconductor
, from the constructor of your test class. Otherwise the controller node might be shutdown before other nodes have completed and you will see errors like:AskTimeoutException: sending to terminated ref breaks promises
. Using lazy val is fine.