Class TestKit
- java.lang.Object
- 
- org.apache.pekko.testkit.TestKit
 
- 
- All Implemented Interfaces:
- TestKitBase
 - Direct Known Subclasses:
- MultiNodeSpec,- TestProbe
 
 public class TestKit extends java.lang.Object implements TestKitBase 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 theexpectMsg...methods. Assertions and bounds concerning timing are available in the form ofwithinblocks.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.terminate() } }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 withinblocks); 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 pekko.conf entry "pekko.test.timefactor". 
- 
- 
Constructor SummaryConstructors Constructor Description TestKit(ActorSystem _system)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleanawaitCond(scala.Function0<java.lang.Object> p, scala.concurrent.duration.Duration max, scala.concurrent.duration.Duration interval, boolean noThrow)Await until the given condition evaluates totrueor the timeout expires, whichever comes first.static scala.concurrent.duration.DurationawaitCond$default$3()static booleanawaitCond$default$4()static scala.concurrent.duration.Durationnow()Obtain current timestamp as Duration for relative measurements (using System.nanoTime).static voidshutdownActorSystem(ActorSystem actorSystem, scala.concurrent.duration.Duration duration, boolean verifySystemShutdown)Shut down an actor system and wait for termination.static scala.concurrent.duration.DurationshutdownActorSystem$default$2()static booleanshutdownActorSystem$default$3()ActorSystemsystem()ActorReftestActor()ActorRef of the test actor.- 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface org.apache.pekko.testkit.TestKitBaseassertForDuration, assertForDuration$default$3, awaitAssert, awaitAssert$default$2, awaitAssert$default$3, awaitCond, awaitCond$default$2, awaitCond$default$3, awaitCond$default$4, checkMissingAndUnexpected, childActorOf, childActorOf, childActorOf, childActorOf, end_$eq, expectMsg, expectMsg, expectMsg, expectMsg_internal, expectMsg_internal$default$3, expectMsgAllClassOf, expectMsgAllClassOf, expectMsgAllConformingOf, expectMsgAllConformingOf, expectMsgAllOf, expectMsgAllOf, expectMsgAllOf_internal, expectMsgAnyClassOf, expectMsgAnyClassOf, expectMsgAnyClassOf_internal, expectMsgAnyOf, expectMsgAnyOf, expectMsgAnyOf_internal, expectMsgClass, expectMsgClass, expectMsgClass_internal, expectMsgPF, expectMsgPF$default$1, expectMsgPF$default$2, expectMsgType, expectMsgType, expectNoMessage, expectNoMessage, expectNoMsg, expectNoMsg, expectNoMsg_internal, expectTerminated, expectTerminated$default$2, fishForMessage, fishForMessage$default$1, fishForMessage$default$2, fishForSpecificMessage, fishForSpecificMessage$default$1, fishForSpecificMessage$default$2, format, ignoreMsg, ignoreNoMsg, internalExpectMsgAllClassOf, internalExpectMsgAllConformingOf, lastSender, lastWasNoMsg_$eq, msgAvailable, now, receiveN, receiveN, receiveN_internal, receiveOne, receiveWhile, receiveWhile$default$1, receiveWhile$default$2, receiveWhile$default$3, remaining, remainingOr, remainingOrDefault, remainingOrDilated, setAutoPilot, shutdown, shutdown$default$1, shutdown$default$2, shutdown$default$3, testActorName, testKitSettings, unwatch, watch, within, within
 
- 
 
- 
- 
- 
Constructor Detail- 
TestKitpublic TestKit(ActorSystem _system) 
 
- 
 - 
Method Detail- 
awaitCondpublic 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 totrueor the timeout expires, whichever comes first.
 - 
awaitCond$default$3public static scala.concurrent.duration.Duration awaitCond$default$3() 
 - 
awaitCond$default$4public static boolean awaitCond$default$4() 
 - 
nowpublic static scala.concurrent.duration.Duration now() Obtain current timestamp as Duration for relative measurements (using System.nanoTime).
 - 
shutdownActorSystempublic static void shutdownActorSystem(ActorSystem actorSystem, scala.concurrent.duration.Duration duration, boolean verifySystemShutdown) Shut down an actor system and wait for termination. On failure debug output will be logged about the remaining actors in the system.The durationis dilated by the timefactor.If verifySystemShutdown is true, then an exception will be thrown on failure. 
 - 
shutdownActorSystem$default$2public static scala.concurrent.duration.Duration shutdownActorSystem$default$2() 
 - 
shutdownActorSystem$default$3public static boolean shutdownActorSystem$default$3() 
 - 
testActorpublic ActorRef testActor() Description copied from interface:TestKitBaseActorRef of the test actor. Access is provided to enable e.g. registration as message target.- Specified by:
- testActorin interface- TestKitBase
 
 - 
systempublic ActorSystem system() - Specified by:
- systemin interface- TestKitBase
 
 
- 
 
-