在我的单元测试中,有没有一种方法可以杀死然后重新启动一个持久actor以检查它是否可以正确保留状态(并且,例如,事件序列化/反序列化工作正常)?如何在单元测试中杀死并重启akka persistent actor以查看它是否保留状态
1
A
回答
3
// Initialize the actor and a probe for the actor
val probe = TestProbe()
val act = system.actorOf(Props[MyActor], "name")
// send messages to the actor to change state
// Validate that the state has changed
// Send a message to terminate the actor
act ! PoisonPill
// wait for the actor to shutdown
probe.watch(act)
probe.expectTerminated(act)
// Initialize a new probe and a new instance of the actor, with the assumption
// that the actor has the same persistence id as the initial one.
// That actor should now be in the same state as before.
val probeTwo = TestProbe()
val rehydrated = system.actorOf(Props[MyActor], "name")
// Validate the state of the actor.
// Todo: Put your validation checks here
以下是关于test actors的一些有用信息。
0
注意:对于持续演员而言,PoisonPill消息不是推荐的方式来阻止演员。推荐的方法是明确关闭例如:system.stop(act)
http://doc.akka.io/docs/akka/current/scala/persistence.html#Safely_shutting_down_persistent_actors
相关问题
- 1. 如何测试Akka Persistence actor
- 2. 如何在X时间后杀死Akka actor?
- 3. 如何在恢复提交并保留单元测试时检查测试?
- 4. 如何测试DIV以查看它是否存在
- 5. 如何杀死应用程序线程并重新启动它?
- 6. 如何测试你的应用程序被杀死并重新启动?
- 7. 使用DeathWatch杀死Akka actor时发送的消息
- 8. 如何成功杀死一个java进程并在unix中重启它?
- 9. 如何单元测试会话状态
- 10. 如何在单元测试时重置状态机C
- 11. 检测会话挂起并杀死它
- 12. 杀死查看并返回rootViewController
- 13. 如何设置测试状态中测试单元成功
- 14. 启动子流程并在完成时保存以杀死
- 15. 重构静态类,所以我可以单元测试它
- 16. 如何杀死配置单元启动的mapred作业?
- 17. Pixastic IE测试杀死IE9
- 18. 如何测试是否在单元测试中出现异常
- 19. x单元测试死锁
- 20. 如何将akka sharded actor状态外部化为redis或ignite?
- 21. 是否可以在不杀死会话的情况下杀死oracle中的单个查询?
- 22. 是否可以测试正则表达式以查看它是否减少为:*
- 23. Akka的单元测试私有方法
- 24. 测试单元测试是否存在保存方法
- 25. 如何保证AlarmManager生存手机重启和应用杀死
- 26. 在IDE中“逐行”调试specefic akka actor?
- 27. 测试Numpy数组以查看它是否为列形式
- 28. 杀死nodejs进程而不重启
- 29. 在jquery菜单中保留状态
- 30. Angular Reactive forms:如何重置表单状态并在提交后保留值