私はいくつか散発的なテストの失敗があり、その理由を理解するのに苦労しています。私はテストしたい仕事に俳優の束を持っています。テストの開始時に、私はTestProbe()から取得したアクター参照を渡します。後でアクターのグループでいくつかの作業を行い、与えられたテストプローブアクター参照に結果を送信します。次に、TestProbe()を使用して結果を確認します。TestProbe()へのメッセージの送信は、時にはActorInitializationExceptionで失敗します。
class MyCaseSpec extends Spec with ShouldMatchers{
describe("The Thingy"){
it("should work"){
val eventListener = TestProbe()
val myStuffUnderTest = Actor.actorOf(new ComplexActor(eventListener.ref)).start();
myStuffUnderTest ! "Start"
val eventMessage = eventListener.receiveOne(10.seconds).asInstanceOf[SomeEventMessage]
eventMessage.data should be ("Result")
}
}
}
今度は、テストが失敗します。スタックトレースを調べると、テストプローブのアクタにメッセージを送信するときに「ActorInitializationException」が発生することがわかります。しかし、私はTestProbeアクタを停止します。
はここで例外です:
[akka:event-driven:dispatcher:global-11] [LocalActorRef] Actor has not been started, you need to invoke 'actor.start()' before using it
akka.actor.ActorInitializationException: Actor has not been started, you need to invoke 'actor.start()' before using it
[Gamlor-Laptop_c15fdca0-219e-11e1-9579-001b7744104e]
at akka.actor.ScalaActorRef$class.$bang(ActorRef.scala:1399)
at akka.actor.LocalActorRef.$bang(ActorRef.scala:605)
at akka.mobile.client.RemoteMessaging$RemoteMessagingSupervision$$anonfun$receive$1.apply(RemoteMessaging.scala:125)
at akka.mobile.client.RemoteMessaging$RemoteMessagingSupervision$$anonfun$receive$1.apply(RemoteMessaging.scala:121)
at akka.actor.Actor$class.apply(Actor.scala:545)
....
私は何かを明らかに欠けているか、私は微妙な間違いを犯していた場合、私は思ったんだけど?または、コード内で実際に何かが間違っていて、それを見ることができないのでしょうか?
私はAkka 1.2です。
Vitors-Commentの更新。 125行目では、!-operatorを使って俳優にメッセージを送ります。 Test-setupでは、TestProbeアクターリファレンスが使用されます。そして、なぜTestProbeアクタが停止したように見えるのか理解できません。
protected def receive = {
case msg: MaximumNumberOfRestartsWithinTimeRangeReached => {
val lastException = msg.getLastExceptionCausingRestart
faultHandling ! ConnectionError(lastException, messages.toList, self) // < Line 125. The faultHandling is the TestProbe actor
become({
// Change to failure-state behavior
}
// Snip
とにかく、私はしばらくの間問題をさらに分離しようとしています。ヒント/アイデアをありがとう。
あなたが最も興味深い部分を含めていないのはなぜ? (RemoteMessaging.scala:125) –
125で、私はTestProbe()アクターにメッセージを送ります:私がテストプローブ俳優は時々実行されていないと私は例外を取得します。 – Gamlor