Repository: activemq-artemis
Updated Branches:
  refs/heads/master 88e9b55d1 -> adc0f02ae


ARTEMIS-1596 wrong routing-type for STOMP autocreated address/queue


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/dffc6649
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/dffc6649
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/dffc6649

Branch: refs/heads/master
Commit: dffc66496e1e22e4ab13d56a52bbf5767ff7f33c
Parents: 88e9b55
Author: jostbg <[email protected]>
Authored: Fri Jan 12 15:52:40 2018 +0100
Committer: Justin Bertram <[email protected]>
Committed: Fri Jan 12 15:12:03 2018 -0600

----------------------------------------------------------------------
 .../core/protocol/stomp/StompConnection.java    | 29 ++++++-------
 .../tests/integration/stomp/StompTest.java      | 45 ++++++++++++++++++++
 2 files changed, 57 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dffc6649/artemis-protocols/artemis-stomp-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/StompConnection.java
----------------------------------------------------------------------
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 6f7181e..4415c95 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 {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dffc6649/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompTest.java
----------------------------------------------------------------------
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 c2d4115..543c112 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));
+   }
 }

Reply via email to