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 fd11a1e  ARTEMIS-2781 return only local queue names for 
AddressControl.getQueueNames()
     new d3d7d22  This closes #3149
fd11a1e is described below

commit fd11a1e079a1f8e3c1359300ad0ae2ed1a945972
Author: Justin Bertram <[email protected]>
AuthorDate: Tue May 26 15:06:47 2020 -0500

    ARTEMIS-2781 return only local queue names for 
AddressControl.getQueueNames()
---
 .../api/core/management/AddressControl.java        |  8 +++++++-
 .../core/management/impl/AddressControlImpl.java   | 14 +++++++++++--
 .../integration/management/AddressControlTest.java | 24 ++++++++++++++++++++++
 .../management/AddressControlUsingCoreTest.java    |  5 +++++
 4 files changed, 48 insertions(+), 3 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 e367685..d8a2bae 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
@@ -74,7 +74,13 @@ public interface AddressControl {
    /**
     * Returns the names of the queues bound to this address.
     */
-   @Attribute(desc = "names of the 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.
+    */
+   @Attribute(desc = "names of the local queue(s) bound to this address")
    String[] getQueueNames() throws Exception;
 
    /**
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 c3c0a74..bc18864 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
@@ -43,6 +43,7 @@ import org.apache.activemq.artemis.core.security.Role;
 import org.apache.activemq.artemis.core.security.SecurityStore;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
 import org.apache.activemq.artemis.core.server.ActiveMQServerLogger;
+import org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding;
 import org.apache.activemq.artemis.core.server.impl.AddressInfo;
 import org.apache.activemq.artemis.core.server.management.ManagementService;
 import org.apache.activemq.artemis.core.settings.HierarchicalRepository;
@@ -131,9 +132,18 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
    }
 
    @Override
+   public String[] getRemoteQueueNames() throws Exception {
+      return getQueueNames(false);
+   }
+
+   @Override
    public String[] getQueueNames() throws Exception {
+      return getQueueNames(true);
+   }
+
+   private String[] getQueueNames(boolean local) throws Exception {
       if (AuditLogger.isEnabled()) {
-         AuditLogger.getQueueNames(this.addressInfo);
+         AuditLogger.getQueueNames(this.addressInfo, local);
       }
       clearIO();
       try {
@@ -141,7 +151,7 @@ public class AddressControlImpl extends AbstractControl 
implements AddressContro
          if (bindings != null) {
             List<String> queueNames = new ArrayList<>();
             for (Binding binding : bindings.getBindings()) {
-               if (binding instanceof QueueBinding) {
+               if ((local && binding.isLocal()) || (!local && binding 
instanceof RemoteQueueBinding)) {
                   queueNames.add(binding.getUniqueName().toString());
                }
             }
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 d07cc0b..432ecf8 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
@@ -44,6 +44,9 @@ import org.apache.activemq.artemis.core.config.Configuration;
 import org.apache.activemq.artemis.core.security.CheckType;
 import org.apache.activemq.artemis.core.security.Role;
 import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.cluster.RemoteQueueBinding;
+import 
org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType;
+import 
org.apache.activemq.artemis.core.server.cluster.impl.RemoteQueueBindingImpl;
 import org.apache.activemq.artemis.core.server.impl.QueueImpl;
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.tests.util.Wait;
@@ -106,6 +109,10 @@ public class AddressControlTest extends ManagementTestBase 
{
 
       session.createQueue(new QueueConfiguration(queue).setAddress(address));
 
+      // add a fake RemoteQueueBinding to simulate being in a cluster; we 
don't want this binding to be returned by getQueueNames()
+      RemoteQueueBinding binding = new 
RemoteQueueBindingImpl(server.getStorageManager().generateID(), address, 
RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString(), 
RandomUtil.randomLong(), null, null, RandomUtil.randomSimpleString(), 
RandomUtil.randomInt() + 1, MessageLoadBalancingType.OFF);
+      server.getPostOffice().addBinding(binding);
+
       AddressControl addressControl = createManagementControl(address);
       String[] queueNames = addressControl.getQueueNames();
       Assert.assertEquals(1, queueNames.length);
@@ -125,6 +132,23 @@ public class AddressControlTest extends ManagementTestBase 
{
    }
 
    @Test
+   public void testGetRemoteQueueNames() throws Exception {
+      SimpleString address = RandomUtil.randomSimpleString();
+      SimpleString queue = RandomUtil.randomSimpleString();
+
+      session.createAddress(address, RoutingType.MULTICAST, false);
+
+      // add a fake RemoteQueueBinding to simulate being in a cluster; this 
should be returned by getRemoteQueueNames()
+      RemoteQueueBinding binding = new 
RemoteQueueBindingImpl(server.getStorageManager().generateID(), address, queue, 
RandomUtil.randomSimpleString(), RandomUtil.randomLong(), null, null, 
RandomUtil.randomSimpleString(), RandomUtil.randomInt() + 1, 
MessageLoadBalancingType.OFF);
+      server.getPostOffice().addBinding(binding);
+
+      AddressControl addressControl = createManagementControl(address);
+      String[] queueNames = addressControl.getRemoteQueueNames();
+      Assert.assertEquals(1, queueNames.length);
+      Assert.assertEquals(queue.toString(), queueNames[0]);
+   }
+
+   @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 31355fd..cd7354c 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
@@ -74,6 +74,11 @@ public class AddressControlUsingCoreTest extends 
AddressControlTest {
          }
 
          @Override
+         public String[] getRemoteQueueNames() throws Exception {
+            return (String[]) proxy.retrieveAttributeValue("remoteQueueNames", 
String.class);
+         }
+
+         @Override
          public String[] getQueueNames() throws Exception {
             return (String[]) proxy.retrieveAttributeValue("queueNames", 
String.class);
          }

Reply via email to