Only adapted untyped ActorRefs permissible

Hi all

I am trying to test my actors with Actor discovery as follows:

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

When I start test, I’ve got the following error message:

[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

The problem is for sure:

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

But what am I doing wrong?

Thanks

Hi, the problem is the Inbox from the synchronous testkit. Try to use the TestProbe from the asynchronous ActorTestKit instead. You find more info in the testing section in the docs.

1 Like