Search code examples
apache-camelintegration-testing

apache camel testing wait multicast to finish processing


apache camel test

I have my route FirstRoute which at the end multicast and send to SecondRoute.

i am writing my route test, i noticed multicast starts new thread if second_route takes longer to persist the data my integration test which starts first_route can't read the data b/c second_route is separate process first_route signals already finish processing. i am trying to find out a way where my first_route test will wait for second_route to finish processing before it runs my verifications.

following is my route code

from("First_route_id")
.process() // bla bla
.multicast()
.to("Second_route_id");

---
from("Second_route_id")
.proces() // save data
.end()

Solution

  • You can use Camel Notify Builder to build expressions like "when 1 message has completed in my route MySecondRoute".

    Example:

    NotifyBuilder notification = new NotifyBuilder(context)
        .from("direct:secondRoute").whenDone(1)
        .create();
    

    You can then wait for the defined condition to come true and additionally pass a timeout as parameter.

    boolean done = notification.matches(10, TimeUnit.SECONDS);
    

    As soon as the condition becomes true the test is notified and continues. So you can put your assertions below this point.

    If the condition does not become true, the test continues when the timeout is exhausted.

    See link to Camel Docs for more examples of NotifyBuilder.