use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTimeoutExpressionRestart.
public void testAggregateProcessorTimeoutExpressionRestart() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "timeout");
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);
// start with a high timeout so no completes before we stop
ap.setCompletionTimeoutExpression(header("myTimeout"));
ap.start();
Exchange e1 = new DefaultExchange(context);
e1.getIn().setBody("A");
e1.getIn().setHeader("id", 123);
e1.getIn().setHeader("myTimeout", 2000);
Exchange e2 = new DefaultExchange(context);
e2.getIn().setBody("B");
e2.getIn().setHeader("id", 123);
e2.getIn().setHeader("myTimeout", 2000);
ap.process(e1);
ap.process(e2);
// shutdown before the 2 sec timeout occurs
// however we use stop instead of shutdown as shutdown will clear the in memory aggregation repository,
ap.stop();
// should be no completed
assertEquals(0, mock.getReceivedCounter());
// start aggregator again
ap.start();
// the aggregator should restore the timeout condition and trigger timeout
assertMockEndpointsSatisfied();
assertEquals(1, mock.getReceivedCounter());
ap.shutdown();
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTimeoutRestart.
public void testAggregateProcessorTimeoutRestart() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "timeout");
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);
// start with a high timeout so no completes before we stop
ap.setCompletionTimeout(2000);
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);
ap.process(e1);
ap.process(e2);
// shutdown before the 2 sec timeout occurs
// however we use stop instead of shutdown as shutdown will clear the in memory aggregation repository,
ap.stop();
// should be no completed
assertEquals(0, mock.getReceivedCounter());
// start aggregator again
ap.start();
// the aggregator should restore the timeout condition and trigger timeout
assertMockEndpointsSatisfied();
assertEquals(1, mock.getReceivedCounter());
ap.shutdown();
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateShutdownThreadPoolTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
myPool = context.getExecutorServiceManager().newDefaultThreadPool(this, "myPool");
from("direct:foo").routeId("foo").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(3).to("mock:aggregated");
from("direct:bar").routeId("bar").aggregate(header("id"), new BodyInAggregatingStrategy()).executorService(myPool).completionSize(3).to("mock:aggregated");
}
};
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateThreadPoolProfileTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// create and register thread pool profile
ThreadPoolProfile profile = new ThreadPoolProfile("myProfile");
profile.setPoolSize(2);
profile.setMaxPoolSize(8);
profile.setRejectedPolicy(ThreadPoolRejectedPolicy.Abort);
context.getExecutorServiceManager().registerThreadPoolProfile(profile);
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(3).executorServiceRef("myProfile").to("log:foo").to("mock:aggregated");
}
};
}
use of org.apache.camel.processor.BodyInAggregatingStrategy in project camel by apache.
the class AggregateIgnoreInvalidCorrelationKeysTest method testAggregateNotIgnoreInvalidCorrelationKeys.
public void testAggregateNotIgnoreInvalidCorrelationKeys() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").aggregate(header("id"), new BodyInAggregatingStrategy()).completionSize(2).to("mock:result");
}
});
context.start();
getMockEndpoint("mock:result").expectedBodiesReceived("A+C");
template.sendBodyAndHeader("direct:start", "A", "id", 1);
try {
template.sendBodyAndHeader("direct:start", "B", "id", null);
fail("Should throw an exception");
} catch (CamelExecutionException e) {
CamelExchangeException cause = assertIsInstanceOf(CamelExchangeException.class, e.getCause());
assertTrue(cause.getMessage().startsWith("Invalid correlation key"));
}
template.sendBodyAndHeader("direct:start", "C", "id", 1);
assertMockEndpointsSatisfied();
}
Aggregations