You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2021/07/01 06:32:42 UTC

[camel] branch camel-3.11.x updated: CAMEL-16772: camel-sjms - Fix TransactionOnCompletion to equal with the same class (#5772)

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

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


The following commit(s) were added to refs/heads/camel-3.11.x by this push:
     new 6dcc688  CAMEL-16772: camel-sjms - Fix TransactionOnCompletion to equal with the same class (#5772)
6dcc688 is described below

commit 6dcc68883cc6559034e0f815e890ec78ce9f0fdc
Author: Amos Feng <zh...@gmail.com>
AuthorDate: Thu Jul 1 13:19:24 2021 +0800

    CAMEL-16772: camel-sjms - Fix TransactionOnCompletion to equal with the same class (#5772)
---
 .../component/sjms/TransactionOnCompletion.java    |  2 +-
 .../sjms/tx/TransactedOnCompletionTest.java        | 71 ++++++++++++++++++++++
 2 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/TransactionOnCompletion.java b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/TransactionOnCompletion.java
index 91359c3..33ba7ba 100644
--- a/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/TransactionOnCompletion.java
+++ b/components/camel-sjms/src/main/java/org/apache/camel/component/sjms/TransactionOnCompletion.java
@@ -59,7 +59,7 @@ class TransactionOnCompletion extends SynchronizationAdapter {
 
     @Override
     public boolean equals(Object o) {
-        if (o == null) {
+        if (!(o instanceof TransactionOnCompletion) || o == null) {
             return false;
         }
 
diff --git a/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedOnCompletionTest.java b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedOnCompletionTest.java
new file mode 100644
index 0000000..7690f24
--- /dev/null
+++ b/components/camel-sjms/src/test/java/org/apache/camel/component/sjms/tx/TransactedOnCompletionTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.sjms.SjmsComponent;
+import org.apache.camel.test.junit5.CamelTestSupport;
+import org.junit.jupiter.api.Test;
+
+public class TransactedOnCompletionTest extends CamelTestSupport {
+
+    @Produce
+    protected ProducerTemplate template;
+
+    @Test
+    void testOnCompletion() throws Exception {
+        getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+        getMockEndpoint("mock:onCompletion").expectedBodiesReceived("onCompletion");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected CamelContext createCamelContext() throws Exception {
+        ActiveMQConnectionFactory connectionFactory
+                = new ActiveMQConnectionFactory("vm://broker?broker.persistent=false&broker.useJmx=false");
+        CamelContext camelContext = super.createCamelContext();
+        SjmsComponent component = new SjmsComponent();
+        component.setConnectionFactory(connectionFactory);
+        camelContext.addComponent("sjms", component);
+        return camelContext;
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() {
+                from("direct:start")
+                        .onCompletion()
+                        .setBody(simple("onCompletion"))
+                        .to("mock:onCompletion")
+                        .end()
+                        .to("sjms:queue:test.queue?transacted=true");
+
+                from("sjms:queue:test.queue?transacted=true")
+                        .to("mock:result");
+            }
+        };
+    }
+}