camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/4] camel git commit: CAMEL-8945: Loop - Should break out looping if exception happened during routing
Date Thu, 09 Jul 2015 11:46:16 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/13831f67
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/13831f67
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/13831f67

Branch: refs/heads/camel-2.14.x
Commit: 13831f672932f62dfba444135a785bb8a4da82bb
Parents: ad675c1
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:52:35 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/13831f67/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 89649b1..a5e5caa 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
@@ -28,6 +28,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.
  */
@@ -87,6 +89,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();
         }
@@ -133,6 +140,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/13831f67/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