camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From acosent...@apache.org
Subject [2/3] camel git commit: CAMEL-10397 SJMS - Raise an error against InOut+transacted producer as it causes a deadlock
Date Wed, 19 Oct 2016 07:54:20 GMT
CAMEL-10397 SJMS - Raise an error against InOut+transacted producer as it causes a deadlock


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

Branch: refs/heads/master
Commit: d3b0b65f5234ec9cfb08863cb617f9390b6dddbc
Parents: 825a35f
Author: Tomohisa Igarashi <tm.igarashi@gmail.com>
Authored: Wed Oct 19 11:31:47 2016 +0900
Committer: Andrea Cosentino <ancosen@gmail.com>
Committed: Wed Oct 19 09:45:51 2016 +0200

----------------------------------------------------------------------
 .../component/sjms/producer/InOutProducer.java  |  4 ++
 .../tx/TransactedProducerInOutErrorTest.java    | 69 ++++++++++++++++++++
 2 files changed, 73 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d3b0b65f/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/producer/InOutProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/producer/InOutProducer.java
b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/producer/InOutProducer.java
index 68d13e2..aea6563 100644
--- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/producer/InOutProducer.java
+++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/producer/InOutProducer.java
@@ -139,6 +139,10 @@ public class InOutProducer extends SjmsProducer {
 
     @Override
     protected void doStart() throws Exception {
+        if (isEndpointTransacted()) {
+            throw new IllegalArgumentException("InOut exchange pattern is incompatible with
transacted=true as it cuases a deadlock. Please use transacted=false or InOnly exchange pattern.");
+        }
+
         if (ObjectHelper.isEmpty(getNamedReplyTo())) {
             log.debug("No reply to destination is defined.  Using temporary destinations.");
         } else {

http://git-wip-us.apache.org/repos/asf/camel/blob/d3b0b65f/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedProducerInOutErrorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedProducerInOutErrorTest.java
b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedProducerInOutErrorTest.java
new file mode 100644
index 0000000..364bc79
--- /dev/null
+++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedProducerInOutErrorTest.java
@@ -0,0 +1,69 @@
+/**
+ * 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.component.sjms.tx;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.FailedToCreateProducerException;
+import org.apache.camel.FailedToCreateRouteException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.sjms.CamelJmsTestHelper;
+import org.apache.camel.component.sjms.SjmsComponent;
+import org.apache.camel.component.sjms.support.JmsTestSupport;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Assert;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A unit test to ensure the error is raised against incompatible configuration, InOut +
transacted.
+ */
+public class TransactedProducerInOutErrorTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TransactedProducerInOutErrorTest.class);
+
+    @Test(expected = IllegalArgumentException.class)
+    public void test() throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.addRoutes(createRouteBuilder());
+        SjmsComponent component = context.getComponent("sjms", SjmsComponent.class);
+        component.setConnectionFactory(CamelJmsTestHelper.createConnectionFactory());
+        try {
+            context.start();
+        } catch (Throwable t) {
+            LOG.info("Exception was thrown as expected", t);
+            throw t;
+        }
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+
+                from("direct:start")
+                    .to("sjms:queue:test-in?namedReplyTo=test-out&exchangePattern=InOut&transacted=true")
+                    .to("mock:result");
+
+                from("sjms:queue:test-in?exchangePattern=InOut")
+                    .log("Using ${threadName} to process ${body}")
+                    .transform(body().prepend("Bye "));
+            }
+        };
+    }
+}


Mime
View raw message