0
我想用AkkaTestKit测试我的演员逻辑。问题是我的演员使用ask
模式。所以我需要以某种方式回答。它看起来像这样:回答AkkaTestKit
case class AskExecution(id: Long)
override def receive: Receive = {
case id : Long =>
implicit val dispatcher = context.dispatcher
implicit val timeout = Timeout(10 seconds)
val executor = sender
//How to answer this?
val f = executor ? AskExecution(id) map(v => v.asInstanceOf[Option[Long]])
f.onComplete{
case Success(k) =>
case Failure(_) =>
}
}
在测试中,我使用它,如下所示:
val ca = TestActorRef(new TheActor())
ca ! 0L //I send 0, Now I want to answer the ask
//How to do so?
它注入了'TestProbe',并用它来验证消息已发送和回应更简单给他们。不需要创建一个新的演员类,如果其他演员的行为取决于状态,则特别有用。 –