From 750b31e5a6e2c81ce4645b86f97100538be77227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Baptiste=20Onofr=C3=A9?= Date: Sun, 3 Mar 2024 17:53:26 +0100 Subject: [PATCH] AMQ-9419: Implement createContext(int sessionMode) method (cherry picked from commit 7fae1b98e760ba2e35d049d40fa761c5248f5bc1) --- .../apache/activemq/ActiveMQConnectionFactory.java | 6 +++++- .../activemq/jms2/ActiveMQJMS2ContextTest.java | 13 +++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java index 4cbeacb5bd..8c68d5ee65 100644 --- a/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java +++ b/activemq-client/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java @@ -328,7 +328,11 @@ public class ActiveMQConnectionFactory extends JNDIBaseStorable implements Conne */ @Override public JMSContext createContext(int sessionMode) { - throw new UnsupportedOperationException("createContext() is not supported"); + try { + return new ActiveMQContext(createActiveMQConnection(getUserName(), getPassword()), sessionMode); + } catch (JMSException e) { + throw JMSExceptionSupport.convertToJMSRuntimeException(e); + } } /** diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java index 8353fdb907..cf1e0fa594 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/jms2/ActiveMQJMS2ContextTest.java @@ -57,9 +57,18 @@ public class ActiveMQJMS2ContextTest extends ActiveMQJMS2TestBase { } } - @Test(expected = UnsupportedOperationException.class) + @Test public void testConnectionFactoryCreateContextSession() { - activemqConnectionFactory.createContext(Session.AUTO_ACKNOWLEDGE); + try(JMSContext jmsContext = activemqConnectionFactory.createContext(Session.AUTO_ACKNOWLEDGE)) { + assertNotNull(jmsContext); + jmsContext.start(); + assertTrue(ActiveMQContext.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