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

mattrpav pushed a commit to branch activemq-5.18.x
in repository https://gitbox.apache.org/repos/asf/activemq.git


The following commit(s) were added to refs/heads/activemq-5.18.x by this push:
     new f14f78ddc [AMQ-8325] JMS 2.0 XA supported operations
f14f78ddc is described below

commit f14f78ddc730c121643403084426aa058c5c71ba
Author: Matt Pavlovich <[email protected]>
AuthorDate: Wed Aug 30 10:54:16 2023 -0500

    [AMQ-8325] JMS 2.0 XA supported operations
    
     - Backported jakarta.jms -> javax.jms imports
    
    (cherry picked from commit da2f1376b2c3c83354642a82cd6c20d8976a4598)
---
 .../java/org/apache/activemq/ActiveMQContext.java  |  5 +-
 .../activemq/ActiveMQXAConnectionFactory.java      | 15 ++++-
 .../org/apache/activemq/ActiveMQXAContext.java     | 42 ++++++++++++
 .../activemq/ActiveMQXASslConnectionFactory.java   | 13 +++-
 .../activemq/jms2/ActiveMQJMS2ConnectionTest.java  | 12 ----
 .../apache/activemq/jms2/ActiveMQJMS2TestBase.java | 75 +++++++++++++++++++++-
 ...Test.java => ActiveMQJMS2XAConnectionTest.java} | 50 +++++++++------
 .../activemq/jms2/ActiveMQJMS2XAContextTest.java   | 68 ++++++++++++++++++++
 .../activemq/jms2/ActiveMQJMS2XATestBase.java      | 56 ++++++++++++++++
 9 files changed, 295 insertions(+), 41 deletions(-)

diff --git 
a/activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java 
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java
index 4966d09a2..ced175c5d 100644
--- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java
+++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQContext.java
@@ -62,7 +62,7 @@ public class ActiveMQContext implements JMSContext {
 
     private final ActiveMQConnection activemqConnection;
     private final AtomicLong connectionCounter;
-    private ActiveMQSession activemqSession = null;
+    protected ActiveMQSession activemqSession = null;
 
     // Configuration
     private boolean autoStart = DEFAULT_AUTO_START;
@@ -526,7 +526,7 @@ public class ActiveMQContext implements JMSContext {
         }
     }
 
-    private void checkContextState() {
+    protected void checkContextState() {
         if (activemqConnection == null) {
             throw new JMSRuntimeException("Connection not available");
         }
@@ -556,5 +556,4 @@ public class ActiveMQContext implements JMSContext {
          }
         return this.activemqMessageProducer;
     }
-
 }
diff --git 
a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
 
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
index 3a96b1efe..fe13e416b 100644
--- 
a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
+++ 
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
@@ -30,6 +30,7 @@ import javax.jms.XATopicConnectionFactory;
 
 import org.apache.activemq.management.JMSStatsImpl;
 import org.apache.activemq.transport.Transport;
