use of org.apache.camel.Expression 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.Expression 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.Expression 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.Expression in project camel by apache.
the class AggregatorExceptionInPredicateTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(IllegalArgumentException.class).handled(true).to("mock:handled");
from("direct:start").aggregate(header("id")).completionTimeout(500).aggregationStrategy(new AggregationStrategy() {
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
Object body = newExchange.getIn().getBody();
if ("Damn".equals(body)) {
throw new IllegalArgumentException();
}
return newExchange;
}
}).to("mock:result");
from("direct:predicate").aggregate(new Expression() {
public <T> T evaluate(Exchange exchange, Class<T> type) {
if (exchange.getIn().getBody().equals("Damn")) {
throw new IllegalArgumentException();
}
return ExpressionBuilder.headerExpression("id").evaluate(exchange, type);
}
}, new UseLatestAggregationStrategy()).completionTimeout(500).to("mock:result");
}
};
}
use of org.apache.camel.Expression in project camel by apache.
the class ExpressionListComparatorTest method testExpressionListComparator.
public void testExpressionListComparator() {
List<Expression> list = new ArrayList<Expression>();
list.add(new MyFooExpression());
list.add(new MyBarExpression());
ExpressionListComparator comp = new ExpressionListComparator(list);
Exchange e1 = new DefaultExchange(context);
Exchange e2 = new DefaultExchange(context);
int out = comp.compare(e1, e2);
assertEquals(0, out);
}
Aggregations