use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateProcessorTest method testAggregateCompletionInterval.
public void testAggregateCompletionInterval() throws Exception {
// camel context must be started
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B+C", "D");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "interval");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
ap.setCompletionInterval(3000);
ap.start();
Exchange e1 = new DefaultExchange(context);
e1.getIn().setBody("A");
e1.getIn().setHeader("id", 123);
Exchange e2 = new DefaultExchange(context);
e2.getIn().setBody("B");
e2.getIn().setHeader("id", 123);
Exchange e3 = new DefaultExchange(context);
e3.getIn().setBody("C");
e3.getIn().setHeader("id", 123);
Exchange e4 = new DefaultExchange(context);
e4.getIn().setBody("D");
e4.getIn().setHeader("id", 123);
ap.process(e1);
ap.process(e2);
ap.process(e3);
Thread.sleep(5000);
ap.process(e4);
assertMockEndpointsSatisfied();
ap.stop();
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateEagerCheckCompletionTest method testAggregateEagerCheckCompletion.
public void testAggregateEagerCheckCompletion() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionPredicate(body().isEqualTo("END")).eagerCheckCompletion().to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedBodiesReceived("A+B+END");
template.sendBodyAndHeader("direct:start", "A", "id", 1);
template.sendBodyAndHeader("direct:start", "B", "id", 1);
template.sendBodyAndHeader("direct:start", "END", "id", 1);
assertMockEndpointsSatisfied();
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateForceCompletionOnStopParallelTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:forceCompletionTrue").routeId("foo").aggregate(header("id"), new BodyInAggregatingStrategy()).forceCompletionOnStop().completionSize(10).parallelProcessing().delay(100).process("myCompletionProcessor");
from("direct:forceCompletionFalse").routeId("bar").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(10).parallelProcessing().delay(100).process("myCompletionProcessor");
}
};
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateForceCompletionOnStopTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:forceCompletionTrue").routeId("foo").aggregate(header("id"), new BodyInAggregatingStrategy()).forceCompletionOnStop().completionSize(10).delay(100).process("myCompletionProcessor");
from("direct:forceCompletionFalse").routeId("bar").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(10).delay(100).process("myCompletionProcessor");
}
};
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateClosedCorrelationKeyTest method testAggregateClosedCorrelationKey.
public void testAggregateClosedCorrelationKey() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).closeCorrelationKeyOnCompletion(1000).to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedBodiesReceived("A+B");
template.sendBodyAndHeader("direct:start", "A", "id", 1);
template.sendBodyAndHeader("direct:start", "B", "id", 1);
// should be closed
try {
template.sendBodyAndHeader("direct:start", "C", "id", 1);
fail("Should throw an exception");
} catch (CamelExecutionException e) {
ClosedCorrelationKeyException cause = assertIsInstanceOf(ClosedCorrelationKeyException.class, e.getCause());
assertEquals("1", cause.getCorrelationKey());
assertTrue(cause.getMessage().startsWith("The correlation key [1] has been closed."));
}
assertMockEndpointsSatisfied();
}
Aggregations