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

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


The following commit(s) were added to refs/heads/master by this push:
     new b4c0fbb  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.
b4c0fbb is described below

commit b4c0fbbe0bc9643158353c395b3629f02a0a781b
Author: Claus Ibsen <claus.ib...@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 6970aab..55cd399 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
davscl...@apache.org.

Reply via email to