From dffc66496e1e22e4ab13d56a52bbf5767ff7f33c Mon Sep 17 00:00:00 2001 From: jostbg <35264802+jostbg@users.noreply.github.com> Date: Fri, 12 Jan 2018 15:52:40 +0100 Subject: [PATCH] ARTEMIS-1596 wrong routing-type for STOMP autocreated address/queue --- .../core/protocol/stomp/StompConnection.java | 29 +++++------- .../tests/integration/stomp/StompTest.java | 45 +++++++++++++++++++ 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java index 6f7181e539..4415c952b4 100644 --- a/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java +++ b/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java @@ -260,25 +260,22 @@ public final class StompConnection implements RemotingConnection { } } - public boolean autoCreateDestinationIfPossible(String queue, RoutingType routingType) throws ActiveMQStompException { - boolean result = false; + public void autoCreateDestinationIfPossible(String queue, RoutingType routingType) throws ActiveMQStompException { ServerSession session = getSession().getCoreSession(); try { - if (manager.getServer().getAddressInfo(SimpleString.toSimpleString(queue)) == null) { + SimpleString simpleQueue = SimpleString.toSimpleString(queue); + if (manager.getServer().getAddressInfo(simpleQueue) == null) { AddressSettings addressSettings = manager.getServer().getAddressSettingsRepository().getMatch(queue); - if (routingType != null && routingType == RoutingType.MULTICAST && addressSettings.isAutoCreateAddresses()) { - session.createAddress(SimpleString.toSimpleString(queue), RoutingType.MULTICAST, true); - result = true; - } else { - if (addressSettings.isAutoCreateAddresses()) { - session.createAddress(SimpleString.toSimpleString(queue), RoutingType.ANYCAST, true); - result = true; - } - if (addressSettings.isAutoCreateQueues()) { - session.createQueue(SimpleString.toSimpleString(queue), SimpleString.toSimpleString(queue), RoutingType.ANYCAST, null, false, true, true); - result = true; - } + + RoutingType effectiveAddressRoutingType = routingType == null ? addressSettings.getDefaultAddressRoutingType() : routingType; + if (addressSettings.isAutoCreateAddresses()) { + session.createAddress(simpleQueue, effectiveAddressRoutingType, true); + } + + // only auto create the queue if the address is ANYCAST + if (effectiveAddressRoutingType == RoutingType.ANYCAST && addressSettings.isAutoCreateQueues()) { + session.createQueue(simpleQueue, simpleQueue, routingType == null ? addressSettings.getDefaultQueueRoutingType() : routingType, null, false, true, true); } } } catch (ActiveMQQueueExistsException e) { @@ -286,8 +283,6 @@ public final class StompConnection implements RemotingConnection { } catch (Exception e) { throw new ActiveMQStompException(e.getMessage(), e).setHandler(frameHandler); } - - return result; } public void checkRoutingSemantics(String destination, RoutingType routingType) throws ActiveMQStompException { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java index c2d4115b39..543c112a30 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java @@ -50,7 +50,9 @@ import org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding; import org.apache.activemq.artemis.core.protocol.stomp.Stomp; import org.apache.activemq.artemis.core.protocol.stomp.StompProtocolManagerFactory; import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.server.AddressQueryResult; import org.apache.activemq.artemis.core.server.Queue; +import org.apache.activemq.artemis.core.server.QueueQueryResult; import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; import org.apache.activemq.artemis.core.server.impl.AddressInfo; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; @@ -1665,4 +1667,47 @@ public class StompTest extends StompTestBase { assertTrue(Wait.waitFor(() -> activeMQServer.locateQueue(SimpleString.toSimpleString(queueA)).getMessageCount() + activeMQServer.locateQueue(SimpleString.toSimpleString(queueB)).getMessageCount() == 1, 2000, 100)); assertTrue(Wait.waitFor(() -> activeMQServer.locateQueue(SimpleString.toSimpleString(queueC)).getMessageCount() + activeMQServer.locateQueue(SimpleString.toSimpleString(queueD)).getMessageCount() == 2, 2000, 100)); } + + @Test + public void testAutoCreatedAnycastAddress() throws Exception { + conn.connect(defUser, defPass); + + String queueName = UUID.randomUUID().toString(); + SimpleString simpleQueueName = SimpleString.toSimpleString(queueName); + + ActiveMQServer activeMQServer = server.getActiveMQServer(); + + Assert.assertNull(activeMQServer.getAddressInfo(simpleQueueName)); + Assert.assertNull(activeMQServer.locateQueue(simpleQueueName)); + + activeMQServer.getAddressSettingsRepository().addMatch(queueName, new AddressSettings() + .setDefaultAddressRoutingType(RoutingType.ANYCAST) + .setDefaultQueueRoutingType(RoutingType.ANYCAST) + ); + + send(conn, queueName, null, "Hello ANYCAST"); + + assertTrue("Address and queue should be created now", Wait.waitFor(() -> (activeMQServer.getAddressInfo(simpleQueueName) != null) && (activeMQServer.locateQueue(simpleQueueName) != null), 2000, 200)); + assertTrue(activeMQServer.getAddressInfo(simpleQueueName).getRoutingTypes().contains(RoutingType.ANYCAST)); + assertEquals(RoutingType.ANYCAST, activeMQServer.locateQueue(simpleQueueName).getRoutingType()); + } + + @Test + public void testAutoCreatedMulticastAddress() throws Exception { + conn.connect(defUser, defPass); + + String queueName = UUID.randomUUID().toString(); + SimpleString simpleQueueName = SimpleString.toSimpleString(queueName); + + ActiveMQServer activeMQServer = server.getActiveMQServer(); + + Assert.assertNull(activeMQServer.getAddressInfo(simpleQueueName)); + Assert.assertNull(activeMQServer.locateQueue(simpleQueueName)); + + send(conn, queueName, null, "Hello MULTICAST"); + + assertTrue("Address should be created now", Wait.waitFor(() -> (activeMQServer.getAddressInfo(simpleQueueName) != null), 2000, 200)); + assertTrue(activeMQServer.getAddressInfo(simpleQueueName).getRoutingTypes().contains(RoutingType.MULTICAST)); + Assert.assertNull(activeMQServer.locateQueue(simpleQueueName)); + } }