Class ActorTestKit
- java.lang.Object
-
- org.apache.pekko.actor.testkit.typed.scaladsl.ActorTestKit
-
public final class ActorTestKit extends java.lang.ObjectTestkit for asynchronous testing of typed actors, meant for mixing into the test class.Provides a typed actor system started on creation, used for all test cases and shut down when
shutdownis called.The actor system has a custom guardian that allows for spawning arbitrary actors using the
spawnmethods.Designed to work with any test framework, but framework glue code that calls shutdown after all tests has run needs to be provided by the user.
For synchronous testing of a
BehaviorseeBehaviorTestKit
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static com.typesafe.config.ConfigApplicationTestConfig()Config loaded fromapplication-test.conf, which is used if no specific config is given.static ActorTestKitapply()Create a testkit named from the ActorTestKit class.static ActorTestKitapply(com.typesafe.config.Config customConfig)Create a testkit named from the ActorTestKit class, and use a custom config for the actor system.static ActorTestKitapply(java.lang.String name)Create a testkit using the provided name.static ActorTestKitapply(java.lang.String name, com.typesafe.config.Config customConfig)Create a test kit named based on the provided name, and uses the provided custom config for the actor system.static ActorTestKitapply(java.lang.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 ActorTestKitapply(ActorSystem<?> system)Create a testkit from the provided actor system.com.typesafe.config.Configconfig()TestProbe<DeadLetter>createDeadLetterProbe()TestProbe<Dropped>createDroppedMessageProbe()<M> TestProbe<M>createTestProbe()Shortcut for creating a new test probe for the testkit actor system<M> TestProbe<M>createTestProbe(java.lang.String name)Shortcut for creating a new named test probe for the testkit actor systemTestProbe<UnhandledMessage>createUnhandledMessageProbe()ActorSystem<?>internalSystem()java.lang.Stringname()Schedulerscheduler()SerializationTestKitserializationTestKit()Additional testing utilities for serialization.static voidshutdown(ActorSystem<?> system)Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thanTestKitSettings.DefaultActorSystemShutdownTimeoutpasses an exception is thrownstatic voidshutdown(ActorSystem<?> system, scala.concurrent.duration.Duration timeout, boolean throwIfShutdownFails)Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down or thedurationhits.static booleanshutdown$default$3()voidshutdownTestKit()<T> ActorRef<T>spawn(Behavior<T> behavior)Spawn the given behavior.<T> ActorRef<T>spawn(Behavior<T> behavior, java.lang.String name)Spawn the given behavior.<T> ActorRef<T>spawn(Behavior<T> behavior, java.lang.String name, Props props)Spawn the given behavior.<T> ActorRef<T>spawn(Behavior<T> behavior, Props props)Spawn the given behavior.<T> voidstop(ActorRef<T> ref, scala.concurrent.duration.FiniteDuration max)Stop the actor under test and wait until it terminates.<T> scala.concurrent.duration.FiniteDurationstop$default$2()ActorSystem<scala.runtime.Nothing$>system()INTERNAL APITestKitSettingstestKitSettings()Timeouttimeout()
-
-
-
Method Detail
-
apply
public static ActorTestKit apply()
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.
-
apply
public static ActorTestKit apply(ActorSystem<?> system)
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.
-
apply
public static ActorTestKit apply(java.lang.String name)
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.
-
apply
public static ActorTestKit apply(com.typesafe.config.Config customConfig)
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().
-
apply
public static ActorTestKit apply(java.lang.String name, com.typesafe.config.Config customConfig)
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().
-
apply
public static ActorTestKit apply(java.lang.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)
Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down, if more time thanTestKitSettings.DefaultActorSystemShutdownTimeoutpasses an exception is thrown
-
shutdown
public static void shutdown(ActorSystem<?> system, scala.concurrent.duration.Duration timeout, boolean throwIfShutdownFails)
Shutdown the givenpekko.actor.typed.ActorSystemand block until it shuts down or thedurationhits. If the timeout hitsverifySystemShutdowndecides
-
shutdown$default$3
public static boolean shutdown$default$3()
-
ApplicationTestConfig
public static com.typesafe.config.Config ApplicationTestConfig()
Config loaded fromapplication-test.conf, which is used if no specific config is given.
-
internalSystem
public ActorSystem<?> internalSystem()
-
name
public java.lang.String name()
-
config
public com.typesafe.config.Config config()
-
testKitSettings
public TestKitSettings testKitSettings()
-
system
public ActorSystem<scala.runtime.Nothing$> system()
INTERNAL API
-
timeout
public Timeout timeout()
-
scheduler
public Scheduler scheduler()
-
shutdownTestKit
public void shutdownTestKit()
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior)
Spawn the given behavior. This is created as a child of the test kit guardian
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior, Props props)
Spawn the given behavior. This is created as a child of the test kit guardian
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior, java.lang.String name)
Spawn the given behavior. This is created as a child of the test kit guardian
-
spawn
public <T> ActorRef<T> spawn(Behavior<T> behavior, java.lang.String name, Props props)
Spawn the given behavior. This is created as a child of the test kit guardian
-
stop
public <T> void stop(ActorRef<T> ref, scala.concurrent.duration.FiniteDuration max)
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$default$2
public <T> scala.concurrent.duration.FiniteDuration stop$default$2()
-
createTestProbe
public <M> TestProbe<M> createTestProbe()
Shortcut for creating a new test probe for the testkit actor system
-
createTestProbe
public <M> TestProbe<M> createTestProbe(java.lang.String name)
Shortcut for creating a new named test probe for the testkit actor system
-
createUnhandledMessageProbe
public TestProbe<UnhandledMessage> 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.
-
createDeadLetterProbe
public TestProbe<DeadLetter> 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.
-
createDroppedMessageProbe
public TestProbe<Dropped> 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.
-
serializationTestKit
public SerializationTestKit serializationTestKit()
Additional testing utilities for serialization.
-
-