public class TestKit extends java.lang.Object implements TestKitBase
expectMsg...
methods. Assertions and bounds concerning
timing are available in the form of within
blocks.
class Test extends TestKit(ActorSystem()) {
try {
val test = system.actorOf(Props[SomeActor])
within (1.second) {
test ! SomeWork
expectMsg(Result1) // bounded to 1 second
expectMsg(Result2) // bounded to the remainder of the 1 second
}
} finally {
system.terminate()
}
} finally {
system.shutdown()
}
}
Beware of two points:
- the ActorSystem passed into the constructor needs to be shutdown,
otherwise thread pools and memory will be leaked
- this class is not thread-safe (only one actor with one queue, one stack
of within
blocks); it is expected that the code is executed from a
constructor as shown above, which makes this a non-issue, otherwise take
care not to run tests within a single test class instance in parallel.
It should be noted that for CI servers and the like all maximum Durations are scaled using their Duration.dilated method, which uses the TestKitExtension.Settings.TestTimeFactor settable via akka.conf entry "akka.test.timefactor".
Constructor and Description |
---|
TestKit(akka.actor.ActorSystem _system) |
Modifier and Type | Method and Description |
---|---|
static boolean |
awaitCond(scala.Function0<java.lang.Object> p,
scala.concurrent.duration.Duration max,
scala.concurrent.duration.Duration interval,
boolean noThrow)
Await until the given condition evaluates to
true or the timeout
expires, whichever comes first. |
static scala.concurrent.duration.Duration |
now()
Obtain current timestamp as Duration for relative measurements (using System.nanoTime).
|
static void |
shutdownActorSystem(akka.actor.ActorSystem actorSystem,
scala.concurrent.duration.Duration duration,
boolean verifySystemShutdown)
Shut down an actor system and wait for termination.
|
akka.actor.ActorSystem |
system() |
static java.util.concurrent.atomic.AtomicInteger |
testActorId() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
awaitAssert, awaitCond, checkMissingAndUnexpected, end, expectMsg_internal, expectMsg, expectMsg, expectMsg, expectMsgAllClassOf, expectMsgAllClassOf, expectMsgAllConformingOf, expectMsgAllConformingOf, expectMsgAllOf_internal, expectMsgAllOf, expectMsgAllOf, expectMsgAnyClassOf_internal, expectMsgAnyClassOf, expectMsgAnyClassOf, expectMsgAnyOf_internal, expectMsgAnyOf, expectMsgAnyOf, expectMsgClass_internal, expectMsgClass, expectMsgClass, expectMsgPF, expectMsgType, expectMsgType, expectNoMsg_internal, expectNoMsg, expectNoMsg, expectTerminated, fishForMessage, format, ignoreMsg, ignoreNoMsg, internalExpectMsgAllClassOf, internalExpectMsgAllConformingOf, lastMessage, lastSender, lastWasNoMsg, msgAvailable, now, queue, receiveN_internal, receiveN, receiveN, receiveOne, receiveWhile, remaining, remainingOr, remainingOrDefault, remainingOrDilated, setAutoPilot, shutdown, testActor, testActorName, testKitSettings, unwatch, watch, within, within
public static java.util.concurrent.atomic.AtomicInteger testActorId()
public static boolean awaitCond(scala.Function0<java.lang.Object> p, scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration interval, boolean noThrow)
true
or the timeout
expires, whichever comes first.p
- (undocumented)max
- (undocumented)interval
- (undocumented)noThrow
- (undocumented)public static scala.concurrent.duration.Duration now()
public static void shutdownActorSystem(akka.actor.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)public akka.actor.ActorSystem system()
system
in interface TestKitBase