Akka持久性测试方法 [英] Akka persistence testing approaches

查看:116
本文介绍了Akka持久性测试方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉此处定义的Akka测试方法:

I am familiar with the Akka testing approaches defined here:

http://doc.akka.io/docs/akka/snapshot/scala/testing.html

我了解如何使用TestKit,TestActorRef,TestProbe等。我也了解我的核心领域逻辑应与Akka隔离地进行提取和测试。

I understand how to use TestKit, TestActorRef, TestProbe etc. I also understand that my core domain logic should be extracted and tested in isolation from Akka.

我的问题是关于在Akka Persistence角色(即PersistentActor和PersistentView)上进行TDD的策略。

My question is about strategies for doing TDD on Akka Persistence actors i.e. PersistentActor and PersistentView.

我希望能够以合理的低开销,高效的方式测试以下类型的场景,即尽可能接近单元测试:

I want to be able to test the following types of scenarios in a reasonably low overhead, efficient manner i.e. as close to a unit test as possible:


  1. 持久性参与者是否以正确的ID坚持了一个事件?

  2. 我的快照恢复还原状态是​​否正确?

  3. 我的视图是否读取了正确的事件?

如果有人知道一个可以帮助我看到实际行动的项目,我将不胜感激。

If anyone knows of a project which can help me see this in action, I would be grateful.

我可以的一种方法想到的是有一个测试PersistentView,该测试可用于验证PersitentActor的工作。

One approach I can think of is to have a test PersistentView which can be used to verify a PersitentActor did its job. Seems a bit convoluted though.

这并不是要测试Akka持久性框架本身,而是要测试我的Actor是否已正确设置为可以使用它,并且行为是否符合预期。

This is not about testing Akka persistence framework itself, but to test that my Actors have been setup properly to use it and the behaviour is as expected.

推荐答案

Ad.1 的可重用解决方案是使用某种内存日志事件总线发布功能。这样,您可以创建一个测试探针,以监听事件总线上已发布的事件并对其进行断言。

Ad.1 Reusable solution for that would be some kind of in-memory journal with event bus publishing feature. This way you could create a test probe to listen on event bus for published events and assert them.

Ad.2 Ad .3 关于如果我的演员在还原后正确响应,我有理由相信它处于正确状态。这样,您不仅可以验证它的内部字段是否设置正确,还可以验证它的接收方法是否由于成为的更改而被正确还原。

Ad.2 and Ad.3 are more about if my actor responds correctly after restore, I have a reason to believe that it's in correct state. This way you can not only validate if it's internal fields are correctly set, but also if it receive method has been restored correctly due to become changes.

(可选)要明确检查状态,可以使用某些消息类型将参与者的状态返回给发件人。通过在接收方法上使用特征和重写,可以使其通用。

Optionally to check state distinctly have some message type that returns actor's state back to sender. It can be made generic by using traits and overrides on receive methods.

这篇关于Akka持久性测试方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