public interface TestKitBase
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
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
...
}
Modifier and Type | Method and Description |
---|---|
void |
awaitAssert(scala.Function0<java.lang.Object> a,
scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration interval)
Await until the given assert does not throw an exception or the timeout
expires, whichever comes first.
|
void |
awaitCond(scala.Function0<java.lang.Object> p,
scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration interval,
java.lang.String message)
Await until the given condition evaluates to
true or the timeout
expires, whichever comes first. |
void |
checkMissingAndUnexpected(scala.collection.Seq<java.lang.Object> missing,
scala.collection.Seq<java.lang.Object> unexpected,
java.lang.String missingMessage,
java.lang.String unexpectedMessage) |
ActorRef |
childActorOf(Props props)
Spawns an actor as a child of this test actor with an auto-generated name and stopping supervisor strategy, returning the child's ActorRef.
|
ActorRef |
childActorOf(Props props,
java.lang.String name)
Spawns an actor as a child of this test actor with a stopping supervisor strategy, and returns the child's ActorRef.
|
ActorRef |
childActorOf(Props props,
java.lang.String name,
SupervisorStrategy supervisorStrategy)
Spawns an actor as a child of this test actor, and returns the child's ActorRef.
|
ActorRef |
childActorOf(Props props,
SupervisorStrategy supervisorStrategy)
Spawns an actor as a child of this test actor with an auto-generated name, and returns the child's ActorRef.
|
<T> T |
expectMsg_internal(scala.concurrent.duration.Duration max,
T obj,
scala.Option<java.lang.String> hint) |
<T> T |
expectMsg(scala.concurrent.duration.FiniteDuration max,
java.lang.String hint,
T obj)
Receive one message from the test actor and assert that it equals the
given object.
|
<T> T |
expectMsg(scala.concurrent.duration.FiniteDuration max,
T obj)
Receive one message from the test actor and assert that it equals the
given object.
|
<T> T |
expectMsg(T obj)
Same as
expectMsg(remainingOrDefault, obj) , but correctly treating the timeFactor. |
<T> scala.collection.immutable.Seq<T> |
expectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj)
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).
|
<T> scala.collection.immutable.Seq<T> |
expectMsgAllClassOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
Same as
expectMsgAllClassOf(remainingOrDefault, obj...) , but correctly treating the timeFactor. |
<T> scala.collection.immutable.Seq<T> |
expectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj)
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).
|
<T> scala.collection.immutable.Seq<T> |
expectMsgAllConformingOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
Same as
expectMsgAllConformingOf(remainingOrDefault, obj...) , but correctly treating the timeFactor. |
<T> scala.collection.immutable.Seq<T> |
expectMsgAllOf_internal(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj) |
<T> scala.collection.immutable.Seq<T> |
expectMsgAllOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj)
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.
|
<T> scala.collection.immutable.Seq<T> |
expectMsgAllOf(scala.collection.Seq<T> obj)
Same as
expectMsgAllOf(remainingOrDefault, obj...) , but correctly treating the timeFactor. |
<C> C |
expectMsgAnyClassOf_internal(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends C>> obj) |
<C> C |
expectMsgAnyClassOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends C>> obj)
Receive one message from the test actor and assert that it conforms to
one of the given classes.
|
<C> C |
expectMsgAnyClassOf(scala.collection.Seq<java.lang.Class<? extends C>> obj)
Same as
expectMsgAnyClassOf(remainingOrDefault, obj...) , but correctly treating the timeFactor. |
<T> T |
expectMsgAnyOf_internal(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj) |
<T> T |
expectMsgAnyOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<T> obj)
Receive one message from the test actor and assert that it equals one of
the given objects.
|
<T> T |
expectMsgAnyOf(scala.collection.Seq<T> obj)
Same as
expectMsgAnyOf(remainingOrDefault, obj...) , but correctly treating the timeFactor. |
<C> C |
expectMsgClass_internal(scala.concurrent.duration.FiniteDuration max,
java.lang.Class<C> c) |
<C> C |
expectMsgClass(java.lang.Class<C> c)
Same as
expectMsgClass(remainingOrDefault, c) , but correctly treating the timeFactor. |
<C> C |
expectMsgClass(scala.concurrent.duration.FiniteDuration max,
java.lang.Class<C> c)
Receive one message from the test actor and assert that it conforms to
the given class.
|
<T> T |
expectMsgPF(scala.concurrent.duration.Duration max,
java.lang.String hint,
scala.PartialFunction<java.lang.Object,T> f)
Receive one message from the test actor and assert that the given
partial function accepts it.
|
<T> T |
expectMsgType(scala.reflect.ClassTag<T> t)
Same as
expectMsgType[T](remainingOrDefault) , but correctly treating the timeFactor. |
<T> T |
expectMsgType(scala.concurrent.duration.FiniteDuration max,
scala.reflect.ClassTag<T> t)
Receive one message from the test actor and assert that it conforms to the
given type (after erasure).
|
void |
expectNoMsg_internal(scala.concurrent.duration.FiniteDuration max) |
void |
expectNoMsg()
Same as
expectNoMsg(remainingOrDefault) , but correctly treating the timeFactor. |
void |
expectNoMsg(scala.concurrent.duration.FiniteDuration max)
Assert that no message is received for the specified time.
|
Terminated |
expectTerminated(ActorRef target,
scala.concurrent.duration.Duration max)
Receive one message from the test actor and assert that it is the Terminated message of the given ActorRef.
|
java.lang.Object |
fishForMessage(scala.concurrent.duration.Duration max,
java.lang.String hint,
scala.PartialFunction<java.lang.Object,java.lang.Object> f)
Hybrid of expectMsgPF and receiveWhile: receive messages while the
partial function matches and returns false.
|
java.lang.String |
format(java.util.concurrent.TimeUnit u,
scala.concurrent.duration.Duration d) |
void |
ignoreMsg(scala.PartialFunction<java.lang.Object,java.lang.Object> f)
Ignore all messages in the test actor for which the given partial
function returns true.
|
void |
ignoreNoMsg()
Stop ignoring messages in the test actor.
|
<T> scala.collection.immutable.Seq<T> |
internalExpectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj) |
<T> scala.collection.immutable.Seq<T> |
internalExpectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max,
scala.collection.Seq<java.lang.Class<? extends T>> obj) |
TestActor.Message |
lastMessage() |
ActorRef |
lastSender() |
boolean |
msgAvailable()
Query queue status.
|
scala.concurrent.duration.FiniteDuration |
now()
Obtain current time (
System.nanoTime ) as Duration. |
scala.collection.immutable.Seq<java.lang.Object> |
receiveN_internal(int n,
scala.concurrent.duration.Duration max) |
scala.collection.immutable.Seq<java.lang.Object> |
receiveN(int n)
Same as
receiveN(n, remaining) but correctly taking into account
Duration.timeFactor. |
scala.collection.immutable.Seq<java.lang.Object> |
receiveN(int n,
scala.concurrent.duration.FiniteDuration max)
Receive N messages in a row before the given deadline.
|
java.lang.Object |
receiveOne(scala.concurrent.duration.Duration max)
Receive one message from the internal queue of the TestActor.
|
<T> scala.collection.immutable.Seq<T> |
receiveWhile(scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration idle,
int messages,
scala.PartialFunction<java.lang.Object,T> f)
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.
|
scala.concurrent.duration.FiniteDuration |
remaining()
Obtain time remaining for execution of the innermost enclosing
within
block or throw an AssertionError if no within block surrounds this
call. |
scala.concurrent.duration.FiniteDuration |
remainingOr(scala.concurrent.duration.FiniteDuration duration)
Obtain time remaining for execution of the innermost enclosing
within
block or missing that it returns the given duration. |
scala.concurrent.duration.FiniteDuration |
remainingOrDefault()
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"). |
scala.concurrent.duration.FiniteDuration |
remainingOrDilated(scala.concurrent.duration.Duration max) |
void |
setAutoPilot(TestActor.AutoPilot pilot)
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.
|
void |
shutdown(ActorSystem actorSystem,
scala.concurrent.duration.Duration duration,
boolean verifySystemShutdown)
Shut down an actor system and wait for termination.
|
ActorSystem |
system() |
ActorRef |
testActor()
ActorRef of the test actor.
|
java.lang.String |
testActorName()
Defines the testActor name.
|
TestKitSettings |
testKitSettings() |
ActorRef |
unwatch(ActorRef ref)
Have the testActor stop watching someone (i.e.
|
ActorRef |
watch(ActorRef ref)
Have the testActor watch someone (i.e.
|
<T> T |
within(scala.concurrent.duration.FiniteDuration min,
scala.concurrent.duration.FiniteDuration max,
scala.Function0<T> f)
Execute code block while bounding its execution time between
min and
max . |
<T> T |
within(scala.concurrent.duration.FiniteDuration max,
scala.Function0<T> f)
Same as calling
within(0 seconds, max)(f) . |
ActorSystem system()
TestKitSettings testKitSettings()
TestActor.Message lastMessage()
ActorRef lastSender()
java.lang.String testActorName()
ActorRef testActor()
void ignoreMsg(scala.PartialFunction<java.lang.Object,java.lang.Object> f)
f
- (undocumented)void ignoreNoMsg()
ActorRef watch(ActorRef ref)
context.watch(...)
).ref
- (undocumented)ActorRef unwatch(ActorRef ref)
context.unwatch(...)
).ref
- (undocumented)void setAutoPilot(TestActor.AutoPilot pilot)
pilot
- (undocumented)scala.concurrent.duration.FiniteDuration now()
System.nanoTime
) as Duration.scala.concurrent.duration.FiniteDuration remainingOrDefault()
within
block or missing that it returns the properly dilated default for this
case from settings (key "akka.test.single-expect-default").scala.concurrent.duration.FiniteDuration remaining()
within
block or throw an AssertionError
if no within
block surrounds this
call.scala.concurrent.duration.FiniteDuration remainingOr(scala.concurrent.duration.FiniteDuration duration)
within
block or missing that it returns the given duration.duration
- (undocumented)scala.concurrent.duration.FiniteDuration remainingOrDilated(scala.concurrent.duration.Duration max)
boolean msgAvailable()
void awaitCond(scala.Function0<java.lang.Object> p, scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration interval, java.lang.String message)
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".
p
- (undocumented)max
- (undocumented)interval
- (undocumented)message
- (undocumented)void awaitAssert(scala.Function0<java.lang.Object> a, scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration interval)
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".
a
- (undocumented)max
- (undocumented)interval
- (undocumented)<T> T within(scala.concurrent.duration.FiniteDuration min, scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
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])
}
min
- (undocumented)max
- (undocumented)f
- (undocumented)<T> T within(scala.concurrent.duration.FiniteDuration max, scala.Function0<T> f)
within(0 seconds, max)(f)
.max
- (undocumented)f
- (undocumented)<T> T expectMsg(T obj)
expectMsg(remainingOrDefault, obj)
, but correctly treating the timeFactor.obj
- (undocumented)<T> T expectMsg(scala.concurrent.duration.FiniteDuration max, T obj)
max
- (undocumented)obj
- (undocumented)<T> T expectMsg(scala.concurrent.duration.FiniteDuration max, java.lang.String hint, T obj)
max
- (undocumented)hint
- (undocumented)obj
- (undocumented)<T> T expectMsg_internal(scala.concurrent.duration.Duration max, T obj, scala.Option<java.lang.String> hint)
<T> T expectMsgPF(scala.concurrent.duration.Duration max, java.lang.String hint, scala.PartialFunction<java.lang.Object,T> f)
Use this variant to implement more complicated or conditional processing.
max
- (undocumented)hint
- (undocumented)f
- (undocumented)Terminated expectTerminated(ActorRef target, scala.concurrent.duration.Duration max)
target
- (undocumented)max
- (undocumented)java.lang.Object fishForMessage(scala.concurrent.duration.Duration max, java.lang.String hint, scala.PartialFunction<java.lang.Object,java.lang.Object> f)
max
- (undocumented)hint
- (undocumented)f
- (undocumented)<T> T expectMsgType(scala.reflect.ClassTag<T> t)
expectMsgType[T](remainingOrDefault)
, but correctly treating the timeFactor.t
- (undocumented)<T> T expectMsgType(scala.concurrent.duration.FiniteDuration max, scala.reflect.ClassTag<T> t)
max
- (undocumented)t
- (undocumented)<C> C expectMsgClass(java.lang.Class<C> c)
expectMsgClass(remainingOrDefault, c)
, but correctly treating the timeFactor.c
- (undocumented)<C> C expectMsgClass(scala.concurrent.duration.FiniteDuration max, java.lang.Class<C> c)
max
- (undocumented)c
- (undocumented)<C> C expectMsgClass_internal(scala.concurrent.duration.FiniteDuration max, java.lang.Class<C> c)
<T> T expectMsgAnyOf(scala.collection.Seq<T> obj)
expectMsgAnyOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.obj
- (undocumented)<T> T expectMsgAnyOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
max
- (undocumented)obj
- (undocumented)<T> T expectMsgAnyOf_internal(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
<C> C expectMsgAnyClassOf(scala.collection.Seq<java.lang.Class<? extends C>> obj)
expectMsgAnyClassOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.obj
- (undocumented)<C> C expectMsgAnyClassOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends C>> obj)
max
- (undocumented)obj
- (undocumented)<C> C expectMsgAnyClassOf_internal(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends C>> obj)
<T> scala.collection.immutable.Seq<T> expectMsgAllOf(scala.collection.Seq<T> obj)
expectMsgAllOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.obj
- (undocumented)<T> scala.collection.immutable.Seq<T> expectMsgAllOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
dispatcher ! SomeWork1() dispatcher ! SomeWork2() expectMsgAllOf(1 second, Result1(), Result2())
max
- (undocumented)obj
- (undocumented)void checkMissingAndUnexpected(scala.collection.Seq<java.lang.Object> missing, scala.collection.Seq<java.lang.Object> unexpected, java.lang.String missingMessage, java.lang.String unexpectedMessage)
<T> scala.collection.immutable.Seq<T> expectMsgAllOf_internal(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<T> obj)
<T> scala.collection.immutable.Seq<T> expectMsgAllClassOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
expectMsgAllClassOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.obj
- (undocumented)<T> scala.collection.immutable.Seq<T> expectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
max
- (undocumented)obj
- (undocumented)<T> scala.collection.immutable.Seq<T> internalExpectMsgAllClassOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
<T> scala.collection.immutable.Seq<T> expectMsgAllConformingOf(scala.collection.Seq<java.lang.Class<? extends T>> obj)
expectMsgAllConformingOf(remainingOrDefault, obj...)
, but correctly treating the timeFactor.obj
- (undocumented)<T> scala.collection.immutable.Seq<T> expectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
Beware that one object may satisfy all given class constraints, which may be counter-intuitive.
max
- (undocumented)obj
- (undocumented)<T> scala.collection.immutable.Seq<T> internalExpectMsgAllConformingOf(scala.concurrent.duration.FiniteDuration max, scala.collection.Seq<java.lang.Class<? extends T>> obj)
void expectNoMsg()
expectNoMsg(remainingOrDefault)
, but correctly treating the timeFactor.void expectNoMsg(scala.concurrent.duration.FiniteDuration max)
max
- (undocumented)void expectNoMsg_internal(scala.concurrent.duration.FiniteDuration max)
<T> scala.collection.immutable.Seq<T> receiveWhile(scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration idle, int messages, scala.PartialFunction<java.lang.Object,T> f)
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)
max
- (undocumented)idle
- (undocumented)messages
- (undocumented)f
- (undocumented)scala.collection.immutable.Seq<java.lang.Object> receiveN(int n)
receiveN(n, remaining)
but correctly taking into account
Duration.timeFactor.n
- (undocumented)scala.collection.immutable.Seq<java.lang.Object> receiveN(int n, scala.concurrent.duration.FiniteDuration max)
n
- (undocumented)max
- (undocumented)scala.collection.immutable.Seq<java.lang.Object> receiveN_internal(int n, scala.concurrent.duration.Duration max)
java.lang.Object receiveOne(scala.concurrent.duration.Duration max)
This method does NOT automatically scale its Duration parameter!
max
- (undocumented)void shutdown(ActorSystem actorSystem, scala.concurrent.duration.Duration duration, boolean verifySystemShutdown)
If verifySystemShutdown is true, then an exception will be thrown on failure.
actorSystem
- (undocumented)duration
- (undocumented)verifySystemShutdown
- (undocumented)ActorRef childActorOf(Props props, java.lang.String name, SupervisorStrategy supervisorStrategy)
props
- Props to create the child actorname
- Actor name for the child actorsupervisorStrategy
- Strategy should decide what to do with failures in the actor.ActorRef childActorOf(Props props, SupervisorStrategy supervisorStrategy)
props
- Props to create the child actorsupervisorStrategy
- Strategy should decide what to do with failures in the actor.ActorRef childActorOf(Props props, java.lang.String name)
props
- Props to create the child actorname
- Actor name for the child actorActorRef childActorOf(Props props)
props
- Props to create the child actorjava.lang.String format(java.util.concurrent.TimeUnit u, scala.concurrent.duration.Duration d)