Search code examples
junitapache-camelcitrus-framework

Citrus fails to find reply channel when receiving & sending messages in parallel


I'm using the Citrus framework to test Camel routes. I'm sending a request to the Camel-based application which in turn sends multiple requests in parallel to a SOAP server. I'm trying to mock the SOAP server with Citrus using the parallel container. I use selectors to trigger the correct receive and send actions similar to the following example (the real code is a bit more complicated):

parallel().actions(
    sequential().actions(
        soap().server("soapService")
            .receive()
            .selector("xpath:local-name(/*)='exampleRequest1' AND xpath://ns1:id/text()='123'")
            .payload(new ClassPathResource("data/123/exampleRequest1.xml")),
        echo("Received exampleRequest1"),
        soap().server("soapService")
            .send()
            .payload(new ClassPathResource("data/123/exampleResponse1.xml")),
        echo("Sent exampleResponse1"),
    ),
    sequential().actions(
        soap().server("soapService")
            .receive()
            .selector("xpath:local-name(/*)='exampleRequest2' AND xpath://ns1:id/text()='456'")
            .payload(new ClassPathResource("data/456/exampleRequest2.xml")),
        echo("Received exampleRequest2"),
        soap().server("soapService")
            .send()
            .payload(new ClassPathResource("data/456/exampleResponse2.xml")),
        echo("Sent exampleResponse2"),
    ),
    ...
)

Citrus does indeed receive the messages but it cannot reply. The error message of each parallel thread is:

13:35:36.121 [Thread-22] ERROR com.consol.citrus.container.Parallel - Parallel test action raised error
java.lang.IllegalArgumentException: Failed to find reply channel for message correlation key: citrus_message_id = 'c37eb703-4fb3-4c34-98f8-9cf8ee0414a1'
    at org.springframework.util.Assert.notNull(Assert.java:198)
    at com.consol.citrus.channel.ChannelSyncConsumer.send(ChannelSyncConsumer.java:73)
    at com.consol.citrus.actions.SendMessageAction.doExecute(SendMessageAction.java:125)
    …

Important: The citrus_message_id that each thread is looking for is always the same but should be different. So if one of the send actions actually succeeds, it's usually sending with the wrong reply channel.

What could be the problem here? Is this a bug or am I missing something? Thank you very much!


Solution

  • The parallel container causes the problems here. But you can safely remove the parallel container when using selectors in receive actions. It should work fine for you once you have removed the parallels