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 2021/08/06 16:08:52 UTC

[activemq-artemis] branch main updated: ARTEMIS-3417 AutoDelete false by default on the created broker.xml

This is an automated email from the ASF dual-hosted git repository.

clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git


The following commit(s) were added to refs/heads/main by this push:
     new 8442c9b  ARTEMIS-3417 AutoDelete false by default on the created broker.xml
8442c9b is described below

commit 8442c9b9d600827000f4ffaeb641f2c9ab0780aa
Author: Clebert Suconic <cl...@apache.org>
AuthorDate: Fri Aug 6 10:39:56 2021 -0400

    ARTEMIS-3417 AutoDelete false by default on the created broker.xml
---
 .../activemq/artemis/cli/commands/Create.java      | 13 +++++
 .../activemq/artemis/cli/commands/etc/broker.xml   |  2 +
 .../org/apache/activemq/cli/test/ArtemisTest.java  | 60 +++++++++++++++++++++-
 3 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
index da0ed7c..0207344 100644
--- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
+++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java
@@ -223,6 +223,9 @@ public class Create extends InputAbstract {
    @Option(name = "--autocreate", description = "Auto create addresses. (default: true)")
    private Boolean autoCreate;
 
+   @Option(name = "--autodelete", description = "If set, the default broker.xml will allow auto deletion of queues and addresses")
+   private boolean autoDelete;
+
    @Option(name = "--user", description = "The username (Default: input)")
    private String user;
 
@@ -429,6 +432,15 @@ public class Create extends InputAbstract {
       this.etc = etc;
    }
 
+   public boolean isAutoDelete() {
+      return autoDelete;
+   }
+
+   public Create setAutoDelete(boolean autoDelete) {
+      this.autoDelete = autoDelete;
+      return this;
+   }
+
    private String getClusterUser() {
       if (clusterUser == null) {
          clusterUser = input("--cluster-user", "Please provide the username:", "cluster-admin");
@@ -819,6 +831,7 @@ public class Create extends InputAbstract {
 
 
       filters.put("${auto-create}", isAutoCreate() ? "true" : "false");
+      filters.put("${auto-delete}", autoDelete ? "true" : "false");
 
       if (jdbc) {
          noAutoTune = true;
diff --git a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml
index 78a9fd1..7550879 100644
--- a/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml
+++ b/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/etc/broker.xml
@@ -151,6 +151,8 @@ ${cluster-security.settings}${cluster.settings}${replicated.settings}${shared-st
             <auto-create-addresses>${auto-create}</auto-create-addresses>
             <auto-create-jms-queues>${auto-create}</auto-create-jms-queues>
             <auto-create-jms-topics>${auto-create}</auto-create-jms-topics>
+            <auto-delete-queues>${auto-delete}</auto-delete-queues>
+            <auto-delete-addresses>${auto-delete}</auto-delete-addresses>
          </address-setting>
       </address-settings>
 
diff --git a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
index 325e83c..cfd63a8 100644
--- a/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
+++ b/artemis-cli/src/test/java/org/apache/activemq/cli/test/ArtemisTest.java
@@ -21,6 +21,7 @@ import javax.jms.JMSException;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
 import javax.jms.MessageProducer;
+import javax.jms.Queue;
 import javax.jms.Session;
 import javax.jms.TextMessage;
 import javax.json.JsonArray;
@@ -83,6 +84,7 @@ import org.apache.activemq.artemis.nativo.jlibaio.LibaioContext;
 import org.apache.activemq.artemis.utils.DefaultSensitiveStringCodec;
 import org.apache.activemq.artemis.utils.HashProcessor;
 import org.apache.activemq.artemis.utils.PasswordMaskingUtil;
+import org.apache.activemq.artemis.utils.RandomUtil;
 import org.apache.activemq.artemis.utils.SensitiveDataCodec;
 import org.apache.activemq.artemis.utils.StringUtil;
 import org.apache.activemq.artemis.utils.Wait;
@@ -749,7 +751,6 @@ public class ArtemisTest extends CliTestBase {
 
       File userFile = new File(instance1.getAbsolutePath() + "/etc/artemis-users.properties");
       userFile.delete();
-      //      File roleFile = new File(instance1.getAbsolutePath() + "/etc/artemis-roles.properties");
 
       try {
          activeMQServerControl.listUser("");
@@ -1326,6 +1327,63 @@ public class ArtemisTest extends CliTestBase {
       }
    }
 
+   @Test
+   public void testAutoDeleteTrue() throws Exception {
+      testAutoDelete(true);
+   }
+
+   @Test
+   public void testAutoDeleteFalse() throws Exception {
+      testAutoDelete(false);
+   }
+
+   private void testAutoDelete(boolean autoDelete) throws Exception {
+
+      File instanceFolder = temporaryFolder.newFolder("autocreate" + autoDelete);
+      setupAuth(instanceFolder);
+
+      // This is usually set when run from the command line via artemis.profile
+      Run.setEmbedded(true);
+      if (autoDelete) {
+         Artemis.main("create", instanceFolder.getAbsolutePath(), "--force", "--silent",  "--no-web", "--no-autotune",  "--require-login", "--autodelete");
+      } else {
+         Artemis.main("create", instanceFolder.getAbsolutePath(), "--force", "--silent", "--no-web",  "--require-login", "--no-autotune");
+      }
+      System.setProperty("artemis.instance", instanceFolder.getAbsolutePath());
+
+
+      try {
+         // Some exceptions may happen on the initialization, but they should be ok on start the basic core protocol
+         Pair<ManagementContext, ActiveMQServer> run = (Pair<ManagementContext, ActiveMQServer>) Artemis.internalExecute("run");
+
+         String queueName = "testAutoDelete" + RandomUtil.randomPositiveInt();
+
+         ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory();
+         try (Connection connection = factory.createConnection("admin", "admin")) {
+            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+            Queue queue = session.createQueue(queueName);
+            MessageProducer producer = session.createProducer(queue);
+            producer.send(session.createTextMessage("hi"));
+
+            Wait.assertTrue(() -> run.getB().locateQueue(queueName) != null);
+            connection.start();
+            MessageConsumer consumer = session.createConsumer(queue);
+            Assert.assertNotNull(consumer.receive(5000));
+         }
+
+         if (autoDelete) {
+            Wait.assertTrue(() -> run.getB().locateQueue(queueName) == null);
+         } else {
+            // Things are async, allowing some time to make sure it would eventually fail
+            Thread.sleep(500);
+            Assert.assertNotNull(run.getB().locateQueue(queueName));
+         }
+      } finally {
+         stopServer();
+      }
+   }
+
+
 
    @Test
    public void testPing() throws Exception {