英文:
Insert events to get desired state before running behaviour tests
问题
我正在尝试在执行某些命令之前插入事件。我希望将我的行为设置为特定测试的状态,而无需重新运行所有命令,就像常规测试中的数据库固件一样。
我正在使用:
akka.persistence.testkit.javadsl.EventSourcedBehaviorTestKit`
akka.actor.testkit.typed.javadsl.ActorTestKit`
akka.persistence.testkit.javadsl.PersistenceTestKit
我创建了我的测试工具:
static final ActorTestKit testKit = ActorTestKit.create(EventSourcedBehaviorTestKit.config());
static final EventSourcedBehaviorTestKit<Command, Event, State> eventSourcedTestKit = EventSourcedBehaviorTestKit.create(
testKit.system(),
MyPersistentBehaviour.create(),
EventSourcedBehaviorTestKit.disabledSerializationSettings()
);
然后我尝试执行:
eventSourcedTestKit.persistenceTestKit().persistForRecovery(
"1",
//我的Akka事件列表
);
eventSourcedTestKit.restart();
但是,一旦我尝试通过runCommand
运行这些已持久化的事件,它们并没有被应用。
这样做是一个好方法吗?
英文:
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?
答案1
得分: 0
问题是当我调用persistForRecovery
时,我将"1"
作为 persistenceId 传递,而这是错误的,persistenceId 是实体名称 + ID 的组合,所以它看起来应该像是 "order|1"
。
英文:
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"
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论