Akka Eventhandlerは永遠に回転します。どうすれば止めるべきですか?
-
25-10-2019 - |
質問
私はで問題を見つけたと思います EventHandler
. 。以下の仕様は永遠に実行されます。基本的に EventHandler.info()
これを引き起こします。電話してみました EventHandler.shutdown()
After Specを使用します。しかし、運がない。私は何かが足りないと思いますか?
Akka:1.3-RC1
class EventHandlerProblem extends Specification {
def is =
"This describes a possible problem with the EventHandler" ^
p ^
"The EventHandler should" ^
"not keep spinning forever...." ! e1
end
def e1 = {
// no need to start the actor
val ac = TestActorRef[PrintMessageActor]
true must beTrue
}
}
class PrintMessageActor extends Actor {
EventHandler.info(this, "Printer actor is starting up...")
def receive = {
case msg => {
println("Recieved: " + msg)
}
}
}
解決
Akkaの俳優テストでは、 registry.shutdownAll
すべてのフラグメントを実行した後。このようにして、テストがお互いに足を踏み入れることなく並行して実行できるように注意する必要がありますが、すべてのテストが実行された後、事態は清掃されます。これが特性です:
import org.specs2.Specification
import org.specs2.specification.{Step,Fragments}
import akka.actor.Actor.registry
trait AkkaSpec extends Specification {
override def map(fs: => Fragments) = fs ^ Step(registry.shutdownAll)
}
class EventHandlerProblem extends AkkaSpec {
def is =
"This describes a possible problem with the EventHandler" ^
p ^
"The EventHandler should" ^
"not keep spinning forever...." ! e1
end
def e1 = {
// no need to start the actor
val ac = TestActorRef[PrintMessageActor]
true must beTrue
}
}
class PrintMessageActor extends Actor {
EventHandler.info(this, "Printer actor is starting up...")
def receive = {
case msg => {
println("Recieved: " + msg)
}
}
}
他のヒント
一緒に試しました EventHandler.shutdown()
そして、それは(ハングアップせずに)適切に機能しました。これが出力です:
Testing started at 11:03 ...
[INFO] [29/11/11 11:03] [specs2.DefaultExecutionStrategy1] [PrintMessageActor] Printer actor is starting up...
[INFO] [29/11/11 11:03] [specs2.DefaultExecutionStrategy2] [PrintMessageActor] Printer actor is starting up...
Process finished with exit code 0
とコード:
import akka.testkit.TestActorRef
import org.specs2.Specification
import akka.event.EventHandler
class EventHandlerProblemSpec extends Specification {
def is =
"This describes a possible problem with the EventHandler" ^
p ^
"The EventHandler should" ^
"not keep spinning forever...." ! e1 ^
"not keep spinning forever 2...." ! e2 ^
end
def e1 = {
{
val ac = TestActorRef[PrintMessageActor]
true must beTrue
} after {
EventHandler.shutdown()
}
}
def e2 = {
try {
val ac = TestActorRef[PrintMessageActor]
true must beTrue
} finally {
EventHandler.shutdown()
}
}
}
所属していません StackOverflow