+import org.apache.activemq.util.JMSExceptionSupport;
 
 /**
  * A factory of {@link XAConnection} instances
@@ -80,15 +81,23 @@ public class ActiveMQXAConnectionFactory extends 
ActiveMQConnectionFactory imple
     public XATopicConnection createXATopicConnection(String userName, String 
password) throws JMSException {
         return (XATopicConnection) createActiveMQConnection(userName, 
password);
     }
-    
+
     @Override
     public XAJMSContext createXAContext() {
-        throw new UnsupportedOperationException("createXAContext() is not 
supported");
+        try {
+            return new 
ActiveMQXAContext((ActiveMQXAConnection)createXAConnection());
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
     }
 
     @Override
     public XAJMSContext createXAContext(String userName, String password) {
-        throw new UnsupportedOperationException("createXAContext(userName, 
password) is not supported");
+        try {
+            return new 
ActiveMQXAContext((ActiveMQXAConnection)createXAConnection(userName, password));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
     }
 
     protected ActiveMQConnection createActiveMQConnection(Transport transport, 
JMSStatsImpl stats) throws Exception {
diff --git 
a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAContext.java 
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAContext.java
new file mode 100644
index 000000000..dbb168671
--- /dev/null
+++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXAContext.java
@@ -0,0 +1,42 @@
+/**
+ * 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.activemq;
+
+import javax.transaction.xa.XAResource;
+
+import javax.jms.JMSContext;
+import javax.jms.XAJMSContext;
+import javax.jms.XASession;
+
+public class ActiveMQXAContext extends ActiveMQContext implements XAJMSContext 
{
+
+    ActiveMQXAContext(ActiveMQXAConnection activemqXAConnection) {
+        super(activemqXAConnection);
+    }
+
+    @Override
+    public JMSContext getContext() {
+        return this;
+    }
+
+    @Override
+    public XAResource getXAResource() {
+        checkContextState();
+        return ((XASession) activemqSession).getXAResource();
+    }
+
+}
diff --git 
a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
 
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
index aa5fa6c8d..ec965e96f 100644
--- 
a/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
+++ 
b/activemq-client/src/main/java/org/apache/activemq/ActiveMQXASslConnectionFactory.java
@@ -30,6 +30,7 @@ import javax.jms.XATopicConnectionFactory;
 
 import org.apache.activemq.management.JMSStatsImpl;
 import org.apache.activemq.transport.Transport;
+import org.apache.activemq.util.JMSExceptionSupport;
 
 public class ActiveMQXASslConnectionFactory extends 
ActiveMQSslConnectionFactory implements XAConnectionFactory, 
XAQueueConnectionFactory, XATopicConnectionFactory {
 
@@ -76,12 +77,20 @@ public class ActiveMQXASslConnectionFactory extends 
ActiveMQSslConnectionFactory
 
     @Override
     public XAJMSContext createXAContext() {
-        throw new UnsupportedOperationException("createXAContext() is not 
supported");
+        try {
+            return new 
ActiveMQXAContext((ActiveMQXAConnection)createXAConnection());
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
     }
 
     @Override
     public XAJMSContext createXAContext(String userName, String password) {
-        throw new UnsupportedOperationException("createXAContext(userName, 
password) is not supported");
+        try {
+            return new 
ActiveMQXAContext((ActiveMQXAConnection)createXAConnection(userName, password));
+        } catch (JMSException e) {
+            throw JMSExceptionSupport.convertToJMSRuntimeException(e);
+        }
     }
 
     @Override
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
index d6765ad38..f976e87e0 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
@@ -50,16 +50,4 @@ public class ActiveMQJMS2ConnectionTest extends 
ActiveMQJMS2TestBase {
         verifySession(connection.createSession(Session.SESSION_TRANSACTED), 
Session.SESSION_TRANSACTED);
     }
 
-    private void verifySession(Session session, int acknowledgeMode) throws 
JMSException {
-        try {
-            assertNotNull(session);
-            assertEquals(acknowledgeMode, session.getAcknowledgeMode());
-            assertEquals(acknowledgeMode == Session.SESSION_TRANSACTED, 
session.getTransacted());
-        } finally {
-            if (session != null) {
-                session.close();
-            }
-        }
-    }
-
 }
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2TestBase.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2TestBase.java
index d15af018d..1139f4e92 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2TestBase.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2TestBase.java
@@ -16,12 +16,27 @@
  */
 package org.apache.activemq.jms2;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import java.lang.management.ManagementFactory;
+import java.util.Enumeration;
 import java.util.LinkedList;
 import java.util.List;
 import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.JMSConsumer;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.JMSProducer;
 import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.QueueBrowser;
 import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.jms.Topic;
+
 import javax.management.JMX;
 import javax.management.MBeanServer;
 import org.apache.activemq.ActiveMQConnectionFactory;
