activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [activemq-artemis] branch master updated: ARTEMIS-2339 Set JMS Name on compatible destinations
Date Mon, 20 May 2019 19:48:39 GMT
This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/master by this push:
     new 9c9bd48  ARTEMIS-2339 Set JMS Name on compatible destinations
     new 57cfb5d  This closes #2670
9c9bd48 is described below

commit 9c9bd48154063011a00f5796a0cdda19cc987564
Author: Clebert Suconic <clebertsuconic@apache.org>
AuthorDate: Wed May 15 18:03:15 2019 -0400

    ARTEMIS-2339 Set JMS Name on compatible destinations
---
 .../artemis/jms/client/ActiveMQDestination.java    | 18 +++++++---
 .../artemis/jms/client/ActiveMQSession.java        |  9 +++++
 .../jmsReplyToTempTopic/receiveMessages.groovy     |  3 ++
 .../jmsReplyToTempTopic/sendMessagesAddress.groovy |  2 ++
 .../integration/jms/SimpleJNDIClientTest.java      | 38 +++++++++++++++-------
 5 files changed, 53 insertions(+), 17 deletions(-)

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 0a1b721..3da3a5a 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 5041b57..aea3d45 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 0ab25bf..5c7f300 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 97b9fed..d54cda2 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 a18248e..c9299aa 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();
    }


Mime
View raw message