camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/4] camel git commit: CAMEL-8945: Loop - Should break out looping if exception happened during routing
Date Thu, 09 Jul 2015 11:46:14 GMT
CAMEL-8945: Loop - Should break out looping if exception happened during routing


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b580f3f6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b580f3f6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b580f3f6

Branch: refs/heads/master
Commit: b580f3f6476e893e6d86365382fd4b8883bc6ee4
Parents: 3c8b0b7
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu Jul 9 13:45:48 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Jul 9 13:45:48 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/processor/LoopProcessor.java   | 12 +++++
 .../camel/processor/LoopExceptionTest.java      | 49 ++++++++++++++++++++
 2 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b580f3f6/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
index d5b484d..124ba89 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/LoopProcessor.java
@@ -29,6 +29,8 @@ import org.apache.camel.util.ExchangeHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.processor.PipelineHelper.continueProcessing;
+
 /**
  * The processor which sends messages in a loop.
  */
@@ -89,6 +91,11 @@ public class LoopProcessor extends DelegateAsyncProcessor implements Traceable,
 
             LOG.trace("Processing exchangeId: {} is continued being processed synchronously",
target.getExchangeId());
 
+            // check for error if so we should break out
+            if (!continueProcessing(target, "so breaking out of loop", LOG)) {
+                break;
+            }
+
             // increment counter before next loop
             index.getAndIncrement();
         }
@@ -135,6 +142,11 @@ public class LoopProcessor extends DelegateAsyncProcessor implements
Traceable,
                         return;
                     }
 
+                    // check for error if so we should break out
+                    if (!continueProcessing(target, "so breaking out of loop", LOG)) {
+                        break;
+                    }
+
                     // increment counter before next loop
                     index.getAndIncrement();
                 }

http://git-wip-us.apache.org/repos/asf/camel/blob/b580f3f6/camel-core/src/test/java/org/apache/camel/processor/LoopExceptionTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/LoopExceptionTest.java b/camel-core/src/test/java/org/apache/camel/processor/LoopExceptionTest.java
new file mode 100644
index 0000000..83a0672
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/LoopExceptionTest.java
@@ -0,0 +1,49 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class LoopExceptionTest extends ContextTestSupport {
+
+    public void testLoopException() throws Exception {
+        getMockEndpoint("mock:dead").expectedMessageCount(1);
+        getMockEndpoint("mock:loop").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                errorHandler(deadLetterChannel("mock:dead"));
+
+                from("direct:start")
+                    .loop(3)
+                        .to("mock:loop")
+                        .throwException(new IllegalArgumentException("Forced"))
+                    .end()
+                    .to("mock:result");
+            }
+        };
+    }
+}


Mime
View raw message