Scala 仅允许使用已调整的非类型ActorRefs

Scala 仅允许使用已调整的非类型ActorRefs,scala,akka,akka-typed,Scala,Akka,Akka Typed,我试图用以下方法测试我的演员: class DetectorSpec extends BddSpec { private val sap = new SapMock() .withExposedPorts(8080) .waitingFor(Wait.forHttp("/")) private val kafka = new KafkaContainer("5.2.1") sap.start() kafka.start() override de

我试图用以下方法测试我的演员:

class DetectorSpec extends BddSpec {


  private val sap = new SapMock()
    .withExposedPorts(8080)
    .waitingFor(Wait.forHttp("/"))

  private val kafka = new KafkaContainer("5.2.1")


  sap.start()
  kafka.start()


  override def afterAll(): Unit = {
    sap.stop()
    kafka.stop()
  }

  private def withKafkaAndSapOnline(testCode: TestInbox[ServerEvent] => Future[Assertion])
  : Future[Assertion] = {

    val config = ConfigFactory.parseString(
      s"""
         kafka {
           servers = "${kafka.getBootstrapServers}"
         }
         sap {
           server = "ws://${sap.getContainerIpAddress}:${sap.getMappedPort(8080)}"
         }""")

    val system = ActorSystem(DetectorSupervisor.create(), "testSystem1", config)
    val inbox = TestInbox[ServerEvent]()
    system.receptionist ! Receptionist.Register(ServerStateKey, inbox.ref)

    complete {
      testCode(inbox)
    } lastly {
      system.terminate()
    }

  }


  feature("Detect Kafka and SAP availability") {
    info("As a technical user, I want to be notified in real time, if Kafka and SAP is up and running or not.")
    scenario("SAP and Kafka are available") {
      withKafkaAndSapOnline { inbox =>
        Given("I am waiting for the current state message")
        When("I am receive the state message")
        Then("it should contain `SAP and Kafka are online`")
        Future {
          inbox.receiveMessage() should be(ServerOnlineApproved)
        }
      }
    }
  }
}
启动测试时,我收到以下错误消息:

[ERROR] [06/30/2019 22:15:07.643] [testSystem3-akka.actor.default-dispatcher-3] [akka://testSystem3/system/receptionist] only adapted untyped ActorRefs permissible (Actor[akka.actor.typed.inbox://anonymous/inbox#-233829306] of class akka.actor.testkit.typed.internal.FunctionRef)
akka.actor.ActorInitializationException: akka://testSystem3/system/receptionist/$a: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:202)
    at akka.actor.ActorCell.create(ActorCell.scala:696)
    at akka.actor.ActorCell.invokeAll$1(ActorCell.scala:547)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:569)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:293)
    at akka.dispatch.Mailbox.run(Mailbox.scala:228)
    at akka.dispatch.Mailbox.exec(Mailbox.scala:241)
    at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.UnsupportedOperationException: only adapted untyped ActorRefs permissible (Actor[akka.actor.typed.inbox://anonymous/inbox#-233829306] of class akka.actor.testkit.typed.internal.FunctionRef)
    at akka.actor.typed.internal.adapter.ActorRefAdapter$.toUntyped(ActorRefAdapter.scala:55)
    at akka.actor.typed.internal.adapter.ActorContextAdapter.watch(ActorContextAdapter.scala:99)
    at akka.actor.typed.internal.receptionist.LocalReceptionist$.$anonfun$behavior$2(LocalReceptionist.scala:64)
    at akka.actor.typed.Behavior$DeferredBehavior$$anon$1.apply(Behavior.scala:264)
    at akka.actor.typed.Behavior$.start(Behavior.scala:331)
    at akka.actor.typed.internal.adapter.ActorAdapter.preStart(ActorAdapter.scala:238)
    at akka.actor.Actor.aroundPreStart(Actor.scala:550)
    at akka.actor.Actor.aroundPreStart$(Actor.scala:550)
    at akka.actor.typed.internal.adapter.ActorAdapter.aroundPreStart(ActorAdapter.scala:51)
    at akka.actor.ActorCell.create(ActorCell.scala:676)
    ... 9 more
问题是肯定的:

system.receptionist ! Receptionist.Register(ServerStateKey, inbox.ref)

但是我做错了什么?

收件箱不是真正的参与者(它是使用
函数ref
实现的),不能向接待员注册。在测试中使用
TestProbe[T]
。这是有效的,因为它们有一个真正的参与者作为后盾。

收件箱不是真正的参与者(它是使用
FunctionRef
实现的),不能向接待员注册。在测试中使用
TestProbe[T]
。这是可行的,因为这些都有真正的参与者支持。

在文档中哪里可以找到
TestProbe[T]
?在下面一点:在文档中哪里可以找到
TestProbe[T]
?在下面一点: