Akka EventHandler永远旋转.我该如何阻止它



我想我发现了EventHandler的问题。下面的规范将永远运行。基本上EventHandler.info()会导致这个。我试着用After规范呼叫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)
    }
  }
}

在我的Akka Actor测试中,我有一个特殊的特性,在运行所有片段后调用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()
    }
  }
}

相关内容

  • 没有找到相关文章

最新更新