camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvahdat <babak.vah...@swissonline.ch>
Subject Is this pollEnrich()'s expected behaviour?
Date Thu, 23 Jun 2011 11:06:51 GMT
Hi,

while riding on camel 2.7.2 the following test case works for me:

import org.apache.camel.EndpointInject;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;

public class PollEnrichTest extends CamelTestSupport {

    @EndpointInject(uri = "mock:foo")
    private MockEndpoint mock;

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {

            @Override
            public void configure() {
               
from("direct:start").pollEnrich("file:target?fileName=foo.txt&noop=true",
2000).to(mock);
            }

        };
    }

    @Test
    public void shouldConsumeTheFileContent() throws Exception {
        assertFileExists("target/foo.txt");

        mock.expectedBodiesReceived("file content of target/foo.txt");
        
        template.sendBody("direct:start", "test");
        
        mock.assertIsSatisfied();
    }

}


However if I remove the 2 seconds timeout parameter & run the test again,
the message received by the mock endpoint is not the file's content anymore
but the "test" string sent to the direct endpoint:

java.lang.AssertionError: mock://foo Body of message: 0. Expected: <file
content of target/foo.txt> but was: <test>
	at
org.apache.camel.component.mock.MockEndpoint.fail(MockEndpoint.java:1086)
	at
org.apache.camel.component.mock.MockEndpoint.assertEquals(MockEndpoint.java:1068)
	at
org.apache.camel.component.mock.MockEndpoint$4.run(MockEndpoint.java:532)
	at
org.apache.camel.component.mock.MockEndpoint.doAssertIsSatisfied(MockEndpoint.java:378)
	at
org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:346)
	at
org.apache.camel.component.mock.MockEndpoint.assertIsSatisfied(MockEndpoint.java:334)
....

In the case the timeout isn't given explicitly, it will default to 0, that's
receiveNoWait. But the file is still there (noop=true). On the other hand
the documentation[1] says:

/"By default Camel will use the reply from the external service as outgoing
message."/

So that in the absence of an explicit AggregationStrategy, it should always
pick the response of the "external service".

Still another point: If I change the route defintion to

from("direct:start").pollEnrich("file:target?fileName=bar.txt&noop=true",
2000).to(mock);

where bar.txt doesn't exist, again the "test" message is sent to the mock
endpoint (exactly the same stacktrace as above). To my understanding I would
expect 0 exchanges to be sent to the mock, as the file "bar.txt" is missing.

Any idea?

Regards, Babak

[1] http://camel.apache.org/content-enricher.html


--
View this message in context: http://camel.465427.n5.nabble.com/Is-this-pollEnrich-s-expected-behaviour-tp4517089p4517089.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message