Akka Eventhandler вращается навсегда. Как мне это остановить?
-
25-10-2019 - |
Вопрос
Я думаю, что нашел проблему с EventHandler
. Анкет Спецификация ниже будет работать навсегда. В основном EventHandler.info()
вызовет это. Я пытался позвонить EventHandler.shutdown()
Использование после спецификации. Но без удачи. Как ты думаешь, я что -то упускаю?
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)
}
}
}
Решение
В моих тестах на актер Акка у меня есть специальная черта, которая называет 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