You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2019/01/24 19:35:25 UTC

[activemq-artemis] branch master updated: ARTEMIS-2238 Fixing QueueQuery on every single send on topics

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 90a6626  ARTEMIS-2238 Fixing QueueQuery on every single send on topics
     new bcd2f1c  This closes #2519
90a6626 is described below

commit 90a66266b67cc1c0ee964d33b5ac3608cda921e8
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Thu Jan 24 13:38:31 2019 -0500

    ARTEMIS-2238 Fixing QueueQuery on every single send on topics
---
 .../jms/client/ActiveMQMessageProducer.java        | 18 +++++++-------
 .../integration/amqp/QueueAutoCreationTest.java    | 28 ++++++++++++++++++++--
 2 files changed, 36 insertions(+), 10 deletions(-)

diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
index 74f39ee..b6c72a7 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessageProducer.java
@@ -423,16 +423,18 @@ public class ActiveMQMessageProducer implements MessageProducer, QueueSender, To
                      throw new InvalidDestinationException("Destination " + address + " does not exist");
                   }
                } else {
-                  ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
-                  if (queueQuery.isExists()) {
-                     connection.addKnownDestination(address);
-                  } else if (destination.isQueue() && query.isAutoCreateQueues()) {
-                     if (destination.isTemporary()) {
-                        session.createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, query);
-                     } else {
-                        session.createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query);
+                  if (destination.isQueue()) {
+                     ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
+                     if (!queueQuery.isExists()) {
+                        if (destination.isTemporary()) {
+                           session.createTemporaryQueue(destination, RoutingType.ANYCAST, address, null, query);
+                        } else {
+                           session.createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query);
+                        }
                      }
                   }
+
+                  connection.addKnownDestination(address);
                }
             } catch (ActiveMQQueueExistsException e) {
                // The queue was created by another client/admin between the query check and send create queue packet
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/QueueAutoCreationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/QueueAutoCreationTest.java
index f6c8b22..5d87f11 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/QueueAutoCreationTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/QueueAutoCreationTest.java
@@ -24,7 +24,9 @@ import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.JournalType;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.jms.client.ActiveMQConnection;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
 import org.apache.activemq.artemis.jms.client.ActiveMQQueue;
+import org.apache.activemq.artemis.jms.client.ActiveMQTopic;
 import org.apache.activemq.artemis.utils.UUIDGenerator;
 import org.junit.After;
 import org.junit.Assert;
@@ -32,6 +34,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
 import javax.jms.DeliveryMode;
 import javax.jms.JMSException;
 import javax.jms.MessageConsumer;
@@ -39,6 +42,7 @@ import javax.jms.MessageProducer;
 import javax.jms.Queue;
 import javax.jms.Session;
 import javax.jms.TextMessage;
+import javax.jms.Topic;
 import java.math.BigInteger;
 import java.util.Map;
 import java.util.Random;
@@ -58,7 +62,7 @@ public class QueueAutoCreationTest extends JMSClientTestSupport {
       String randomSuffix = new BigInteger(130, random).toString(32);
       testConn = (ActiveMQConnection)createCoreConnection();
       clientSession = testConn.getSessionFactory().createSession();
-      queue1 = createQueue("queue1_" + randomSuffix);
+      queue1 = createAddressOnlyAndFakeQueue("queue1_" + randomSuffix);
    }
 
    @Override
@@ -89,7 +93,7 @@ public class QueueAutoCreationTest extends JMSClientTestSupport {
    }
 
 
-   protected Queue createQueue(final String queueName) throws Exception {
+   protected Queue createAddressOnlyAndFakeQueue(final String queueName) throws Exception {
       SimpleString address = SimpleString.toSimpleString(queueName);
       clientSession.createAddress(address, RoutingType.ANYCAST, false);
       return new ActiveMQQueue(queueName);
@@ -109,6 +113,26 @@ public class QueueAutoCreationTest extends JMSClientTestSupport {
       sendStringOfSize(1024 * 1024, true);
    }
 
+
+   @Test(timeout = 30000)
+   // QueueAutoCreationTest was created to validate auto-creation of queues
+   // and this test was added to validate a regression: https://issues.apache.org/jira/browse/ARTEMIS-2238
+   public void testAutoCreateOnTopic() throws Exception {
+      ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:5672");
+      Connection connection = factory.createConnection();
+      SimpleString addressName = UUIDGenerator.getInstance().generateSimpleStringUUID();
+      System.out.println("Address is " + addressName);
+      clientSession.createAddress(addressName, RoutingType.ANYCAST, false);
+      Topic topic = new ActiveMQTopic(addressName.toString());
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      MessageProducer producer = session.createProducer(topic);
+      for (int i = 0; i < 10; i++) {
+         producer.send(session.createTextMessage("hello"));
+      }
+
+      Assert.assertTrue(((ActiveMQConnection)connection).containsKnownDestination(addressName));
+   }
+
    private void sendStringOfSize(int msgSize, boolean useCoreReceive) throws JMSException {
 
       Connection conn = this.createConnection();