Class ActorTestKit
- java.lang.Object
-
- akka.actor.testkit.typed.scaladsl.ActorTestKit
-
public final class ActorTestKit extends java.lang.Object
Testkit 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
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 shutdown after all tests has run needs to be provided by the user.
For synchronous testing of a
Behavior
seeBehaviorTestKit
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static com.typesafe.config.Config
ApplicationTestConfig()
Config loaded fromapplication-test.conf
, which is used if no specific config is given.static ActorTestKit
apply()
Create a testkit named from the ActorTestKit class.static ActorTestKit
apply(ActorSystem<?> system)
Create a testkit from the provided actor system.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.static ActorTestKit
apply(java.lang.String name)
Create a testkit using the provided name.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.static ActorTestKit
apply(java.lang.String name, com.typesafe.config.Config customConfig, TestKitSettings settings)
Create anActorSystem
named based on the provided name, use the provided custom config for the actor system, and the testkit will use the provided setting.com.typesafe.config.Config
config()
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.String
name()
Scheduler
scheduler()
SerializationTestKit
serializationTestKit()
Additional testing utilities for serialization.static void
shutdown(ActorSystem<?> system)
Shutdown the givenActorSystem
and block until it shuts down, if more time thanTestKitSettings.DefaultActorSystemShutdownTimeout
passes an exception is thrownstatic void
shutdown(ActorSystem<?> system, scala.concurrent.duration.Duration timeout, boolean throwIfShutdownFails)
Shutdown the givenActorSystem
and block until it shuts down or theduration
hits.static boolean
shutdown$default$3()
void
shutdownTestKit()
<T> ActorRef<T>
spawn(Behavior<T> behavior)
Spawn the given behavior.<T> ActorRef<T>
spawn(Behavior<T> behavior, Props props)
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> void
stop(ActorRef<T> ref, scala.concurrent.duration.FiniteDuration max)
Stop the actor under test and wait until it terminates.<T> scala.concurrent.duration.FiniteDuration
stop$default$2()
ActorSystem<scala.runtime.Nothing$>
system()
INTERNAL APITestKitSettings
testKitSettings()
Timeout
timeout()
-
-
-
Method Detail
-
apply
public static ActorTestKit apply()
Create a testkit named from the ActorTestKit class.When the test has completed you should terminate the
ActorSystem
and the testkit withshutdownTestKit()
.Config loaded from
application-test.conf
if 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
ActorSystem
and 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
ActorSystem
with this name, e.g. threads will include the name. When the test has completed you should terminate theActorSystem
and the testkit withshutdownTestKit()
.Config loaded from
application-test.conf
if 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
ActorSystem
When the test has completed you should terminate the
ActorSystem
and 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
ActorSystem
with this name, e.g. threads will include the name.It will also used the provided customConfig provided to create the
ActorSystem
When the test has completed you should terminate the
ActorSystem
and the testkit withshutdownTestKit()
.
-
apply
public static ActorTestKit apply(java.lang.String name, com.typesafe.config.Config customConfig, TestKitSettings settings)
Create anActorSystem
named 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
ActorSystem
with 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
ActorSystem
and the testkit withshutdownTestKit()
.
-
shutdown
public static void shutdown(ActorSystem<?> system)
Shutdown the givenActorSystem
and block until it shuts down, if more time thanTestKitSettings.DefaultActorSystemShutdownTimeout
passes an exception is thrown
-
shutdown
public static void shutdown(ActorSystem<?> system, scala.concurrent.duration.Duration timeout, boolean throwIfShutdownFails)
Shutdown the givenActorSystem
and block until it shuts down or theduration
hits. If the timeout hitsverifySystemShutdown
decides
-
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.
-
-