我想知道测试演员是否已经停止在akka的规范方式是什么.这是我目前正在做的一个例子; 我担心我会让它变得复杂.
import akka.actor.{Terminated, Actor, Props, ActorSystem} import akka.testkit.TestProbe class MyActor extends Actor { import MyActor._ override def receive: Receive = { case Stop => context.stop(self) } } object MyActor { def props = Props(new MyActor) case object Stop } object MyActorSpec { val system = ActorSystem() val myActor = system.actorOf(MyActor.props) val testProbe = TestProbe() case object MyActorStopped val watcher = system.actorOf(Props(new Actor { context.watch(myActor) override def receive: Actor.Receive = { case Terminated(`myActor`) => testProbe.ref ! MyActorStopped } })) myActor ! MyActor.Stop testProbe.expectMsg(MyActorStopped) }
Shadowlands.. 25
你可以摆脱单独的观察者演员,直接从testProbe
演员那里观看目标演员:
val testProbe = TestProbe() testProbe watch myActor myActor ! MyActor.Stop testProbe.expectTerminated(myActor)
请参阅此处了解Akka测试文档的相关部分.
你可以摆脱单独的观察者演员,直接从testProbe
演员那里观看目标演员:
val testProbe = TestProbe() testProbe watch myActor myActor ! MyActor.Stop testProbe.expectTerminated(myActor)
请参阅此处了解Akka测试文档的相关部分.