From 90a66266b67cc1c0ee964d33b5ac3608cda921e8 Mon Sep 17 00:00:00 2001 From: Clebert Suconic Date: Thu, 24 Jan 2019 13:38:31 -0500 Subject: [PATCH] ARTEMIS-2238 Fixing QueueQuery on every single send on topics --- .../jms/client/ActiveMQMessageProducer.java | 18 ++++++------ .../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 74f39eed8c..b6c72a7e36 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 f6c8b22152..5d87f11d4f 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();