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 2016/12/13 00:39:27 UTC

[1/2] activemq-artemis git commit: ARTEMIS-789 add tests; fix bugs from tests

Repository: activemq-artemis
Updated Branches:
  refs/heads/master f28578520 -> 52e4fc4a5


ARTEMIS-789 add tests; fix bugs from tests

Add some routing and createQueue tests to deal with new semantics.
Also fix a few bugs exposed by the new tests.


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

Branch: refs/heads/master
Commit: 02f5f5c01dd8863e77acebe80dee5d53a106ca59
Parents: f285785
Author: jbertram <jb...@apache.org>
Authored: Mon Dec 12 16:40:20 2016 -0600
Committer: jbertram <jb...@apache.org>
Committed: Mon Dec 12 17:01:52 2016 -0600

----------------------------------------------------------------------
 .../ActiveMQAddressDoesNotExistException.java   |   4 +-
 .../core/server/ActiveMQMessageBundle.java      |   2 +-
 .../core/server/impl/ActiveMQServerImpl.java    |  17 +--
 .../core/server/impl/ServerSessionImpl.java     |   2 +-
 .../integration/client/CreateQueueTest.java     | 107 +++++++++++++++++++
 .../tests/integration/client/RoutingTest.java   |  64 +++++++++++
 6 files changed, 177 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/02f5f5c0/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQAddressDoesNotExistException.java
