Search code examples
scalaplayframeworkakkaactorakka-testkit

Play - Akka: Actors testing


I've read about TestKit, TestActorRef and ImplicitSender provided by Akka. But I didn't found a way to check if a certain actor has received a certain message. I think that "expectMsg(Foo)" can be useful if the receiver-actor does "sender ! Foo". But my application is different: I have an actor A that sends a message to another actor B. Than B sends a message to a Java client through WebSocket. When B receives a reply, this is forwarded to actor C. How to check that C receives that message (possibly within a certain timeout)? Thanks.


Solution

  • Without code it's hard to give a concrete answer, but you can create a TestProbe to stand in for actor C.

    val actorCProbe = TestProbe()
    
    val actorB = system.actorOf(Props(classOf[ActorB], actorCProbe.ref))
    

    Then you can use all the standard test kit expects on the test probe:

    actorB ! testMsg
    
    actorCProbe.expectMsg(500 millis, "result")