activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/2] activemq-artemis git commit: ARTEMIS-218 auto-create in cluster
Date Tue, 05 Jan 2016 20:38:58 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 74de4ec98 -> bd6cd0d13


ARTEMIS-218 auto-create in cluster


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

Branch: refs/heads/master
Commit: e899c850e73ddbeb83997afd37efafb2e3b50322
Parents: 74de4ec
Author: jbertram <jbertram@apache.org>
Authored: Mon Jan 4 17:51:46 2016 -0600
Committer: jbertram <jbertram@apache.org>
Committed: Tue Jan 5 14:02:05 2016 -0600

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQSession.java     |  6 +-
 .../jms/cluster/AutoCreateQueueClusterTest.java | 82 ++++++++++++++++++++
 2 files changed, 87 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e899c850/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
index e2a1fca..9d510f5 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
@@ -644,7 +644,11 @@ public class ActiveMQSession implements QueueSession, TopicSession {
          if (dest.isQueue()) {
             AddressQuery response = session.addressQuery(dest.getSimpleAddress());
 
-            if (!response.isExists()) {
+            /* The address query will send back exists=true even if the node only has a REMOTE
binding for the destination.
+             * Therefore, we must check if the queue names list contains the exact name of
the address to know whether or
+             * not a LOCAL binding for the address exists. If no LOCAL binding exists then
it should be created here.
+             */
+            if (!response.isExists() || !response.getQueueNames().contains(dest.getSimpleAddress()))
{
                if (response.isAutoCreateJmsQueues()) {
                   session.createQueue(dest.getSimpleAddress(), dest.getSimpleAddress(), true);
                }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/e899c850/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/cluster/AutoCreateQueueClusterTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/cluster/AutoCreateQueueClusterTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/cluster/AutoCreateQueueClusterTest.java
new file mode 100644
index 0000000..2551890
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/cluster/AutoCreateQueueClusterTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.jms.cluster;
+
+import javax.jms.Connection;
+import javax.jms.DeliveryMode;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.tests.util.JMSClusteredTestBase;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AutoCreateQueueClusterTest extends JMSClusteredTestBase {
+
+   @Override
+   @Before
+   public void setUp() throws Exception {
+      //todo fix if needed
+      super.setUp();
+      jmsServer1.getActiveMQServer().setIdentity("Server 1");
+      jmsServer2.getActiveMQServer().setIdentity("Server 2");
+   }
+
+   @Override
+   protected boolean enablePersistence() {
+      return true;
+   }
+
+   @Test
+   public void testAutoCreate() throws Exception {
+      server1.getAddressSettingsRepository().getMatch("#").setAutoCreateJmsQueues(true).setRedistributionDelay(0);
+      server2.getAddressSettingsRepository().getMatch("#").setAutoCreateJmsQueues(true).setRedistributionDelay(0);
+      Connection conn1 = cf1.createConnection();
+      Connection conn2 = cf2.createConnection();
+      conn1.start();
+      conn2.start();
+
+      try {
+         Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+         MessageProducer prod1 = session1.createProducer(ActiveMQJMSClient.createQueue("myQueue"));
+
+         prod1.setDeliveryMode(DeliveryMode.PERSISTENT);
+
+         prod1.send(session1.createTextMessage("m1"));
+
+         MessageConsumer cons2 = session2.createConsumer(ActiveMQJMSClient.createQueue("myQueue"));
+
+         TextMessage received = (TextMessage) cons2.receive(5000);
+
+         assertNotNull(received);
+
+         assertEquals("m1", received.getText());
+
+         cons2.close();
+      }
+      finally {
+         conn1.close();
+         conn2.close();
+      }
+   }
+}


Mime
View raw message