我有以下场景:父主管actor使用构造函数中传递的工厂(函数)为每条消息创建一个子节点。
class supervisorActor(childActorMaker: ActorRefFactory => ActorRef)
extends Actor with ActorLogging{
def receive: Receive = {
case "testThis" =>
val childActor = childActorMaker(context)
childActor!"messageForChild"
}
override val supervisorStrategy =
OneForOneStrategy() {
case _ => Stop
}
}
class childActor extends Actor {
def receive:Receive = {
case _ => /** whatever **/
}
}
在测试中,我覆盖了子 Receive 以强制异常。我的期望是因为我设定的监督策略,每次都会阻止儿童演员。
"When the child Actor throws an exception the Supervisor Actor " should " " +
" stop it" in {
val childActorRef = TestActorRef(new childActor() {
override def receive = {
case msg: String => throw new IllegalArgumentException("kaboom")
}
})
watch(childActorRef)
val maker = (_: ActorRefFactory) => childActorRef
val supervisorActorRef = system.actorOf(Props(new supervisorActor(maker)))
supervisorActorRef!"testThis"
expectTerminated(childActorRef, 1.second)
}
我希望由于 supervisorStrategy Stop 而停止子演员。相反,我收到此错误:
java.lang.AssertionError: assertion failed: timeout (1 second) during expectMsg: Terminated
知道为什么会这样吗?谢谢