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 2016/02/07 18:19:22 UTC

[2/6] camel git commit: CAMEL-9444: Added test and avoid adding the same exception multiple times when using sharedUnitOfWork

CAMEL-9444: Added test and avoid adding the same exception multiple times when using sharedUnitOfWork


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

Branch: refs/heads/master
Commit: 7c826d339fd0cb6a08efd7b4137fafc8ef4e408a
Parents: c710a2b
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 7 17:06:31 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 7 17:06:31 2016 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultSubUnitOfWork.java |  5 +-
 ...tOfWorkOnExceptionHandledFalseIssueTest.java | 61 ++++++++++++++++++++
 2 files changed, 65 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7c826d33/camel-core/src/main/java/org/apache/camel/impl/DefaultSubUnitOfWork.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultSubUnitOfWork.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultSubUnitOfWork.java
index 2bbc4b1..ec29df3 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultSubUnitOfWork.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultSubUnitOfWork.java
@@ -62,7 +62,10 @@ public class DefaultSubUnitOfWork implements SubUnitOfWork, SubUnitOfWorkCallbac
         if (failedExceptions == null) {
             failedExceptions = new ArrayList<Exception>();
         }
-        failedExceptions.add(exception);
+        if (!failedExceptions.contains(exception)) {
+            // avoid adding the same exception multiple times
+            failedExceptions.add(exception);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/7c826d33/camel-core/src/test/java/org/apache/camel/issues/MulticastShareUnitOfWorkOnExceptionHandledFalseIssueTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/MulticastShareUnitOfWorkOnExceptionHandledFalseIssueTest.java b/camel-core/src/test/java/org/apache/camel/issues/MulticastShareUnitOfWorkOnExceptionHandledFalseIssueTest.java
new file mode 100644
index 0000000..bb9f88f
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/MulticastShareUnitOfWorkOnExceptionHandledFalseIssueTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class MulticastShareUnitOfWorkOnExceptionHandledFalseIssueTest extends ContextTestSupport {
+
+    public void testMulticast() throws Exception {
+        // TODO: CAMEL-9444: getMockEndpoint("mock:a").expectedMessageCount(1);
+        getMockEndpoint("mock:b").expectedMessageCount(1);
+        getMockEndpoint("mock:result").expectedMessageCount(0);
+
+        try {
+            template.sendBody("direct:start", "Hello World");
+            fail("Should throw exception");
+        } catch (Exception e) {
+            IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Forced", cause.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(Exception.class)
+                    .handled(false)
+                    .to("mock:a");
+
+                from("direct:start")
+                    .multicast().shareUnitOfWork().stopOnException()
+                        .to("direct:b")
+                    .end()
+                    .to("mock:result");
+
+                from("direct:b")
+                    .to("mock:b")
+                    .throwException(new IllegalArgumentException("Forced"));
+            }
+        };
+    }
+}