Class EventSourcedBehaviorTestKit<Command,Event,State>
- java.lang.Object
-
- org.apache.pekko.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 classEventSourcedBehaviorTestKit.CommandResult<Command,Event,State>The result of running a command.static classEventSourcedBehaviorTestKit.CommandResultWithReply<Command,Event,State,Reply>The result of running a command with aActorRef, i.e.replyTo static classEventSourcedBehaviorTestKit.RestartResult<State>The result of restarting the behavior.static classEventSourcedBehaviorTestKit.SerializationSettingsCustomization 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 voidclear()Clears the in-memory journal and snapshot storage and restarts the behavior.static com.typesafe.config.Configconfig()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.SerializationSettingsdisabledSerializationSettings()static EventSourcedBehaviorTestKit.SerializationSettingsenabledSerializationSettings()StategetState()Retrieve the current state of the Behavior.voidinitialize(java.lang.Object... events)voidinitialize(scala.collection.immutable.Seq<Event> events)voidinitialize(State state, java.lang.Object... events)Initializes behavior from provided state and/or events.voidinitialize(State state, scala.collection.immutable.Seq<Event> events)Initializes behavior from provided state and/or events.PersistenceTestKitpersistenceTestKit()The underlyingPersistenceTestKitfor 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: ActorRefthrough the behavior.java.util.Optional<SnapshotTestKit>snapshotTestKit()The underlyingSnapshotTestKitfor 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
equalsmust be implemented in the commands, events and state ifverifyEqualityis 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: ActorRefthrough 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 underlyingPersistenceTestKitfor 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 underlyingSnapshotTestKitfor 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.
-
-