插入事件以在运行行为测试之前获得所需状态

huangapple go评论53阅读模式
英文:

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&lt;Command, Event, State&gt; eventSourcedTestKit = EventSourcedBehaviorTestKit.create(
    testKit.system(),
    MyPersistentBehaviour.create(),
    EventSourcedBehaviorTestKit.disabledSerializationSettings()
);

and then I try to do:

eventSourcedTestKit.persistenceTestKit().persistForRecovery(
    &quot;1&quot;,
    //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时,我将&quot;1&quot; 作为 persistenceId 传递,而这是错误的,persistenceId 是实体名称 + ID 的组合,所以它看起来应该像是 &quot;order|1&quot;

英文:

The issue was that I passed &quot;1&quot; as persistenceId when I invoked persistForRecovery and that is wrong, persistenceId is a composite of entity name + id, so it would look like &quot;order|1&quot;.

huangapple
  • 本文由 发表于 2020年8月19日 22:30:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/63489257.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定