Package akka.persistence.testkit.javadsl
Class EventSourcedBehaviorTestKit<Command,Event,State>
- java.lang.Object
-
- akka.persistence.testkit.javadsl.EventSourcedBehaviorTestKit<Command,Event,State>
-
public final class EventSourcedBehaviorTestKit<Command,Event,State> extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EventSourcedBehaviorTestKit.CommandResult<Command,Event,State>
The result of running a command.static class
EventSourcedBehaviorTestKit.CommandResultWithReply<Command,Event,State,Reply>
The result of running a command with aActorRef
, i.e.replyTo static class
EventSourcedBehaviorTestKit.RestartResult<State>
The result of restarting the behavior.static class
EventSourcedBehaviorTestKit.SerializationSettings
Customization of which serialization checks that are performed.
-
Constructor Summary
Constructors Constructor Description EventSourcedBehaviorTestKit(EventSourcedBehaviorTestKit<Command,Event,State> delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the in-memory journal and snapshot storage and restarts the behavior.static com.typesafe.config.Config
config()
The configuration to be included in the configuration of theActorSystem
.static <Command,Event,State>
EventSourcedBehaviorTestKit<Command,Event,State>create(ActorSystem<?> system, Behavior<Command> behavior)
Factory method to create a new EventSourcedBehaviorTestKit.static <Command,Event,State>
EventSourcedBehaviorTestKit<Command,Event,State>create(ActorSystem<?> system, Behavior<Command> behavior, EventSourcedBehaviorTestKit.SerializationSettings serializationSettings)
Factory method to create a new EventSourcedBehaviorTestKit with customEventSourcedBehaviorTestKit.SerializationSettings
.static EventSourcedBehaviorTestKit.SerializationSettings
disabledSerializationSettings()
static EventSourcedBehaviorTestKit.SerializationSettings
enabledSerializationSettings()
State
getState()
Retrieve the current state of the Behavior.void
initialize(java.lang.Object... events)
void
initialize(scala.collection.immutable.Seq<Event> events)
void
initialize(State state, java.lang.Object... events)
Initializes behavior from provided state and/or events.void
initialize(State state, scala.collection.immutable.Seq<Event> events)
Initializes behavior from provided state and/or events.PersistenceTestKit
persistenceTestKit()
The underlyingPersistenceTestKit
for the in-memory journal.EventSourcedBehaviorTestKit.RestartResult<State>
restart()
Restart the behavior, which will then recover from stored snapshot and events.EventSourcedBehaviorTestKit.CommandResult<Command,Event,State>
runCommand(Command command)
Run one command through the behavior.<R> EventSourcedBehaviorTestKit.CommandResultWithReply<Command,Event,State,R>
runCommand(java.util.function.Function<ActorRef<R>,Command> creator)
Run one command with areplyTo: ActorRef
through the behavior.java.util.Optional<SnapshotTestKit>
snapshotTestKit()
The underlyingSnapshotTestKit
for snapshot storage.
-
-
-
Constructor Detail
-
EventSourcedBehaviorTestKit
public EventSourcedBehaviorTestKit(EventSourcedBehaviorTestKit<Command,Event,State> delegate)
-
-
Method Detail
-
config
public static com.typesafe.config.Config config()
The configuration to be included in the configuration of theActorSystem
. Typically used as constructor parameter toTestKitJunitResource
. The configuration enables the in-memory journal and snapshot storage.
-
enabledSerializationSettings
public static EventSourcedBehaviorTestKit.SerializationSettings enabledSerializationSettings()
-
disabledSerializationSettings
public static EventSourcedBehaviorTestKit.SerializationSettings disabledSerializationSettings()
-
create
public static <Command,Event,State> EventSourcedBehaviorTestKit<Command,Event,State> create(ActorSystem<?> system, Behavior<Command> behavior)
Factory method to create a new EventSourcedBehaviorTestKit.
-
create
public static <Command,Event,State> EventSourcedBehaviorTestKit<Command,Event,State> create(ActorSystem<?> system, Behavior<Command> behavior, EventSourcedBehaviorTestKit.SerializationSettings serializationSettings)
Factory method to create a new EventSourcedBehaviorTestKit with customEventSourcedBehaviorTestKit.SerializationSettings
.Note that
equals
must be implemented in the commands, events and state ifverifyEquality
is enabled.
-
initialize
public void initialize(State state, java.lang.Object... events)
Initializes behavior from provided state and/or events.
-
initialize
public void initialize(java.lang.Object... events)
-
runCommand
public EventSourcedBehaviorTestKit.CommandResult<Command,Event,State> runCommand(Command command)
Run one command through the behavior. The returned result contains emitted events and the state after applying the events.
-
runCommand
public <R> EventSourcedBehaviorTestKit.CommandResultWithReply<Command,Event,State,R> runCommand(java.util.function.Function<ActorRef<R>,Command> creator)
Run one command with areplyTo: ActorRef
through the behavior. The returned result contains emitted events, the state after applying the events, and the reply.
-
getState
public State getState()
Retrieve the current state of the Behavior.
-
restart
public EventSourcedBehaviorTestKit.RestartResult<State> restart()
Restart the behavior, which will then recover from stored snapshot and events. Can be used for testing that the recovery is correct.
-
clear
public void clear()
Clears the in-memory journal and snapshot storage and restarts the behavior.
-
initialize
public void initialize(State state, scala.collection.immutable.Seq<Event> events)
Initializes behavior from provided state and/or events.
-
initialize
public void initialize(scala.collection.immutable.Seq<Event> events)
-
persistenceTestKit
public PersistenceTestKit persistenceTestKit()
The underlyingPersistenceTestKit
for the in-memory journal. Can be useful for advanced testing scenarios, such as simulating failures or populating the journal with events that are used for replay.
-
snapshotTestKit
public java.util.Optional<SnapshotTestKit> snapshotTestKit()
The underlyingSnapshotTestKit
for snapshot storage. Present only if snapshots are enabled. Can be useful for advanced testing scenarios, such as simulating failures or populating the storage with snapshots that are used for replay.
-
-