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

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


The following commit(s) were added to refs/heads/master by this push:
     new 39b3dd1  ARTEMIS-2781 Adding getAllQueueNames; fixing tests
     new 30f1329  This closes #3152
39b3dd1 is described below

commit 39b3dd1044138ea2a516b67fc6452f57358ea14d
Author: Clebert Suconic <[email protected]>
AuthorDate: Thu May 28 09:19:53 2020 -0400

    ARTEMIS-2781 Adding getAllQueueNames; fixing tests
---
 .../api/core/management/AddressControl.java        | 10 ++++--
 .../jms/server/impl/JMSServerManagerImpl.java      |  4 +--
 .../core/management/impl/AddressControlImpl.java   | 19 +++++++++---
 .../server/management/TopicControlClusterTest.java | 14 ++++++---
 .../integration/management/AddressControlTest.java | 36 +++++++++++++++++++++-
 .../management/AddressControlUsingCoreTest.java    |  5 +++
 6 files changed, 74 insertions(+), 14 deletions(-)

diff --git 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
index d8a2bae..908fb20 100644
--- 
a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
+++ 
b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/AddressControl.java
@@ -72,18 +72,24 @@ public interface AddressControl {
    long getNumberOfMessages() throws Exception;
 
    /**
-    * Returns the names of the queues bound to this address.
+    * Returns the names of the remote queue(s) bound to this address.
     */
    @Attribute(desc = "names of the remote queue(s) bound to this address")
    String[] getRemoteQueueNames() throws Exception;
 
    /**
-    * Returns the names of the queues bound to this address.
+    * Returns the names of the local queue(s) bound to this address.
     */
    @Attribute(desc = "names of the local queue(s) bound to this address")
    String[] getQueueNames() throws Exception;
 
    /**
+    * Returns the names of both the local & remote queue(s) bound to this 
address.
+    */
+   @Attribute(desc = "names of both the local & remote queue(s) bound to this 
address")
+   String[] getAllQueueNames() throws Exception;
+
+   /**
     * Returns the number of pages used by this address.
     */
    @Attribute(desc = "number of pages used by this address")
diff --git 
a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
 
b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
index c19960f..951b9ad 100644
--- 
a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
+++ 
b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/server/impl/JMSServerManagerImpl.java
@@ -808,7 +808,7 @@ public class JMSServerManagerImpl extends 
CleaningActivateCallback implements JM
       checkInitialised();
       AddressControl addressControl = (AddressControl) 
server.getManagementService().getResource(ResourceNames.ADDRESS + name);
       if (addressControl != null) {
-         for (String queueName : addressControl.getQueueNames()) {
+         for (String queueName : addressControl.getAllQueueNames()) {
             Binding binding = server.getPostOffice().getBinding(new 
SimpleString(queueName));
             if (binding == null) {
                ActiveMQJMSServerLogger.LOGGER.noQueueOnTopic(queueName, name);
@@ -821,7 +821,7 @@ public class JMSServerManagerImpl extends 
CleaningActivateCallback implements JM
             }
          }
 
-         if (addressControl.getQueueNames().length == 0) {
+         if (addressControl.getAllQueueNames().length == 0) {
             try {
                server.removeAddressInfo(SimpleString.toSimpleString(name), 
null);
             } catch (ActiveMQAddressDoesNotExistException e) {
diff --git 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
index bc18864..7760849 100644
--- 
a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
+++ 
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java
@@ -133,17 +133,26 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
 
    @Override
    public String[] getRemoteQueueNames() throws Exception {
-      return getQueueNames(false);
+      return getQueueNames(SearchType.REMOTE);
    }
 
    @Override
    public String[] getQueueNames() throws Exception {
-      return getQueueNames(true);
+      return getQueueNames(SearchType.LOCAL);
    }
 
-   private String[] getQueueNames(boolean local) throws Exception {
+   @Override
+   public String[] getAllQueueNames() throws Exception {
+      return getQueueNames(SearchType.ALL);
+   }
+
+   enum SearchType {
+      LOCAL, REMOTE, ALL
+   }
+
+   private String[] getQueueNames(SearchType searchType) throws Exception {
       if (AuditLogger.isEnabled()) {
-         AuditLogger.getQueueNames(this.addressInfo, local);
+         AuditLogger.getQueueNames(this.addressInfo, searchType);
       }
       clearIO();
       try {
@@ -151,7 +160,7 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
          if (bindings != null) {
             List<String> queueNames = new ArrayList<>();
             for (Binding binding : bindings.getBindings()) {
-               if ((local && binding.isLocal()) || (!local && binding 
instanceof RemoteQueueBinding)) {
+               if (binding instanceof QueueBinding && ((searchType == 
SearchType.ALL) || (searchType == SearchType.LOCAL && binding.isLocal()) || 
(searchType == SearchType.REMOTE && binding instanceof RemoteQueueBinding))) {
                   queueNames.add(binding.getUniqueName().toString());
                }
             }
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlClusterTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlClusterTest.java
index 5db6575..45402e6 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlClusterTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/server/management/TopicControlClusterTest.java
@@ -52,11 +52,17 @@ public class TopicControlClusterTest extends 
JMSClusteredTestBase {
          AddressControl topicControl1 = 
ManagementControlHelper.createAddressControl(simpleTopicName, mBeanServer1);
          AddressControl topicControl2 = 
ManagementControlHelper.createAddressControl(simpleTopicName, mBeanServer2);
 
-         assertTrue("There should be 3 subscriptions on the topic, 2 local and 
1 remote.",
-                    Wait.waitFor(() -> topicControl1.getQueueNames().length == 
3, 2000));
+         assertTrue("There should be 2 local subscriptions on the topic.",
+                    Wait.waitFor(() -> topicControl1.getQueueNames().length == 
2, 2000));
 
-         assertTrue("There should be 3 subscriptions on the topic, 1 local and 
2 remote.",
-                    Wait.waitFor(() -> topicControl2.getQueueNames().length == 
3, 2000));
+         assertTrue("There should be 1 remote subscription on the topic.",
+                    Wait.waitFor(() -> 
topicControl1.getRemoteQueueNames().length == 1, 2000));
+
+         assertTrue("There should be 1 local subscription on the topic.",
+                    Wait.waitFor(() -> topicControl2.getQueueNames().length == 
1, 2000));
+
+         assertTrue("There should be 2 remote subscriptions on the topic.",
+                    Wait.waitFor(() -> 
topicControl2.getRemoteQueueNames().length == 2, 2000));
       }
 
       jmsServer1.destroyTopic("t1");
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java
index 432ecf8..55a9bad 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java
@@ -102,7 +102,7 @@ public class AddressControlTest extends ManagementTestBase {
    }
 
    @Test
-   public void testGetQueueNames() throws Exception {
+   public void testGetLocalQueueNames() throws Exception {
       SimpleString address = RandomUtil.randomSimpleString();
       SimpleString queue = RandomUtil.randomSimpleString();
       SimpleString anotherQueue = RandomUtil.randomSimpleString();
@@ -149,6 +149,40 @@ public class AddressControlTest extends ManagementTestBase 
{
    }
 
    @Test
+   public void testGetAllQueueNames() throws Exception {
+      SimpleString address = RandomUtil.randomSimpleString();
+      SimpleString queue = RandomUtil.randomSimpleString();
+      SimpleString anotherQueue = RandomUtil.randomSimpleString();
+      SimpleString remoteQueue = RandomUtil.randomSimpleString();
+
+      session.createQueue(new QueueConfiguration(queue).setAddress(address));
+
+      // add a fake RemoteQueueBinding to simulate being in a cluster
+      RemoteQueueBinding binding = new 
RemoteQueueBindingImpl(server.getStorageManager().generateID(), address, 
remoteQueue, RandomUtil.randomSimpleString(), RandomUtil.randomLong(), null, 
null, RandomUtil.randomSimpleString(), RandomUtil.randomInt() + 1, 
MessageLoadBalancingType.OFF);
+      server.getPostOffice().addBinding(binding);
+
+      AddressControl addressControl = createManagementControl(address);
+      String[] queueNames = addressControl.getAllQueueNames();
+      Assert.assertEquals(2, queueNames.length);
+      Assert.assertTrue(Arrays.asList(queueNames).contains(queue.toString()));
+      
Assert.assertTrue(Arrays.asList(queueNames).contains(remoteQueue.toString()));
+
+      session.createQueue(new 
QueueConfiguration(anotherQueue).setAddress(address).setDurable(false));
+      queueNames = addressControl.getAllQueueNames();
+      Assert.assertEquals(3, queueNames.length);
+      
Assert.assertTrue(Arrays.asList(queueNames).contains(anotherQueue.toString()));
+
+      session.deleteQueue(queue);
+
+      queueNames = addressControl.getAllQueueNames();
+      Assert.assertEquals(2, queueNames.length);
+      
Assert.assertTrue(Arrays.asList(queueNames).contains(anotherQueue.toString()));
+      Assert.assertFalse(Arrays.asList(queueNames).contains(queue.toString()));
+
+      session.deleteQueue(anotherQueue);
+   }
+
+   @Test
    public void testGetBindingNames() throws Exception {
       SimpleString address = RandomUtil.randomSimpleString();
       SimpleString queue = RandomUtil.randomSimpleString();
diff --git 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
index cd7354c..faf41aa 100644
--- 
a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
+++ 
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlUsingCoreTest.java
@@ -79,6 +79,11 @@ public class AddressControlUsingCoreTest extends 
AddressControlTest {
          }
 
          @Override
+         public String[] getAllQueueNames() throws Exception {
+            return (String[]) proxy.retrieveAttributeValue("allQueueNames", 
String.class);
+         }
+
+         @Override
          public String[] getQueueNames() throws Exception {
             return (String[]) proxy.retrieveAttributeValue("queueNames", 
String.class);
          }

Reply via email to