activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [07/43] activemq-artemis git commit: ARTEMIS-395 auto-delete only if setting is true
Date Tue, 09 Feb 2016 20:20:26 GMT
ARTEMIS-395 auto-delete only if setting is true


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

Branch: refs/heads/refactor-openwire
Commit: dffe93152bbf71d923c8386b5c9765a480c488f4
Parents: 37addea
Author: jbertram <jbertram@apache.org>
Authored: Tue Feb 9 09:16:38 2016 -0600
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Tue Feb 9 14:24:51 2016 -0500

----------------------------------------------------------------------
 .../impl/AutoCreatedQueueManagerImpl.java       |  7 +--
 .../client/AutoDeleteJmsQueueTest.java          | 46 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dffe9315/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java
index b6b5508..b57ae47 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AutoCreatedQueueManagerImpl.java
@@ -36,16 +36,17 @@ public class AutoCreatedQueueManagerImpl implements AutoCreatedQueueManager
{
             Queue queue = server.locateQueue(queueName);
             long consumerCount = queue.getConsumerCount();
             long messageCount = queue.getMessageCount();
+            boolean isAutoDeleteJmsQueues = server.getAddressSettingsRepository().getMatch(queueName.toString()).isAutoDeleteJmsQueues();
 
-            if (server.locateQueue(queueName).getMessageCount() == 0) {
+            if (server.locateQueue(queueName).getMessageCount() == 0 && isAutoDeleteJmsQueues)
{
                if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
-                  ActiveMQServerLogger.LOGGER.debug("deleting auto-created queue \"" + queueName
+ "\" because consumerCount = " + consumerCount + " and messageCount = " + messageCount);
+                  ActiveMQServerLogger.LOGGER.debug("deleting auto-created queue \"" + queueName
+ ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteJmsQueues
= " + isAutoDeleteJmsQueues);
                }
 
                server.destroyQueue(queueName, null, false);
             }
             else if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
-               ActiveMQServerLogger.LOGGER.debug("NOT deleting auto-created queue \"" + queueName
+ "\" because consumerCount = " + consumerCount + " and messageCount = " + messageCount);
+               ActiveMQServerLogger.LOGGER.debug("NOT deleting auto-created queue \"" + queueName
+ ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteJmsQueues
= " + isAutoDeleteJmsQueues);
             }
          }
          catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/dffe9315/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteJmsQueueTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteJmsQueueTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteJmsQueueTest.java
index 018667e..b120b29 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteJmsQueueTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/AutoDeleteJmsQueueTest.java
@@ -25,6 +25,7 @@ import javax.jms.TextMessage;
 
 import org.apache.activemq.artemis.api.core.SimpleString;
 import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.tests.util.JMSTestBase;
 import org.apache.activemq.artemis.core.server.Queue;
 import org.junit.Assert;
@@ -75,4 +76,49 @@ public class AutoDeleteJmsQueueTest extends JMSTestBase {
       // ensure the queue was removed
       Assert.assertNull(server.getPostOffice().getBinding(new SimpleString("jms.queue.test")));
    }
+
+   @Test
+   public void testAutoDeleteNegative() throws Exception {
+      server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoDeleteJmsQueues(false));
+      Connection connection = cf.createConnection();
+      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      javax.jms.Queue queue = ActiveMQJMSClient.createQueue("test");
+
+      MessageProducer producer = session.createProducer(queue);
+
+      final int numMessages = 100;
+
+      for (int i = 0; i < numMessages; i++) {
+         TextMessage mess = session.createTextMessage("msg" + i);
+         producer.send(mess);
+      }
+
+      producer.close();
+
+      MessageConsumer messageConsumer = session.createConsumer(queue);
+      connection.start();
+
+      for (int i = 0; i < numMessages - 1; i++) {
+         Message m = messageConsumer.receive(5000);
+         Assert.assertNotNull(m);
+      }
+
+      session.close();
+
+      // ensure the queue is still there
+      Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString("jms.queue.test")).getBindable();
+      Assert.assertEquals(1, q.getMessageCount());
+      Assert.assertEquals(numMessages, q.getMessagesAdded());
+
+      session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+      messageConsumer = session.createConsumer(queue);
+      Message m = messageConsumer.receive(5000);
+      Assert.assertNotNull(m);
+
+      connection.close();
+
+      // ensure the queue was not removed
+      Assert.assertNotNull(server.getPostOffice().getBinding(new SimpleString("jms.queue.test")));
+   }
 }


Mime
View raw message