Testing 如何在单元测试中杀死并重新启动akka持久参与者,以查看它是否保留状态

Testing 如何在单元测试中杀死并重新启动akka持久参与者,以查看它是否保留状态,testing,akka-persistence,Testing,Akka Persistence,在我的单元测试中,是否有一种方法可以杀死并重新启动一个持久参与者,以检查它是否能够正确地保留状态(例如,事件序列化/反序列化工作正常) 以下是一些关于如何阻止参与者的有用信息。注意:对于持久参与者,不建议使用毒药消息来阻止参与者。建议的方式是显式关闭,例如:系统。停止(动作) // Initialize the actor and a probe for the actor val probe = TestProbe() val act = system.actorOf(Props[MyAc

在我的单元测试中,是否有一种方法可以杀死并重新启动一个持久参与者,以检查它是否能够正确地保留状态(例如,事件序列化/反序列化工作正常)


以下是一些关于如何阻止参与者的有用信息。

注意:对于持久参与者,不建议使用毒药消息来阻止参与者。建议的方式是显式关闭,例如:
系统。停止(动作)

// 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