You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/12/15 12:14:55 UTC

svn commit: r890762 - /camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListFineGrainedErrorHandlingTest.java

Author: davsclaus
Date: Tue Dec 15 11:14:54 2009
New Revision: 890762

URL: http://svn.apache.org/viewvc?rev=890762&view=rev
Log:
CAMEL-2278: Added additional unit test

Modified:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListFineGrainedErrorHandlingTest.java

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListFineGrainedErrorHandlingTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListFineGrainedErrorHandlingTest.java?rev=890762&r1=890761&r2=890762&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListFineGrainedErrorHandlingTest.java (original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RecipientListFineGrainedErrorHandlingTest.java Tue Dec 15 11:14:54 2009
@@ -22,6 +22,7 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.processor.aggregate.AggregationStrategy;
 
 /**
  * @version $Revision$
@@ -29,6 +30,7 @@
 public class RecipientListFineGrainedErrorHandlingTest extends ContextTestSupport {
 
     private static int counter;
+    private static int tries;
 
     @Override
     protected JndiRegistry createRegistry() throws Exception {
@@ -60,6 +62,38 @@
         assertMockEndpointsSatisfied();
     }
 
+    public void testRecipientListErrorAggregate() throws Exception {
+        counter = 0;
+        tries = 0;
+
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start")
+                    .onException(Exception.class).maximumRedeliveries(3).end()
+                    .to("mock:a")
+                    .recipientList(header("foo"))
+                        .aggregationStrategy(new MyAggregationStrategy())
+                        .parallelProcessing();
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:foo").expectedMessageCount(1);
+        getMockEndpoint("mock:bar").expectedMessageCount(1);
+        getMockEndpoint("mock:baz").expectedMessageCount(1);
+
+        template.sendBodyAndHeader("direct:start", "Hello World", "foo", "mock:foo,mock:bar,bean:fail,mock:baz");
+
+        assertMockEndpointsSatisfied();
+
+        // bean is invoked 4 times
+        assertEquals(4, counter);
+        // of which 3 of them is retries
+        assertEquals(3, tries);
+    }
+
     public void testRecipientListError() throws Exception {
         counter = 0;
 
@@ -134,6 +168,22 @@
         return false;
     }
 
+    public static class MyAggregationStrategy implements AggregationStrategy {
+
+        public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
+            // check whether we have attempted redelivery
+            Boolean redelivered = newExchange.getIn().getHeader(Exchange.REDELIVERED, Boolean.class);
+            if (redelivered != null && redelivered) {
+                // extract the number of times we tried
+                tries = newExchange.getIn().getHeader(Exchange.REDELIVERY_COUNTER, Integer.class);
+                // this is the endpoint that failed
+                assertEquals("bean://fail", newExchange.getProperty(Exchange.FAILURE_ENDPOINT, String.class));
+            }
+            // just let it pass through
+            return newExchange;
+        }
+    }
+
     public static class MyRecipientBean {
 
         @org.apache.camel.RecipientList(stopOnException = true)