gpt4 book ai didi

scala - 创建 TestActorRef 导致 NullPointerException

转载 作者:行者123 更新时间:2023-11-28 20:00:11 25 4
gpt4 key购买 nike

我正在尝试获得这样的 TestActorRef

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

这个 Actor

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

def receive = {
[...]
}
}

但这给我留下了以下堆栈跟踪

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

编辑:这似乎与这个 Actor 特别有关。获取另一个 actor 类的 TestActorRef 工作正常。我读到,对于具有 Stash 特征的 actor,TextActorRefs 存在问题,但据说在当前版本中已解决。 ( Reference )

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

最佳答案

已验证升级到 akka 2.3.0是使用 Stash 特性修复 TestActorRef 的正确答案。

关于scala - 创建 TestActorRef 导致 NullPointerException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21725473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com