Scala 阿克卡永远在旋转。我该怎么阻止它?

Scala 阿克卡永远在旋转。我该怎么阻止它?,scala,event-handling,akka,Scala,Event Handling,Akka,我想我发现了EventHandler的问题。下面的规范将永远运行。 基本上,EventHandler.info()会导致这种情况。我尝试使用After规范调用EventHandler.shutdown(),但是运气不好。你认为我遗漏了什么吗 阿克卡:1.3-RC1 类EventHandlerProblem扩展了规范{ def是= “这描述了EventHandler可能存在的问题”^ p^ “事件处理程序应该”^ “不要永远旋转”!e1 结束 def e1={ //不需要启动演员 val ac=T

我想我发现了
EventHandler
的问题。下面的规范将永远运行。 基本上,
EventHandler.info()
会导致这种情况。我尝试使用After规范调用
EventHandler.shutdown()
,但是运气不好。你认为我遗漏了什么吗

阿克卡:1.3-RC1

类EventHandlerProblem扩展了规范{
def是=
“这描述了EventHandler可能存在的问题”^
p^
“事件处理程序应该”^
“不要永远旋转”!e1
结束
def e1={
//不需要启动演员
val ac=TestActorRef[PrintMessageActor]
真的一定是真的
}
}
类PrintMessageActor扩展了Actor{
info(此“打印机参与者正在启动…”)
def接收={
case msg=>{
println(“收到:+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()
    }
  }
}

在我的Akka Actor测试中,我有一个特殊的特性,在运行所有片段后调用
注册表.shutdownlall
。这样,虽然您仍然需要注意,您的测试可以并行运行,而不会相互影响,但在所有测试运行之后,事情会得到清理。这是一个特点:

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)
    }
  }
}

酷,我用了这个解决方案。但是我添加了一个对Actor.remote.shutdown()的额外调用,否则它将无法工作(至少我正在处理的项目需要它)。注意:请注意,您不会在SBT上注意到这一点。只有在使用IDE运行时,才能看到它。当然,您始终可以执行线程转储。。。