You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2018/10/16 14:54:29 UTC
[camel] branch master updated: [CAMEL-12886] Various asynchronous
engine issues
This is an automated email from the ASF dual-hosted git repository.
gnodet 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 ef2075b [CAMEL-12886] Various asynchronous engine issues
ef2075b is described below
commit ef2075bea278a152c83aab5c198dd4344a5b5824
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Tue Oct 16 14:59:17 2018 +0200
[CAMEL-12886] Various asynchronous engine issues
---
.../camel/impl/SubscribeMethodProcessor.java | 3 +-
.../org/apache/camel/processor/LoopProcessor.java | 2 +-
.../apache/camel/processor/MulticastProcessor.java | 5 +-
.../org/apache/camel/processor/RoutingSlip.java | 2 +-
.../loadbalancer/FailOverLoadBalancer.java | 1 +
.../apache/camel/processor/AsyncLoopCopyTest.java | 4 +-
.../apache/camel/processor/LoopAsyncCopyTest.java | 58 ++++++++++++++++++++++
.../camel/processor/LoopAsyncNoCopyTest.java | 58 ++++++++++++++++++++++
8 files changed, 124 insertions(+), 9 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java b/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java
index bf39a7e..43acdd9 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/SubscribeMethodProcessor.java
@@ -88,9 +88,8 @@ public final class SubscribeMethodProcessor extends ServiceSupport implements As
}
} catch (Throwable e) {
exchange.setException(e);
- return true;
}
-
+ callback.done(true);
return true;
}
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 07bb255..9da438c 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
@@ -172,7 +172,7 @@ public class LoopProcessor extends DelegateAsyncProcessor implements Traceable,
}
// we are done so prepare the result
- ExchangeHelper.copyResults(exchange, target);
+ ExchangeHelper.copyResults(original, target);
LOG.trace("Processing complete for exchangeId: {} >>> {}", exchange.getExchangeId(), exchange);
callback.done(false);
}
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 98f8abc..b0d6e32 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
@@ -758,10 +758,9 @@ public class MulticastProcessor extends ServiceSupport implements AsyncProcessor
doAggregate(getAggregationStrategy(subExchange), result, subExchange);
}
} catch (Throwable e) {
- // wrap in exception to explain where it failed
- subExchange.setException(new CamelExchangeException("Sequential processing failed for number " + total, subExchange, e));
+ original.setException(e);
// and do the done work
- doDone(original, subExchange, pairs, callback, false, true);
+ doDone(original, null, pairs, callback, false, true);
return;
}
diff --git a/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java b/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
index dbfb8ad..7358d6a 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RoutingSlip.java
@@ -408,7 +408,7 @@ public class RoutingSlip extends ServiceSupport implements AsyncProcessor, Trace
}
} catch (Exception e) {
// error resolving endpoint so we should break out
- exchange.setException(e);
+ current.setException(e);
break;
}
diff --git a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
index d02df0e..d0d37d3 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/loadbalancer/FailOverLoadBalancer.java
@@ -315,6 +315,7 @@ public class FailOverLoadBalancer extends LoadBalancerSupport implements Traceab
}
// we cannot process so invoke callback
callback.done(false);
+ return;
}
attempts.incrementAndGet();
diff --git a/camel-core/src/test/java/org/apache/camel/processor/AsyncLoopCopyTest.java b/camel-core/src/test/java/org/apache/camel/processor/AsyncLoopCopyTest.java
index cee8b7d..7013dbd 100644
--- a/camel-core/src/test/java/org/apache/camel/processor/AsyncLoopCopyTest.java
+++ b/camel-core/src/test/java/org/apache/camel/processor/AsyncLoopCopyTest.java
@@ -36,10 +36,10 @@ public class AsyncLoopCopyTest extends ContextTestSupport {
getMockEndpoint("mock:before").expectedBodiesReceived("Hello Camel");
getMockEndpoint("mock:loopIterationStart").expectedBodiesReceived("Hello Camel", "Hello Camel");
getMockEndpoint("mock:loopIterationEnd").expectedBodiesReceived("Bye Camel", "Bye Camel");
- getMockEndpoint("mock:result").expectedBodiesReceived("Hello Camel");
+ getMockEndpoint("mock:result").expectedBodiesReceived("Bye Camel");
String reply = template.requestBodyAndHeader("direct:start", "Hello Camel", "NumberIterations", 2, String.class);
- assertEquals("Hello Camel", reply);
+ assertEquals("Bye Camel", reply);
assertMockEndpointsSatisfied();
diff --git a/camel-core/src/test/java/org/apache/camel/processor/LoopAsyncCopyTest.java b/camel-core/src/test/java/org/apache/camel/processor/LoopAsyncCopyTest.java
new file mode 100644
index 0000000..7e1a838
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/LoopAsyncCopyTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class LoopAsyncCopyTest extends ContextTestSupport {
+
+ @Test
+ public void testLoopCopy() throws Exception {
+ getMockEndpoint("mock:loop").expectedBodiesReceived("AB", "AB", "AB");
+ getMockEndpoint("mock:result").expectedBodiesReceived("AB");
+
+ template.sendBody("direct:start", "A");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ from("direct:start")
+ // instruct loop to use copy mode, which mean it will use a copy of the input exchange
+ // for each loop iteration, instead of keep using the same exchange all over
+ .loop(3).copy()
+ .threads(1)
+ .transform(body().append("B"))
+ .end()
+ .to("mock:loop")
+ .end()
+ .to("mock:result");
+ // END SNIPPET: e1
+ }
+ };
+ }
+}
diff --git a/camel-core/src/test/java/org/apache/camel/processor/LoopAsyncNoCopyTest.java b/camel-core/src/test/java/org/apache/camel/processor/LoopAsyncNoCopyTest.java
new file mode 100644
index 0000000..381a564
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/LoopAsyncNoCopyTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class LoopAsyncNoCopyTest extends ContextTestSupport {
+
+ @Test
+ public void testLoopNoCopy() throws Exception {
+ getMockEndpoint("mock:loop").expectedBodiesReceived("AB", "ABB", "ABBB");
+ getMockEndpoint("mock:result").expectedBodiesReceived("ABBB");
+
+ template.sendBody("direct:start", "A");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // START SNIPPET: e1
+ from("direct:start")
+ // by default loop will keep using the same exchange so on the 2nd and 3rd iteration its
+ // the same exchange that was previous used that are being looped all over
+ .loop(3)
+ .threads(1)
+ .transform(body().append("B"))
+ .end()
+ .to("mock:loop")
+ .end()
+ .to("mock:result");
+ // END SNIPPET: e1
+ }
+ };
+ }
+}