diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java index 0a1b721361..3da3a5aac0 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java @@ -55,7 +55,9 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se return input.replace("\\", "\\\\").replace(".", "\\."); } - protected void setName(String name) { + /** createQueue and createTopic from {@link ActiveMQSession} may change the name + * in case Prefix usage */ + void setName(String name) { this.name = name; } @@ -297,15 +299,21 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se } public static ActiveMQTemporaryQueue createTemporaryQueue(final ActiveMQSession session, final String prefix) { - String address = prefix + UUID.randomUUID().toString(); + String name = UUID.randomUUID().toString(); + String address = prefix + name; - return createTemporaryQueue(address, session); + ActiveMQTemporaryQueue queue = createTemporaryQueue(address, session); + queue.setName(name); + return queue; } public static ActiveMQTemporaryTopic createTemporaryTopic(final ActiveMQSession session, final String prefix) { - String address = prefix + UUID.randomUUID().toString(); + String name = UUID.randomUUID().toString(); + String address = prefix + name; - return createTemporaryTopic(address, session); + ActiveMQTemporaryTopic topic = createTemporaryTopic(address, session); + topic.setName(name); + return topic; } public static ActiveMQTemporaryTopic createTemporaryTopic(String address, final ActiveMQSession session) { diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java index 5041b575ec..aea3d455ba 100644 --- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java +++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java @@ -1296,6 +1296,10 @@ public class ActiveMQSession implements QueueSession, TopicSession { queue = ActiveMQDestination.createQueue(queueNameToUse); } + if (queueName != queueNameToUse) { + queue.setName(queueName); + } + QueueQuery response = session.queueQuery(queue.getSimpleAddress()); if (!response.isExists() && !response.isAutoCreateQueues()) { @@ -1319,6 +1323,11 @@ public class ActiveMQSession implements QueueSession, TopicSession { topic = ActiveMQDestination.createTopic(topicNameToUse); } + if (topicNameToUse != topicName) { + topic.setName(topicName); + } + + AddressQuery query = session.addressQuery(topic.getSimpleAddress()); if (!query.isExists() && !query.isAutoCreateAddresses()) { diff --git a/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/receiveMessages.groovy b/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/receiveMessages.groovy index 0ab25bf2a7..5c7f300160 100644 --- a/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/receiveMessages.groovy +++ b/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/receiveMessages.groovy @@ -31,6 +31,9 @@ try { Connection connection = cf.createConnection(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue myQueue = session.createQueue("myQueue"); + +GroovyRun.assertEquals("myQueue", myQueue.getQueueName()); + MessageConsumer queueConsumer = session.createConsumer(myQueue); consumerCreated.countDown(); connection.start() diff --git a/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/sendMessagesAddress.groovy b/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/sendMessagesAddress.groovy index 97b9fedbf0..d54cda2a07 100644 --- a/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/sendMessagesAddress.groovy +++ b/tests/compatibility-tests/src/main/resources/jmsReplyToTempTopic/sendMessagesAddress.groovy @@ -34,6 +34,8 @@ connection.start(); Queue myQueue = session.createQueue("myQueue"); +GroovyRun.assertEquals("myQueue", myQueue.getQueueName()); + System.out.println("myQueue::" + myQueue); TemporaryTopic replyTopic = session.createTemporaryTopic(); MessageConsumer consumer = session.createConsumer(replyTopic); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java index a18248e26e..c9299aabcd 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/SimpleJNDIClientTest.java @@ -55,6 +55,7 @@ import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.server.ActiveMQServer; import org.apache.activemq.artemis.core.server.ActiveMQServers; import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.artemis.jms.client.ActiveMQDestination; import org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory; import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; @@ -679,10 +680,17 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(); - assertTrue(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); - assertTrue(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); - assertTrue(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); - assertTrue(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); + assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX)); + assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX)); + assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX)); + assertTrue(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX)); + + // The name should not include the prefix + assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); + assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); + assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); + assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); + connection.close(); @@ -692,10 +700,16 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { connection = connectionFactory.createConnection(); session = connection.createSession(); - assertTrue(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); - assertTrue(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); - assertTrue(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); - assertTrue(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); + assertTrue(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX)); + assertTrue(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX)); + assertTrue(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX)); + assertTrue(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX)); + + // The name should not include the prefix + assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); + assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); + assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); + assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); connection.close(); } @@ -712,10 +726,10 @@ public class SimpleJNDIClientTest extends ActiveMQTestBase { Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(); - assertFalse(session.createQueue("testQueue").getQueueName().startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())); - assertFalse(session.createTemporaryQueue().getQueueName().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())); - assertFalse(session.createTopic("testTopic").getTopicName().startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())); - assertFalse(session.createTemporaryTopic().getTopicName().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())); + assertFalse(((ActiveMQDestination)session.createQueue("testQueue")).getSimpleAddress().startsWith(PacketImpl.OLD_QUEUE_PREFIX)); + assertFalse(((ActiveMQDestination)session.createTemporaryQueue()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX)); + assertFalse(((ActiveMQDestination)session.createTopic("testTopic")).getSimpleAddress().startsWith(PacketImpl.OLD_TOPIC_PREFIX)); + assertFalse(((ActiveMQDestination)session.createTemporaryTopic()).getSimpleAddress().startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX)); connection.close(); }