@@ -124,7 +139,19 @@ public abstract class ActiveMQJMS2TestBase {
         return JMX.newMBeanProxy(mbeanServer, 
BrokerMBeanSupport.createDestinationName(BrokerMBeanSupport.createBrokerObjectName(DEFAULT_JMX_DOMAIN_NAME,
 DEFAULT_JMX_BROKER_NAME).toString(), destination), TopicViewMBean.class);
     }
 
-    private static String cleanParameterizedMethodName(String methodName) {
+    protected void verifySession(Session session, int acknowledgeMode) throws 
JMSException {
+        try {
+            assertNotNull(session);
+            assertEquals(acknowledgeMode, session.getAcknowledgeMode());
+            assertEquals(acknowledgeMode == Session.SESSION_TRANSACTED, 
session.getTransacted());
+        } finally {
+            if (session != null) {
+                session.close();
+            }
+        }
+    }
+
+    protected static String cleanParameterizedMethodName(String methodName) {
         // clean up parameterized method string: 
TESTMESSAGETIMESTAMPTIMETOLIVE[DESTINATIONTYPE=QUEUE, MESSAGETYPE=BYTES]
         // returns: TESTMESSAGETIMESTAMPTIMETOLIVE.QUEUE.BYTES
 
@@ -138,4 +165,50 @@ public abstract class ActiveMQJMS2TestBase {
 
         return step1[0] + "." + step3[0].split("=", 2)[1] + "." + 
step3[1].split("=", 2)[1];
     }
+
+    protected static void sendMessage(JMSContext jmsContext, Destination 
testDestination, String textBody) {
+        assertNotNull(jmsContext);
+        JMSProducer jmsProducer = jmsContext.createProducer();
+        jmsProducer.send(testDestination, textBody);
+    }
+
+    protected static void browseMessage(JMSContext jmsContext, Destination 
testDestination, String expectedTextBody, boolean expectFound) throws 
JMSException {
+        assertNotNull(jmsContext);
+        assertTrue(Queue.class.isAssignableFrom(testDestination.getClass()));
+        Queue testQueue = Queue.class.cast(testDestination);
+        try(QueueBrowser queueBrowser = jmsContext.createBrowser(testQueue)) {
+            Enumeration<?> messageEnumeration = queueBrowser.getEnumeration();
+            assertNotNull(messageEnumeration);
+
+            boolean found = false; 
+            while(!found && messageEnumeration.hasMoreElements()) {
+                javax.jms.Message message = 
(javax.jms.Message)messageEnumeration.nextElement();
+                assertNotNull(message);
+                
assertTrue(TextMessage.class.isAssignableFrom(message.getClass()));
+                assertEquals(expectedTextBody, 
TextMessage.class.cast(message).getText());
+                found = true;
+            }
+            assertEquals(expectFound, found);
+        }
+    }
+
+    protected static void recvMessage(JMSContext jmsContext, Destination 
testDestination, String expectedTextBody) throws JMSException {
+        assertNotNull(jmsContext);
+        try(JMSConsumer jmsConsumer = 
jmsContext.createConsumer(testDestination)) {
+            javax.jms.Message message = jmsConsumer.receive(1000l);
+            assertNotNull(message);
+            assertTrue(TextMessage.class.isAssignableFrom(message.getClass()));
+            assertEquals(expectedTextBody, 
TextMessage.class.cast(message).getText());
+        }
+    }
+
+    protected static void recvMessageDurable(JMSContext jmsContext, Topic 
testTopic, String subscriptionName, String selector, boolean noLocal, String 
expectedTextBody) throws JMSException {
+        assertNotNull(jmsContext);
+        try(JMSConsumer jmsConsumer = 
jmsContext.createDurableConsumer(testTopic, subscriptionName, selector, 
noLocal)) {
+            javax.jms.Message message = jmsConsumer.receive(1000l);
+            assertNotNull(message);
+            assertTrue(TextMessage.class.isAssignableFrom(message.getClass()));
+            assertEquals(expectedTextBody, 
TextMessage.class.cast(message).getText());
+        }
+    }
 }
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XAConnectionTest.java
similarity index 56%
copy from 
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
copy to 
activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XAConnectionTest.java
index d6765ad38..dfc783b27 100644
--- 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ConnectionTest.java
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XAConnectionTest.java
@@ -16,33 +16,31 @@
  */
 package org.apache.activemq.jms2;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import javax.jms.JMSException;
-import javax.jms.Session;
 import org.junit.Test;
+import javax.jms.Session;
+
+public class ActiveMQJMS2XAConnectionTest extends ActiveMQJMS2XATestBase {
 
-public class ActiveMQJMS2ConnectionTest extends ActiveMQJMS2TestBase {
 
+    // XA connection always creates SESSION_TRANSACTED
     @Test
     public void testCreateSession() throws Exception {
-        verifySession(connection.createSession(), Session.AUTO_ACKNOWLEDGE);
+        verifySession(connection.createSession(), Session.SESSION_TRANSACTED);
     }
 
     @Test
     public void testCreateSessionAckModeAuto() throws Exception {
-        verifySession(connection.createSession(Session.AUTO_ACKNOWLEDGE), 
Session.AUTO_ACKNOWLEDGE);
+        verifySession(connection.createSession(Session.AUTO_ACKNOWLEDGE), 
Session.SESSION_TRANSACTED);
     }
 
     @Test
     public void testCreateSessionAckModeClient() throws Exception {
-        verifySession(connection.createSession(Session.CLIENT_ACKNOWLEDGE), 
Session.CLIENT_ACKNOWLEDGE);
+        verifySession(connection.createSession(Session.CLIENT_ACKNOWLEDGE), 
Session.SESSION_TRANSACTED);
     }
 
     @Test
     public void testCreateSessionAckModeDups() throws Exception {
-        verifySession(connection.createSession(Session.DUPS_OK_ACKNOWLEDGE), 
Session.DUPS_OK_ACKNOWLEDGE);
+        verifySession(connection.createSession(Session.DUPS_OK_ACKNOWLEDGE), 
Session.SESSION_TRANSACTED);
     }
 
     @Test
@@ -50,16 +48,28 @@ public class ActiveMQJMS2ConnectionTest extends 
ActiveMQJMS2TestBase {
         verifySession(connection.createSession(Session.SESSION_TRANSACTED), 
Session.SESSION_TRANSACTED);
     }
 
-    private void verifySession(Session session, int acknowledgeMode) throws 
JMSException {
-        try {
-            assertNotNull(session);
-            assertEquals(acknowledgeMode, session.getAcknowledgeMode());
-            assertEquals(acknowledgeMode == Session.SESSION_TRANSACTED, 
session.getTransacted());
-        } finally {
-            if (session != null) {
-                session.close();
-            }
-        }
+    @Test
+    public void testCreateXASession() throws Exception {
+        verifySession(xaConnection.createSession(), 
Session.SESSION_TRANSACTED);
+    }
+
+    @Test
+    public void testCreateXASessionAckModeAuto() throws Exception {
+        verifySession(xaConnection.createSession(Session.AUTO_ACKNOWLEDGE), 
Session.SESSION_TRANSACTED);
+    }
+
+    @Test
+    public void testCreateXASessionAckModeClient() throws Exception {
+        verifySession(xaConnection.createSession(Session.CLIENT_ACKNOWLEDGE), 
Session.SESSION_TRANSACTED);
+    }
+
+    @Test
+    public void testCreateXASessionAckModeDups() throws Exception {
+        verifySession(xaConnection.createSession(Session.DUPS_OK_ACKNOWLEDGE), 
Session.SESSION_TRANSACTED);
     }
 
+    @Test
+    public void testCreateXASessionAckModeTrans() throws Exception {
+        verifySession(xaConnection.createSession(Session.SESSION_TRANSACTED), 
Session.SESSION_TRANSACTED);
+    }
 }
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XAContextTest.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XAContextTest.java
new file mode 100644
index 000000000..33300cf80
--- /dev/null
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XAContextTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.activemq.jms2;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import javax.jms.Destination;
+import javax.jms.JMSContext;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import org.apache.activemq.ActiveMQXAContext;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ActiveMQJMS2XAContextTest extends ActiveMQJMS2XATestBase {
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        // [AMQ-8325] We override ackMode for unit tests. Actual XA features 
is tested elsewhere
+        activemqXAConnectionFactory.setXaAckMode(Session.AUTO_ACKNOWLEDGE);
+    }
+
+    @Test
+    public void testConnectionFactoryCreateXAContext() {
+        try(JMSContext jmsContext = 
activemqXAConnectionFactory.createXAContext()) {
+            assertNotNull(jmsContext);
+            jmsContext.start();
+            
assertTrue(ActiveMQXAContext.class.isAssignableFrom(jmsContext.getClass()));
+            Destination destination = 
jmsContext.createQueue(methodNameDestinationName);
+            sendMessage(jmsContext, destination, "Test-" + 
methodNameDestinationName);
+            recvMessage(jmsContext, destination, "Test-" + 
methodNameDestinationName);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+
+    @Test
+    public void testConnectionFactoryCreateContextUserPass() {
+        try(JMSContext jmsContext = 
activemqXAConnectionFactory.createXAContext(DEFAULT_JMS_USER, 
DEFAULT_JMS_PASS)) {
+            assertNotNull(jmsContext);
+            jmsContext.start();
+            
assertTrue(ActiveMQXAContext.class.isAssignableFrom(jmsContext.getClass()));
+            Destination destination = 
jmsContext.createQueue(methodNameDestinationName);
+            sendMessage(jmsContext, destination, "Test-" + 
methodNameDestinationName);
+            recvMessage(jmsContext, destination, "Test-" + 
methodNameDestinationName);
+        } catch (JMSException e) {
+            fail(e.getMessage());
+        }
+    }
+}
diff --git 
a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XATestBase.java
 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XATestBase.java
new file mode 100644
index 000000000..324d96cce
--- /dev/null
+++ 
b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2XATestBase.java
@@ -0,0 +1,56 @@
+/**
+ * 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.activemq.jms2;
+
+import java.lang.management.ManagementFactory;
+import javax.jms.Session;
+import javax.jms.XAConnection;
+
+import org.apache.activemq.ActiveMQXAConnectionFactory;
+import org.junit.After;
+import org.junit.Before;
+
+public abstract class ActiveMQJMS2XATestBase extends ActiveMQJMS2TestBase {
+
+    protected ActiveMQXAConnectionFactory activemqXAConnectionFactory = null;
+    protected XAConnection xaConnection = null;
+
+    @Before
+    @Override
+    public void setUp() throws Exception {
+        activemqXAConnectionFactory = new 
ActiveMQXAConnectionFactory("vm://localhost?marshal=false&broker.persistent=false");
+        xaConnection = activemqXAConnectionFactory.createXAConnection();
+
+        // [AMQ-8325] Test using standard JMS connection with 
XAConnectionFactory
+        activemqConnectionFactory = activemqXAConnectionFactory;
+        connection = activemqConnectionFactory.createConnection();
+        connection.start();
+        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+        methodNameDestinationName = "AMQ.JMS2." + 
cleanParameterizedMethodName(testName.getMethodName().toUpperCase());
+        messageProducer = 
session.createProducer(session.createQueue(methodNameDestinationName));
+        mbeanServer = ManagementFactory.getPlatformMBeanServer();
+    }
+
+    @After
+    @Override
+    public void tearDown() {
+        super.tearDown();
+        if(xaConnection != null) {
+            try { xaConnection.close(); } catch (Exception e) { } finally { 
xaConnection = null; }
+        }
+    }
+}

Reply via email to