Search in sources :

Example 16 with AggregateProcessor

use of org.apache.camel.processor.aggregate.AggregateProcessor in project camel by apache.

the class AggregateProcessorTimeoutCompletionRestartTest method testAggregateProcessorTwoTimeoutExpressionRestart.

public void testAggregateProcessorTwoTimeoutExpressionRestart() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("C+D", "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", 3000);
    Exchange e2 = new DefaultExchange(context);
    e2.getIn().setBody("B");
    e2.getIn().setHeader("id", 123);
    e2.getIn().setHeader("myTimeout", 3000);
    Exchange e3 = new DefaultExchange(context);
    e3.getIn().setBody("C");
    e3.getIn().setHeader("id", 456);
    e3.getIn().setHeader("myTimeout", 2000);
    Exchange e4 = new DefaultExchange(context);
    e4.getIn().setBody("D");
    e4.getIn().setHeader("id", 456);
    e4.getIn().setHeader("myTimeout", 2000);
    ap.process(e1);
    ap.process(e2);
    ap.process(e3);
    ap.process(e4);
    // 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(2, mock.getReceivedCounter());
    ap.shutdown();
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) Processor(org.apache.camel.Processor) SendProcessor(org.apache.camel.processor.SendProcessor) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Expression(org.apache.camel.Expression) BodyInAggregatingStrategy(org.apache.camel.processor.BodyInAggregatingStrategy) SendProcessor(org.apache.camel.processor.SendProcessor) AggregationStrategy(org.apache.camel.processor.aggregate.AggregationStrategy) AggregateProcessor(org.apache.camel.processor.aggregate.AggregateProcessor)

Aggregations

Processor (org.apache.camel.Processor)16 AggregateProcessor (org.apache.camel.processor.aggregate.AggregateProcessor)16 Expression (org.apache.camel.Expression)15 SendProcessor (org.apache.camel.processor.SendProcessor)15 AggregationStrategy (org.apache.camel.processor.aggregate.AggregationStrategy)15 Exchange (org.apache.camel.Exchange)14 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 DefaultExchange (org.apache.camel.impl.DefaultExchange)14 BodyInAggregatingStrategy (org.apache.camel.processor.BodyInAggregatingStrategy)14 Predicate (org.apache.camel.Predicate)6 Iterator (java.util.Iterator)1 ExecutorService (java.util.concurrent.ExecutorService)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 DelegateProcessor (org.apache.camel.DelegateProcessor)1 BeanProcessor (org.apache.camel.component.bean.BeanProcessor)1 LogEndpoint (org.apache.camel.component.log.LogEndpoint)1 ManagedAggregateProcessor (org.apache.camel.management.mbean.ManagedAggregateProcessor)1 ManagedBeanProcessor (org.apache.camel.management.mbean.ManagedBeanProcessor)1 ManagedChoice (org.apache.camel.management.mbean.ManagedChoice)1 ManagedCircuitBreakerLoadBalancer (org.apache.camel.management.mbean.ManagedCircuitBreakerLoadBalancer)1