1
votes

I started on a new akka project and having an issue with akka-camel integration testing..

So I have a consumer actor and am trying to test if it is receiving the message I send

Here is the test

@Test
public void testConsumer() {

    final String testXml = "<user>" +
            "<firstName>First</firstName>" +
            "<lastName>Last</lastName>" +
            "</user>";

    new JavaTestKit(_system) {{

        final JavaTestKit probe = new JavaTestKit(_system);

        final ActorRef subject2 = _system.actorOf(Consumer.mkProps(probe.getRef(), endPoint, "testConsumerActor"));
        camel.template().sendBody(endPoint, testXml);

    }};
}

The test fails with the following exception

15:15:02.442 [Camel (test-cdr) thread #0 - seda://testRecords] WARN     o.a.c.component.seda.SedaConsumer - Error processing exchange. Exchange[Message: <user><firstName>First</firstName><lastName>Last</lastName></user>]. Caused by:    [akka.camel.ActorNotRegisteredException - Actor [akka://test-cdr/user/$a] doesn't exist]

akka.camel.ActorNotRegisteredException: Actor [akka://test-cdr/user/$a] doesn't exist at akka.camel.internal.component.ActorProducer$$anonfun$actorFor$1.apply(ActorComponent.scala:182) ~[akka-camel_2.10-2.2.3.jar:na] at akka.camel.internal.component.ActorProducer$$anonfun$actorFor$1.apply(ActorComponent.scala:182) ~[akka-camel_2.10-2.2.3.jar:na] at scala.Option.getOrElse(Option.scala:120) ~[scala-library-2.10.3.jar:na] at akka.camel.internal.component.ActorProducer.actorFor(ActorComponent.scala:182) ~[akka-camel_2.10-2.2.3.jar:na]

When I debug through my test, I notice that before the constructor for my consumer is called, camel is sending the message. How do I prevent this? or am I missing anything?

SD

1

1 Answers

1
votes

I had issue with Akka-Camel which seemed to be problem with Camel initialization. I had to wait for Camel to initialize before I could send messages.

It's descibed in Akka Camel - JMS messages lost - should wait for initialization of Camel?

Java version for Camel initialization was:

ActorRef producer = system.actorOf(new Props(SimpleProducer.class), "simpleproducer"); 
Timeout timeout = new Timeout(Duration.create(15, SECONDS)); 

Future<ActorRef> activationFuture = camel.activationFutureFor(producer,timeout,  system.dispatcher());

activationFuture.onComplete(new OnComplete<ActorRef>() {
        @Override
        public void onComplete(Throwable arg0, ActorRef arg1)
                throws Throwable {

            producer.tell("First!!");
        }
        },system.dispatcher()); 

Are you performing any sort of Camel initialization in your test? If not, adding something like this may help.