use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class AggregateProcessorTest method testAggregateForceCompletion.
public void testAggregateForceCompletion() throws Exception {
// camel context must be started
context.start();
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceivedInAnyOrder("B+END", "A+END");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "force");
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.setCompletionSize(10);
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", 456);
Exchange e3 = new DefaultExchange(context);
e3.getIn().setBody("END");
e3.getIn().setHeader("id", 123);
Exchange e4 = new DefaultExchange(context);
e4.getIn().setBody("END");
e4.getIn().setHeader("id", 456);
ap.process(e1);
ap.process(e2);
ap.process(e3);
ap.process(e4);
assertEquals("should not have completed yet", 0, mock.getExchanges().size());
ap.forceCompletionOfAllGroups();
assertMockEndpointsSatisfied();
ap.stop();
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class AggregateProcessorTest method testAggregateProcessorCompletionPredicateEager.
public void testAggregateProcessorCompletionPredicateEager() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B+END");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "predicate");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
Predicate complete = body().isEqualTo("END");
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
ap.setCompletionPredicate(complete);
ap.setEagerCheckCompletion(true);
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("END");
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);
ap.process(e4);
assertMockEndpointsSatisfied();
ap.stop();
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class AggregateProcessorTest method doTestAggregateProcessorCompletionTimeout.
private void doTestAggregateProcessorCompletionTimeout(boolean eager) throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B+C");
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);
ap.setCompletionTimeout(3000);
ap.setEagerCheckCompletion(eager);
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);
Thread.sleep(250);
ap.process(e2);
Thread.sleep(500);
ap.process(e3);
Thread.sleep(5000);
ap.process(e4);
assertMockEndpointsSatisfied();
ap.stop();
}
use of org.apache.camel.impl.DefaultExchange in project camel by apache.
the class AggregateProcessorTest method testAggregateProcessorCompletionPredicate.
public void testAggregateProcessorCompletionPredicate() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("A+B+END");
mock.expectedPropertyReceived(Exchange.AGGREGATED_COMPLETED_BY, "predicate");
Processor done = new SendProcessor(context.getEndpoint("mock:result"));
Expression corr = header("id");
AggregationStrategy as = new BodyInAggregatingStrategy();
Predicate complete = body().contains("END");
AggregateProcessor ap = new AggregateProcessor(context, done, corr, as, executorService, true);
ap.setCompletionPredicate(complete);
ap.setEagerCheckCompletion(false);
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("END");
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);
ap.process(e4);
assertMockEndpointsSatisfied();
ap.stop();
}
use of org.apache.camel.impl.DefaultExchange 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();
}
Aggregations