Class ActorTestKit
shutdown is called.
The actor system has a custom guardian that allows for spawning arbitrary actors using the spawn methods.
Designed to work with any test framework, but framework glue code that calls shutdownTestKit after all tests has
run needs to be provided by the user or with TestKitJunitResource.
Use TestKit.create factories to construct manually or TestKitJunitResource to use together with JUnit tests
For synchronous testing of a Behavior see BehaviorTestKit
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.typesafe.config.ConfigConfig loaded fromapplication-test.conf, which is used if no specific config is given.static ActorTestKitcreate()Create a testkit named from the ActorTestKit class.static ActorTestKitcreate(com.typesafe.config.Config customConfig) Create a testkit named from the ActorTestKit class, and use a custom config for the actor system.static ActorTestKitCreate a testkit using the provided name.static ActorTestKitCreate a test kit named based on the provided name, and uses the provided custom config for the actor system.static ActorTestKitcreate(String name, com.typesafe.config.Config customConfig, TestKitSettings settings) Create anpekko.actor.typed.ActorSystemnamed based on the provided name, use the provided custom config for the actor system, and the testkit will use the provided setting.static ActorTestKitcreate(ActorSystem<?> system) Create a testkit from the provided actor system.<M> TestProbe<M>Shortcut for creating a new test probe for the testkit actor system<M> TestProbe<M>createTestProbe(Class<M> clazz) Shortcut for creating a new test probe for the testkit actor system<M> TestProbe<M>createTestProbe(String name) Shortcut for creating a new named test probe for the testkit actor system<M> TestProbe<M>createTestProbe(String name, Class<M> clazz) Shortcut for creating a new named test probe for the testkit actor systemThe scheduler of the testkit actor systemAdditional testing utilities for serialization.static voidshutdown(ActorSystem<?> system) Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thansystem-shutdown-defaultpasses an exception is thrown (can be configured withthrow-on-shutdown-timeout).static voidshutdown(ActorSystem<?> system, Duration duration) Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thansystem-shutdown-defaultpasses an exception is thrown (can be configured withthrow-on-shutdown-timeout).static voidshutdown(ActorSystem<?> system, Duration duration, boolean throwIfShutdownTimesOut) Shutdown the given actor system and wait up todurationfor shutdown to complete.voidTerminate the actor system and the testkit<T> ActorRef<T>Spawn a new auto-named actor under the testkit user guardian and return the ActorRef for the spawned actor<T> ActorRef<T>Spawn a new named actor under the testkit user guardian and return the ActorRef for the spawned actor, note that spawning actors with the same name in multiple test cases will cause failures.<T> ActorRef<T>Spawn a new named actor under the testkit user guardian with the given props and return the ActorRef for the spawned actor, note that spawning actors with the same name in multiple test cases will cause failures.<T> ActorRef<T>Spawn a new auto-named actor under the testkit user guardian with the given props and return the ActorRef for the spawned actor<T> voidStop the actor under test and wait until it terminates.<T> voidStop the actor under test and waitmaxuntil it terminates.system()The actor system running for this testkit.timeout()The default timeout as specified with the config/pekko.actor.testkit.typed.TestKitSettings
-
Method Details
-
create
Create a testkit named from the ActorTestKit class.When the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit().Config loaded from
application-test.confif that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries. The application.conf of your project is not used in this case. -
create
Create a testkit from the provided actor system.When the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit().Config loaded from the provided actor if that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries.
-
create
Create a testkit using the provided name.It will create an
pekko.actor.typed.ActorSystemwith this name, e.g. threads will include the name. When the test has completed you should terminate theActorSystemand the testkit withshutdownTestKit().Config loaded from
application-test.confif that exists, otherwise using default configuration from the reference.conf resources that ship with the Akka libraries. The application.conf of your project is not used in this case. -
create
Create a testkit named from the ActorTestKit class, and use a custom config for the actor system.It will also used the provided customConfig provided to create the
ActorSystemWhen the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit(). -
create
Create a test kit named based on the provided name, and uses the provided custom config for the actor system.It will create an
pekko.actor.typed.ActorSystemwith this name, e.g. threads will include the name.It will also used the provided customConfig provided to create the
ActorSystemWhen the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit(). -
create
public static ActorTestKit create(String name, com.typesafe.config.Config customConfig, TestKitSettings settings) Create anpekko.actor.typed.ActorSystemnamed based on the provided name, use the provided custom config for the actor system, and the testkit will use the provided setting.It will create an
pekko.actor.typed.ActorSystemwith this name, e.g. threads will include the name.It will also used the provided customConfig provided to create the
ActorSystem, and provided setting.When the test has completed you should terminate the
ActorSystemand the testkit withshutdownTestKit(). -
shutdown
public static void shutdown(ActorSystem<?> system, Duration duration, boolean throwIfShutdownTimesOut) Shutdown the given actor system and wait up todurationfor shutdown to complete.- Parameters:
throwIfShutdownTimesOut- Fail the test if the system fails to shut down, if false an error is printed to stdout when the system did not shutdown but no exception is thrown.
-
shutdown
Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thansystem-shutdown-defaultpasses an exception is thrown (can be configured withthrow-on-shutdown-timeout). -
shutdown
Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thansystem-shutdown-defaultpasses an exception is thrown (can be configured withthrow-on-shutdown-timeout). -
applicationTestConfig
public static com.typesafe.config.Config applicationTestConfig()Config loaded fromapplication-test.conf, which is used if no specific config is given. -
timeout
The default timeout as specified with the config/pekko.actor.testkit.typed.TestKitSettings -
system
The actor system running for this testkit. Interaction with the user guardian is done through methods on the testkit which is why it is typed toVoid. -
testKitSettings
-
scheduler
The scheduler of the testkit actor system -
spawn
Spawn a new auto-named actor under the testkit user guardian and return the ActorRef for the spawned actor -
spawn
Spawn a new named actor under the testkit user guardian and return the ActorRef for the spawned actor, note that spawning actors with the same name in multiple test cases will cause failures. -
spawn
Spawn a new auto-named actor under the testkit user guardian with the given props and return the ActorRef for the spawned actor -
spawn
Spawn a new named actor under the testkit user guardian with the given props and return the ActorRef for the spawned actor, note that spawning actors with the same name in multiple test cases will cause failures. -
stop
Stop the actor under test and wait until it terminates. It can only be used for actors that were spawned by thisActorTestKit. Other actors will not be stopped by this method. -
stop
Stop the actor under test and waitmaxuntil it terminates. It can only be used for actors that were spawned by thisActorTestKit. Other actors will not be stopped by this method. -
createTestProbe
Shortcut for creating a new test probe for the testkit actor system -
createTestProbe
Shortcut for creating a new test probe for the testkit actor system -
createTestProbe
Shortcut for creating a new named test probe for the testkit actor system -
createTestProbe
Shortcut for creating a new named test probe for the testkit actor system -
createDroppedMessageProbe
- Returns:
- A test probe that is subscribed to dropped letters from the system event bus. Subscription will be completed and verified so any dropped letter after it will be caught by the probe.
-
createDeadLetterProbe
- Returns:
- A test probe that is subscribed to dead letters from the system event bus. Subscription will be completed and verified so any dead letter after it will be caught by the probe.
-
createUnhandledMessageProbe
- Returns:
- A test probe that is subscribed to unhandled messages from the system event bus. Subscription will be completed and verified so any unhandled message after it will be caught by the probe.
-
shutdownTestKit
public void shutdownTestKit()Terminate the actor system and the testkit -
serializationTestKit
Additional testing utilities for serialization.
-