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',並用它來驗證消息已發送和迴應更簡單給他們。不需要創建一個新的演員類,如果其他演員的行爲取決於狀態,則特別有用。 –