Skip to content

Commit

Permalink
ARTEMIS-2238 Fixing QueueQuery on every single send on topics
Browse files Browse the repository at this point in the history
(cherry picked from commit 90a6626)
  • Loading branch information
clebertsuconic committed Jan 24, 2019
1 parent 7e1f83c commit 7a139a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
Expand Up @@ -421,16 +421,17 @@ private void doSendx(ActiveMQDestination destination,
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.isQueue()) {ClientSession.QueueQuery queueQuery = clientSession.queueQuery(address);
if (!queueQuery.isExists()) {

if (destination.isTemporary()) {
clientSession.createTemporaryQueue(address, RoutingType.ANYCAST, address);
} else {
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());
createQueue(destination, RoutingType.ANYCAST, address, null, true, true, query.getDefaultMaxConsumers(), query.isDefaultPurgeOnNoConsumers(), query.isDefaultExclusive(), query.isDefaultLastValueQueue());}
}
}

connection.addKnownDestination(address);
}
} catch (ActiveMQQueueExistsException e) {
// The queue was created by another client/admin between the query check and send create queue packet
Expand Down
Expand Up @@ -24,21 +24,25 @@
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;
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;
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;
Expand All @@ -58,7 +62,7 @@ public void setUp() throws Exception {
String randomSuffix = new BigInteger(130, random).toString(32);
testConn = (ActiveMQConnection)createCoreConnection();
clientSession = testConn.getSessionFactory().createSession();
queue1 = createQueue("queue1_" + randomSuffix);
queue1 = createAddressOnlyAndFakeQueue("queue1_" + randomSuffix);
}

@Override
Expand Down Expand Up @@ -89,7 +93,7 @@ protected void configureAddressPolicy(ActiveMQServer server) {
}


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);
Expand All @@ -109,6 +113,26 @@ public void testHugeString() throws Exception {
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();
Expand Down

0 comments on commit 7a139a4

Please sign in to comment.