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/59c0b002 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/59c0b002 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/59c0b002 Branch: refs/heads/camel-2.16.x Commit: 59c0b002441711b10a3d55ac02d3cf27e3949961 Parents: 155fae5 Author: Claus Ibsen <davscl...@apache.org> Authored: Sun Feb 7 17:06:31 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sun Feb 7 18:19:05 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/59c0b002/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/59c0b002/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")); + } + }; + } +}