nick78
nick78

Reputation: 261

camel completionSize with completionTimeout not working correctly in JUnit

I have a file like this

line1
line2
line3
line4
line5
line6
line7
line8

And a route like that:

.from("direct:start")
.split().tokenize("\r\n").streaming()
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("Splitter:" +
            exchange.getIn().getBody(String.class));
    }
})
.aggregate(constant(true), new MyAggregationStrategy())
.completionSize(3).completionTimeout(10000)
.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        int size = exchange.getIn().getBody(Set.class).size();
        System.out.println("Processor, Set size:" + size);
    }
})
.to("mock:end")

MyAggregationStrategy creates a Set with 3 items. This works well for the first 6 lines, I get an output like this:

Splitter:line 1
Splitter:line 2
Splitter:line 3
...
Processor, Set size:3
...
Splitter:line 4
Splitter:line 5
Splitter:line 6
...
Processor, Set size:3
...
Splitter:line 7
Splitter:line 8

Although line 7 and line 8 are aggregated in the oldExchange in MyAggregationStrategy the Processor defined afterwards is never called for them. Also the completionTimeout is not working. The Code terminates immediately and does not wait for 10 seconds for the not existing line 9.

Any idea? I thought this is the recommended way dealing with remaining lines that don't satisfy the completionSize?

Since we are bound to Java 6 we use camel version 2.13.4.

Upvotes: 2

Views: 915

Answers (1)

nick78
nick78

Reputation: 261

Found the answer!

The problem occured in JUnit only cause finish.assertIsSatisfied() is executed immediately and does not wait for the timeout given in completionTimeout.

Using finish.assertIsSatisfied(long timeoutForEmptyEndpoints) with a value higher than given in completionTimeout solved my Problem

Upvotes: 2

Related Questions