在我的單元測試中,有沒有一種方法可以殺死然後重新啓動一個持久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:如何重置表單狀態並在提交後保留值