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 2018/04/16 08:31:58 UTC

[camel] branch camel-2.20.x updated: CAMEL-12441: Fixed splitter in parallel and streaming mode may block if iterator next throws exception on first call. Thanks to Bodor Maria Mihaela for reporting and reproducer sample project.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch camel-2.20.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.20.x by this push:
     new a85886f  CAMEL-12441: Fixed splitter in parallel and streaming mode may block if iterator next throws exception on first call. Thanks to Bodor Maria Mihaela for reporting and reproducer sample project.
a85886f is described below

commit a85886f18face2ee747d6037a01024b3cfd6a31e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 16 10:30:50 2018 +0200

    CAMEL-12441: Fixed splitter in parallel and streaming mode may block if iterator next throws exception on first call. Thanks to Bodor Maria Mihaela for reporting and reproducer sample project.
---
 .../apache/camel/processor/MulticastProcessor.java |   4 +
 ...rParallelWithIteratorThrowingExceptionTest.java | 111 +++++++++++++++++++++
 2 files changed, 115 insertions(+)

diff --git a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index b16c8e1..ac3b116 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -361,6 +361,10 @@ public class MulticastProcessor extends ServiceSupport implements AsyncProcessor
                 } else {
                     executionException.set(ObjectHelper.wrapRuntimeCamelException(e));
                 }
+                // and because of the exception we must signal we are done so the latch can open and let the other thread continue processing
+                LOG.debug("Signaling we are done aggregating on the fly for exchangeId: {}", original.getExchangeId());
+                LOG.trace("Aggregate on the fly task done for exchangeId: {}", original.getExchangeId());
+                aggregationOnTheFlyDone.countDown();
             }
 
             // signal all tasks has been submitted
diff --git a/camel-core/src/test/java/org/apache/camel/issues/SplitterParallelWithIteratorThrowingExceptionTest.java b/camel-core/src/test/java/org/apache/camel/issues/SplitterParallelWithIteratorThrowingExceptionTest.java
new file mode 100644
index 0000000..0713d79
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/SplitterParallelWithIteratorThrowingExceptionTest.java
@@ -0,0 +1,111 @@
+/**
+ * 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.issues;
+
+import java.util.Iterator;
+import java.util.function.Consumer;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.processor.aggregate.UseLatestAggregationStrategy;
+
+/**
+ * Tests the issue stated in
+ * <a href="https://issues.apache.org/jira/browse/CAMEL-12441">CAMEL-12441</a>.
+ */
+public class SplitterParallelWithIteratorThrowingExceptionTest extends ContextTestSupport {
+
+    public void testIteratorThrowExceptionOnFirst() throws Exception {
+        getMockEndpoint("mock:line").expectedMessageCount(0);
+        getMockEndpoint("mock:end").expectedMessageCount(0);
+
+        try {
+            template.sendBody("direct:start", new MyIterator(1));
+            fail("Should throw exception");
+        } catch (Exception e) {
+            IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Forced error", iae.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testIteratorThrowExceptionOnSecond() throws Exception {
+        getMockEndpoint("mock:line").expectedMessageCount(1);
+        getMockEndpoint("mock:end").expectedMessageCount(0);
+
+        try {
+            template.sendBody("direct:start", new MyIterator(0));
+            fail("Should throw exception");
+        } catch (Exception e) {
+            IllegalArgumentException iae = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Forced error", iae.getMessage());
+        }
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").
+                    split(body())
+                        .aggregationStrategy(new UseLatestAggregationStrategy())
+                        .streaming().stopOnException().parallelProcessing().parallelAggregate()
+                            .to("mock:line")
+                    .end()
+                    .to("mock:end");
+            }
+        };
+    }
+
+    public static class MyIterator implements Iterator<String> {
+
+        public MyIterator(int count) {
+            this.count = count;
+        }
+
+        private int count;
+
+        @Override
+        public boolean hasNext() {
+            return count < 2;
+        }
+
+        @Override
+        public String next() {
+            count++;
+            if (count == 1) {
+                return "Hello";
+            } else {
+                throw new IllegalArgumentException("Forced error");
+            }
+        }
+
+        @Override
+        public void remove() {
+            // noop
+        }
+
+        @Override
+        public void forEachRemaining(Consumer<? super String> action) {
+            // noop
+        }
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.