----------------------------------------------------------------------
diff --git a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQAddressDoesNotExistException.java b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQAddressDoesNotExistException.java
index 46a82b5..5e8a801 100644
--- a/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQAddressDoesNotExistException.java
+++ b/artemis-commons/src/main/java/org/apache/activemq/artemis/api/core/ActiveMQAddressDoesNotExistException.java
@@ -22,10 +22,10 @@ package org.apache.activemq.artemis.api.core;
 public final class ActiveMQAddressDoesNotExistException extends ActiveMQException {
 
    public ActiveMQAddressDoesNotExistException() {
-      super(ActiveMQExceptionType.ADDRESS_EXISTS);
+      super(ActiveMQExceptionType.ADDRESS_DOES_NOT_EXIST);
    }
 
    public ActiveMQAddressDoesNotExistException(String msg) {
-      super(ActiveMQExceptionType.ADDRESS_EXISTS, msg);
+      super(ActiveMQExceptionType.ADDRESS_DOES_NOT_EXIST, msg);
    }
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/02f5f5c0/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
index 5f533ff..1bc1441 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQMessageBundle.java
@@ -406,7 +406,7 @@ public interface ActiveMQMessageBundle {
    @Message(id = 119206, value = "Queue {0} has invalid max consumer setting: {1}", format = Message.Format.MESSAGE_FORMAT)
    IllegalArgumentException invalidMaxConsumers(String queueName, int value);
 
-   @Message(id = 119207, value = "Can not create queue with delivery mode: {0}, Supported delivery modes for address: {1} are {2}", format = Message.Format.MESSAGE_FORMAT)
+   @Message(id = 119207, value = "Can not create queue with routing type: {0}, Supported routing types for address: {1} are {2}", format = Message.Format.MESSAGE_FORMAT)
    IllegalArgumentException invalidRoutingTypeForAddress(RoutingType routingType,
                                                          String address,
                                                          Set<RoutingType> supportedRoutingTypes);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/02f5f5c0/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index ed8c3d8..097118f 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -2512,30 +2512,20 @@ public class ActiveMQServerImpl implements ActiveMQServer {
       defaultAddressInfo.addRoutingType(routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType);
       AddressInfo info = postOffice.getAddressInfo(addressName);
 
-      boolean addressAlreadyExists = true;
-
       if (autoCreateAddress) {
          if (info == null || !info.getRoutingTypes().contains(routingType)) {
             createOrUpdateAddressInfo(defaultAddressInfo.setAutoCreated(true));
-            addressAlreadyExists = false;
          }
       } else if (info == null) {
          throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressName);
+      } else if (!info.getRoutingTypes().contains(routingType)) {
+         throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(routingType, info.getName().toString(), info.getRoutingTypes());
       }
 
       final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(routingType).maxConsumers(maxConsumers).deleteOnNoConsumers(deleteOnNoConsumers).build();
 
       final Queue queue = queueFactory.createQueueWith(queueConfig);
 
-      AddressInfo addressInfo = postOffice.getAddressInfo(queue.getAddress());
-      if (addressInfo == null) {
-         createAddressInfo(new AddressInfo(queue.getAddress()));
-      } else {
-         if (!addressInfo.getRoutingTypes().contains(routingType)) {
-            throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(routingType, addressInfo.getName().toString(), addressInfo.getRoutingTypes());
-         }
-      }
-
       if (transientQueue) {
          queue.setConsumersRefCount(new TransientQueueManagerImpl(this, queue.getName()));
       } else if (queue.isAutoCreated()) {
@@ -2546,9 +2536,6 @@ public class ActiveMQServerImpl implements ActiveMQServer {
 
       if (queue.isDurable()) {
          storageManager.addQueueBinding(txID, localQueueBinding);
-         if (!addressAlreadyExists) {
-            storageManager.addAddressBinding(txID, getAddressInfo(queue.getAddress()));
-         }
       }
 
       try {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/02f5f5c0/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
index 1922578..e80bdc0 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java
@@ -540,7 +540,7 @@ public class ServerSessionImpl implements ServerSession, FailureListener {
 
       server.checkQueueCreationLimit(getUsername());
 
-      Queue queue = server.createQueue(art.getA(), art.getB(), name, filterString, SimpleString.toSimpleString(getUsername()), durable, temporary, autoCreated, maxConsumers, deleteOnNoConsumers, true);
+      Queue queue = server.createQueue(art.getA(), art.getB(), name, filterString, SimpleString.toSimpleString(getUsername()), durable, temporary, autoCreated, maxConsumers, deleteOnNoConsumers, server.getAddressSettingsRepository().getMatch(address.toString()).isAutoCreateAddresses());
 
       if (temporary) {
          // Temporary queue in core simply means the queue will be deleted if

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/02f5f5c0/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java
new file mode 100644
index 0000000..9ec9a00
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/CreateQueueTest.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.client;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.activemq.artemis.api.core.ActiveMQException;
+import org.apache.activemq.artemis.api.core.ActiveMQExceptionType;
+import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.api.core.client.ClientSession;
+import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
+import org.apache.activemq.artemis.api.core.client.ServerLocator;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.RoutingType;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
+import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CreateQueueTest extends ActiveMQTestBase {
+
+   public final SimpleString addressA = new SimpleString("addressA");
+   public final SimpleString addressB = new SimpleString("addressB");
+   public final SimpleString queueA = new SimpleString("queueA");
+   public final SimpleString queueB = new SimpleString("queueB");
+   public final SimpleString queueC = new SimpleString("queueC");
+   public final SimpleString queueD = new SimpleString("queueD");
+
+   private ServerLocator locator;
+   private ActiveMQServer server;
+   private ClientSessionFactory cf;
+
+   @Override
+   @Before
+   public void setUp() throws Exception {
+      super.setUp();
+      locator = createInVMNonHALocator();
+      server = createServer(false);
+
+      server.start();
+      cf = createSessionFactory(locator);
+   }
+
+   @Test
+   public void testUnsupportedRoutingType() throws Exception {
+      ClientSession sendSession = cf.createSession(false, true, true);
+      server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
+      server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false));
+
+      Set<RoutingType> routingTypes = new HashSet<>();
+      routingTypes.add(RoutingType.ANYCAST);
+      sendSession.createAddress(addressA, routingTypes, false);
+      try {
+         sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
+         fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
+      } catch (Exception e) {
+         assertTrue(e instanceof ActiveMQException);
+         ActiveMQException ae = (ActiveMQException) e;
+         assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
+      }
+
+      routingTypes = new HashSet<>();
+      routingTypes.add(RoutingType.MULTICAST);
+      sendSession.createAddress(addressB, routingTypes, false);
+      try {
+         sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB);
+         fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
+      } catch (Exception e) {
+         assertTrue(e instanceof ActiveMQException);
+         ActiveMQException ae = (ActiveMQException) e;
+         assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
+      }
+      sendSession.close();
+   }
+
+   @Test
+   public void testAddressDoesNotExist() throws Exception {
+      ClientSession sendSession = cf.createSession(false, true, true);
+      server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
+      Set<RoutingType> routingTypes = new HashSet<>();
+      routingTypes.add(RoutingType.ANYCAST);
+      try {
+         sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
+         fail("Creating a queue here should fail since the queue's address doesn't exist and auto-create-addresses = false.");
+      } catch (Exception e) {
+         assertTrue(e instanceof ActiveMQException);
+         ActiveMQException ae = (ActiveMQException) e;
+         assertEquals(ActiveMQExceptionType.ADDRESS_DOES_NOT_EXIST, ae.getType());
+      }
+      sendSession.close();
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/02f5f5c0/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java
index cc6d95d..b1cbfd2 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RoutingTest.java
@@ -16,6 +16,10 @@
  */
 package org.apache.activemq.artemis.tests.integration.client;
 
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.activemq.artemis.api.core.Message;
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.core.client.ClientConsumer;
 import org.apache.activemq.artemis.api.core.client.ClientMessage;
@@ -24,6 +28,7 @@ import org.apache.activemq.artemis.api.core.client.ClientSession;
 import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
 import org.apache.activemq.artemis.api.core.client.ServerLocator;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.RoutingType;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.junit.Assert;
 import org.junit.Before;
@@ -32,9 +37,11 @@ import org.junit.Test;
 public class RoutingTest extends ActiveMQTestBase {
 
    public final SimpleString addressA = new SimpleString("addressA");
+   public final SimpleString addressB = new SimpleString("addressB");
    public final SimpleString queueA = new SimpleString("queueA");
    public final SimpleString queueB = new SimpleString("queueB");
    public final SimpleString queueC = new SimpleString("queueC");
+   public final SimpleString queueD = new SimpleString("queueD");
 
    private ServerLocator locator;
    private ActiveMQServer server;
@@ -216,4 +223,61 @@ public class RoutingTest extends ActiveMQTestBase {
       sendSession.close();
       session.close();
    }
+
+   @Test
+   public void testAnycastMessageRoutingExclusivity() throws Exception {
+      ClientSession sendSession = cf.createSession(false, true, true);
+      Set<RoutingType> routingTypes = new HashSet<>();
+      routingTypes.add(RoutingType.ANYCAST);
+      routingTypes.add(RoutingType.MULTICAST);
+      sendSession.createAddress(addressA, routingTypes, false);
+      sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
+      sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);
+      sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC);
+      ClientProducer p = sendSession.createProducer(addressA);
+      ClientMessage message = sendSession.createMessage(false);
+      message.putByteProperty(Message.HDR_ROUTING_TYPE, RoutingType.ANYCAST.getType());
+      p.send(message);
+      sendSession.close();
+      assertEquals(1, server.locateQueue(queueA).getMessageCount() + server.locateQueue(queueB).getMessageCount());
+      assertEquals(0, server.locateQueue(queueC).getMessageCount());
+   }
+
+   @Test
+   public void testMulticastMessageRoutingExclusivity() throws Exception {
+      ClientSession sendSession = cf.createSession(false, true, true);
+      Set<RoutingType> routingTypes = new HashSet<>();
+      routingTypes.add(RoutingType.ANYCAST);
+      routingTypes.add(RoutingType.MULTICAST);
+      sendSession.createAddress(addressA, routingTypes, false);
+      sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
+      sendSession.createQueue(addressA, RoutingType.MULTICAST, queueB);
+      sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC);
+      ClientProducer p = sendSession.createProducer(addressA);
+      ClientMessage message = sendSession.createMessage(false);
+      message.putByteProperty(Message.HDR_ROUTING_TYPE, RoutingType.MULTICAST.getType());
+      p.send(message);
+      sendSession.close();
+      assertEquals(0, server.locateQueue(queueA).getMessageCount());
+      assertEquals(2, server.locateQueue(queueB).getMessageCount() + server.locateQueue(queueC).getMessageCount());
+   }
+
+   @Test
+   public void testAmbiguousMessageRouting() throws Exception {
+      ClientSession sendSession = cf.createSession(false, true, true);
+      Set<RoutingType> routingTypes = new HashSet<>();
+      routingTypes.add(RoutingType.ANYCAST);
+      routingTypes.add(RoutingType.MULTICAST);
+      sendSession.createAddress(addressA, routingTypes, false);
+      sendSession.createQueue(addressA, RoutingType.ANYCAST, queueA);
+      sendSession.createQueue(addressA, RoutingType.ANYCAST, queueB);
+      sendSession.createQueue(addressA, RoutingType.MULTICAST, queueC);
+      sendSession.createQueue(addressA, RoutingType.MULTICAST, queueD);
+      ClientProducer p = sendSession.createProducer(addressA);
+      ClientMessage message = sendSession.createMessage(false);
+      p.send(message);
+      sendSession.close();
+      assertEquals(1, server.locateQueue(queueA).getMessageCount() + server.locateQueue(queueB).getMessageCount());
+      assertEquals(2, server.locateQueue(queueC).getMessageCount() + server.locateQueue(queueD).getMessageCount());
+   }
 }


[2/2] activemq-artemis git commit: This closes #909

Posted by cl...@apache.org.
This closes #909


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

Branch: refs/heads/master
Commit: 52e4fc4a53440ec93f6f425a0929d21998706568
Parents: f285785 02f5f5c
Author: Clebert Suconic <cl...@apache.org>
Authored: Mon Dec 12 19:39:21 2016 -0500
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Dec 12 19:39:21 2016 -0500

----------------------------------------------------------------------
 .../ActiveMQAddressDoesNotExistException.java   |   4 +-
 .../core/server/ActiveMQMessageBundle.java      |   2 +-
 .../core/server/impl/ActiveMQServerImpl.java    |  17 +--
 .../core/server/impl/ServerSessionImpl.java     |   2 +-
 .../integration/client/CreateQueueTest.java     | 107 +++++++++++++++++++
 .../tests/integration/client/RoutingTest.java   |  64 +++++++++++
 6 files changed, 177 insertions(+), 19 deletions(-)
----------------------------------------------------------------------