创建TestActorRef会导致NullPointerException [英] Creating a TestActorRef results in NullPointerException

查看:102
本文介绍了创建TestActorRef会导致NullPointerException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获得这样的TestActorRef

I am trying to get a TestActorRef like that

class NotifySenderTest(_system: ActorSystem) extends TestKit(_system) with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll with BeforeAndAfter {

  def this() = this(ActorSystem("NotifySenderTest"))
  override def afterAll {
    TestKit.shutdownActorSystem(system)
  }

  "A NotifySender" must {
    "be able to process the required messages" in {
      val actorRef = TestActorRef[NotifySender] //Line 92
    }
  }

此演员

class NotifySender extends Actor with Stash {
  import Tcp._
  import context.system

  def receive = {
  [...]
  }
}

但是我有以下堆栈跟踪


java.lang.NullPointerException:at
akka.actor.dungeon.Dispatch $ class.init( Disbatch.scala:62)位于
akka.actor.ActorCell.init(ActorCell.scala:338)位于
akka.actor.LocalActorRef。(ActorRef.scala:304)位于
akka。在
akka.testkit.TestActorRef。(TestActorRef.scala:21)在
akka.testkit.TestActorRef $ .apply(TestActorRef.scala:141)在
akka.testkit.TestActorRef $ .apply(TestActorRef.scala:137) )在
akka.testkit.TestActorRef $ .apply(TestActorRef.scala:146)在
akka.testkit.TestActorRef $ .apply(TestActorRef.scala:144)在
actor.NotifySenderTest $ $ anonfun $ 2 $$ anonfun $ apply $ mcV $ sp $ 4.apply $ mcV $ sp(NotifySenderTest.scala:92)
at
actor.NotifySenderTest $$ anonfun $ 2 $$ anonfun $ apply $ mcV $ sp $ 4.apply(NotifySenderTest.scala:91)
...

java.lang.NullPointerException: at akka.actor.dungeon.Dispatch$class.init(Dispatch.scala:62) at akka.actor.ActorCell.init(ActorCell.scala:338) at akka.actor.LocalActorRef.(ActorRef.scala:304) at akka.testkit.TestActorRef.(TestActorRef.scala:21) at akka.testkit.TestActorRef$.apply(TestActorRef.scala:141) at akka.testkit.TestActorRef$.apply(TestActorRef.scala:137) at akka.testkit.TestActorRef$.apply(TestActorRef.scala:146) at akka.testkit.TestActorRef$.apply(TestActorRef.scala:144) at actor.NotifySenderTest$$anonfun$2$$anonfun$apply$mcV$sp$4.apply$mcV$sp(NotifySenderTest.scala:92) at actor.NotifySenderTest$$anonfun$2$$anonfun$apply$mcV$sp$4.apply(NotifySenderTest.scala:91) ...

编辑:似乎有些事情要做特别是这个演员。将TestActorRef获取到另一个actor类可以正常工作。我读到具有Stash特性的Actor的TextActorRefs存在问题,但是据说在当前版本中已解决。 (参考

It seems to have something to do with this actor in particular. Getting a TestActorRef to another actor class is working correctly. I read that there was a problem with TextActorRefs for actors that have the Stash trait, but this was said to be resolved in the current version. (Reference)

Edit2:好的。我错了。当前版本不是2.3。所以我必须等待?!

Ok. I was wrong. The current release is not 2.3. So I have to wait?!

推荐答案

已验证升级到 akka 2.3.0 是使用 TestActorRef 的正确答案>隐藏特征。

Verified that upgrading to akka 2.3.0 is the correct answer for fixing TestActorRef with the Stash trait.

这篇关于创建TestActorRef会导致NullPointerException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