1
我有以下單元測試:回覆發送者進入死信框
it should "return xml" in new TestScope {
val testProbe: TestProbe = TestProbe()
val someActor = system.actorOf(Props[SomeActor])
testProbe.send(someActor, MakeXmlApiCall())
testProbe.expectMsgPF() {
case Success(message) => {
assert(message == "someMessage")
}
}
}
爲了與本receive
方法演員:
override def receive: Receive = {
case MakeXmlApiCall() => {
val status = Future {"someMessage"}
println("In SomeActor")
status onComplete {
case Success(message) => {
sender ! message
}
}
}
}
「在SomeActor」被打印,其意味着控制達到了receive
方法。
不過,我也收到此消息:
[INFO] [12/15/2016 18:42:29.463] [testSystem-akka.actor.default-dispatcher-3] [akka://testSystem/deadLetters] Message [java.lang.String] from Actor[akka://testSystem/user/$a#-1159394947] to Actor[akka://testSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
那麼爲什麼發送到dead-letter
而非testProbe
從單元測試的消息。
這是怎麼發生的?
如果一個Akka actor將所有消息保存在FIFO隊列中,發送者如何改變? – octavian
因爲在調用'status.onComplete'之後,接收函數返回並且參與者處理下一條消息。期貨是異步的,它們不會阻止調用線程。 – Ryan
'status.pipeTo(sender())'爲我工作..真棒..朋友..文檔在這裏http://doc.akka.io/docs/akka/current/scala/futures.html#use-with -actors –