This closes #3152
This commit is contained in:
commit
30f1329edb
|
@ -72,17 +72,23 @@ 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.
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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();
|
||||
|
@ -148,6 +148,40 @@ public class AddressControlTest extends ManagementTestBase {
|
|||
Assert.assertEquals(queue.toString(), queueNames[0]);
|
||||
}
|
||||
|
||||
@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();
|
||||
|
|
|
@ -78,6 +78,11 @@ public class AddressControlUsingCoreTest extends AddressControlTest {
|
|||
return (String[]) proxy.retrieveAttributeValue("remoteQueueNames", String.class);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
Loading…
Reference in New Issue