1

我在 Scala/Akka 有一个小测试

"test test" in {

  val actor = TestActorRef(new Actor {
    override def receive: Receive = {
      case _ =>
        println("Inside actor " + context.parent)
        context.parent ! 42
    }
  })

  println("Self " + self)

  actor ! "Hello"

  expectMsg(42)
}

它产生的输出是

Self Actor[akka://testSystem/system/testActor1#-1014751973]
Inside actor Actor[akka://testSystem/user]
(...)
assertion failed: timeout (3 seconds) during expectMsg while waiting for 42
java.lang.AssertionError: assertion failed: timeout (3 seconds) during expectMsg while waiting for 42

为什么演员内部不是我们在日志中看到context.parent的真正的父母?testActor1(这是我希望在创建主题时成为父母的演员)。

如果这种物质状态是预期的——如果是这样,为什么?我认为这种方法没有任何好处。

4

1 回答 1

2

There are two possibilities for what this can be. If you call one of the apply methods on the TestActorRef companion that does not accept an explicit supervisor ActorRef then the parent will be the root guardian. If you do call the one that takes an explicit supervisor then the parent will be that ActorRef that you supply.

于 2015-04-22T15:20:21.230 回答