Explorer
Explorer

Reputation: 1647

Akka Test TCP command failed

I am trying to write my first Akka test and going through the documentation. I was running the very first example of it and getting following error:

[ERROR] [10/26/2017 14:08:55.371] [IngestionWorkerActorSpec-akka.actor.default-dispatcher-4] [akka://IngestionWorkerActorSpec/user/$b] Assertion failed: timeout (3 seconds) during expectMsg while waiting for Test message java.lang.AssertionError: assertion failed: timeout (3 seconds) during expectMsg while waiting for Test message

Below is the receive method of my test actor:

override def receive: Receive = {
case p: ProducerRecord[_,_] =>
      sendChannel.send(p.value())
case _ => logger.error("Unknown type Producer Record Received.")
}

Testspec:

val uutActor =system.actorOf(IngestionWorkerActor.props(config, KafkaProducer))
"An actor must send " should  {
"send back messages unchanged" in {
  uutActor ! expected
  Thread.sleep(50)
  expectMsg(expected)
}
}

I wanted to test whether my actor is receiving the messages sent to it or not and later I wanted to modify it to see whether I am getting specific message or not. Any help is appreciated.

Upvotes: 0

Views: 104

Answers (1)

johanandren
johanandren

Reputation: 11479

expectMsg(something) means that the actor would reply with something to sender() (which was captured by an implicit parameter to ! when you sent the message), it does not introspect the messages the actor receives.

Best practice would be to avoid trying to write tests that look into the internal of actors but instead verify that they behave as they should when messages are sent. In this case that could maybe be to put a mock sendChannel in there and verify that the right value was sent on it.

Upvotes: 1

Related Questions