I am trying to insert events before I try to execute some commands. I want to get my behaviour in a state ready for particular test, without needing to rerun all the commands, like database fixtures in regular testing.
I am using:
akka.persistence.testkit.javadsl.EventSourcedBehaviorTestKit`
akka.actor.testkit.typed.javadsl.ActorTestKit`
akka.persistence.testkit.javadsl.PersistenceTestKit
I create my test kits:
static final ActorTestKit testKit = ActorTestKit.create(EventSourcedBehaviorTestKit.config());
static final EventSourcedBehaviorTestKit<Command, Event, State> eventSourcedTestKit = EventSourcedBehaviorTestKit.create(
testKit.system(),
MyPersistentBehaviour.create(),
EventSourcedBehaviorTestKit.disabledSerializationSettings()
);
and then I try to do:
eventSourcedTestKit.persistenceTestKit().persistForRecovery(
"1",
//List of my akka events
);
eventSourcedTestKit.restart();
but as soon as I try to runCommand
those events I persisted aren't applied.
Is this even a good way to do it?
The issue was that I passed "1"
as persistenceId when I invoked persistForRecovery
and that is wrong, persistenceId is a composite of entity name + id, so it would look like "order|1"
.