camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1328676 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ test/java/org/apache/camel/processor/
Date Sat, 21 Apr 2012 14:52:22 GMT
Author: davsclaus
Date: Sat Apr 21 14:52:21 2012
New Revision: 1328676

URL: http://svn.apache.org/viewvc?rev=1328676&view=rev
Log:
CAMEL-1260: Added support for consumer.bridgeErrorHandler option to let the routing error
handler deal with cosumer exceptions occuring outside the routing engine.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerRedeliveryTest.java
      - copied, changed from r1328618, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BridgeExceptionHandlerToErrorHandler.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BridgeExceptionHandlerToErrorHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BridgeExceptionHandlerToErrorHandler.java?rev=1328676&r1=1328675&r2=1328676&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BridgeExceptionHandlerToErrorHandler.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/BridgeExceptionHandlerToErrorHandler.java
Sat Apr 21 14:52:21 2012
@@ -63,6 +63,8 @@ public class BridgeExceptionHandlerToErr
         exchange.setException(exception);
         // and the message
         exchange.getIn().setBody(message);
+        // and mark as redelivery exhausted as we cannot do redeliveries
+        exchange.setProperty(Exchange.REDELIVERY_EXHAUSTED, Boolean.TRUE);
 
         try {
             bridge.process(exchange);

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerRedeliveryTest.java
(from r1328618, camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerRedeliveryTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerRedeliveryTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java&r1=1328618&r2=1328676&rev=1328676&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerRedeliveryTest.java
Sat Apr 21 14:52:21 2012
@@ -16,28 +16,18 @@
  */
 package org.apache.camel.processor;
 
-import java.util.Map;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.camel.Component;
-import org.apache.camel.Consumer;
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.Endpoint;
+import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
-import org.apache.camel.Producer;
 import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.impl.DefaultConsumer;
-import org.apache.camel.impl.DefaultEndpoint;
 
 /**
  *
  */
-public class DefaultConsumerBridgeErrorHandlerTest extends ContextTestSupport {
+public class DefaultConsumerBridgeErrorHandlerRedeliveryTest extends DefaultConsumerBridgeErrorHandlerTest
{
 
-    private final CountDownLatch latch = new CountDownLatch(1);
+    protected final AtomicInteger redeliverCounter = new AtomicInteger();
 
     public void testDefaultConsumerBridgeErrorHandler() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello World");
@@ -47,6 +37,9 @@ public class DefaultConsumerBridgeErrorH
 
         assertMockEndpointsSatisfied();
 
+        // should not attempt redelivery as we must be exhausted when bridging the error
handler
+        assertEquals(0, redeliverCounter.get());
+
         Exception cause = getMockEndpoint("mock:dead").getReceivedExchanges().get(0).getProperty(Exchange.EXCEPTION_CAUGHT,
Exception.class);
         assertNotNull(cause);
         assertEquals("Simulated", cause.getMessage());
@@ -54,15 +47,23 @@ public class DefaultConsumerBridgeErrorH
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
-        // START SNIPPET: e1
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
                 // register our custom component
                 getContext().addComponent("my", new MyComponent());
 
-                // configure error handler
-                errorHandler(deadLetterChannel("mock:dead"));
+                // configure exception clause
+                onException(Exception.class)
+                        .maximumRedeliveries(3)
+                        .onRedelivery(new Processor() {
+                            @Override
+                            public void process(Exchange exchange) throws Exception {
+                                redeliverCounter.incrementAndGet();
+                            }
+                        })
+                        .handled(true)
+                        .to("mock:dead");
 
                 // configure the consumer to bridge with the Camel error handler,
                 // so the above error handler will trigger if exceptions also
@@ -72,83 +73,6 @@ public class DefaultConsumerBridgeErrorH
                     .to("mock:result");
             }
         };
-        // END SNIPPET: e1
-    }
-
-    public class MyComponent extends DefaultComponent {
-
-        @Override
-        protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-            return new MyEndpoint(uri, this);
-        }
-    }
-
-    public class MyEndpoint extends DefaultEndpoint {
-
-        public MyEndpoint(String endpointUri, Component component) {
-            super(endpointUri, component);
-        }
-
-        @Override
-        public Producer createProducer() throws Exception {
-            return null;
-        }
-
-        @Override
-        public Consumer createConsumer(Processor processor) throws Exception {
-            Consumer answer = new MyConsumer(this, processor);
-            configureConsumer(answer);
-            return answer;
-        }
-
-        @Override
-        public boolean isSingleton() {
-            return true;
-        }
     }
 
-    public class MyConsumer extends DefaultConsumer {
-
-        private int invoked;
-
-        public MyConsumer(Endpoint endpoint, Processor processor) {
-            super(endpoint, processor);
-        }
-
-        public void doSomething() throws Exception {
-            try {
-                if (invoked++ == 0) {
-                    throw new IllegalArgumentException("Simulated");
-                }
-
-                Exchange exchange = getEndpoint().createExchange();
-                exchange.getIn().setBody("Hello World");
-                getProcessor().process(exchange);
-
-            } catch (Exception e) {
-                getExceptionHandler().handleException("Cannot process", e);
-            }
-        }
-
-        @Override
-        protected void doStart() throws Exception {
-            super.doStart();
-
-            Thread thread = new Thread() {
-                @Override
-                public void run() {
-                    try {
-                        // do not start before the mocks has been setup and is ready
-                        latch.await(5, TimeUnit.SECONDS);
-                        doSomething();
-                        doSomething();
-                        doSomething();
-                    } catch (Exception e) {
-                        // ignore
-                    }
-                }
-            };
-            thread.start();
-        }
-    }
 }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java?rev=1328676&r1=1328675&r2=1328676&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DefaultConsumerBridgeErrorHandlerTest.java
Sat Apr 21 14:52:21 2012
@@ -37,7 +37,7 @@ import org.apache.camel.impl.DefaultEndp
  */
 public class DefaultConsumerBridgeErrorHandlerTest extends ContextTestSupport {
 
-    private final CountDownLatch latch = new CountDownLatch(1);
+    protected final CountDownLatch latch = new CountDownLatch(1);
 
     public void testDefaultConsumerBridgeErrorHandler() throws Exception {
         getMockEndpoint("mock:result").expectedBodiesReceived("Hello World", "Hello World");



Mime
View raw message