mardi 2 juin 2015

akka Actor unit testing using testkit

There are many examples of using akka-testkit when the Actor being tested is responding to an ask:

//below code was copied from example link
val actorRef = TestActorRef(new MyActor)
// hypothetical message stimulating a '42' answer
val future = actorRef ? Say42
val Success(result: Int) = future.value.get
result must be(42)

But I have an Actor that does not respond to a sender; it instead sends a message to a separate actor. A simplified example being:

class PassThroughActor(sink : ActorRef) {
  def receive : Receive = {
    case _ => sink ! 42
  }
}

TestKit has a suite of expectMsg methods but I cannot find any examples of creating a test sink Actor that could expect a message within a unit test.

Is it possible to test my PassThroughActor?

Thank you in advance for your consideration and response.

Aucun commentaire:

Enregistrer un commentaire