https://issues.apache.org/jira/browse/AMQ-6175 - fix unit test regression SelectiveMBeanRegistrationTest

(cherry picked from commit e313f40989)
This commit is contained in:
gtully 2016-03-08 11:55:19 +00:00 committed by Christopher L. Shannon (cshannon)
parent 94023ebed5
commit e633e49aff
1 changed files with 5 additions and 29 deletions

View File

@ -17,13 +17,11 @@
package org.apache.activemq.broker.jmx;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Session;
import javax.management.MBeanServer;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import org.apache.activemq.ActiveMQConnectionFactory;
@ -32,14 +30,11 @@ import org.apache.activemq.util.Wait;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.*;
public class SelectiveMBeanRegistrationTest {
@ -79,19 +74,18 @@ public class SelectiveMBeanRegistrationTest {
session.createConsumer(queue);
ObjectName brokerName = assertRegisteredObjectName(domain + ":type=Broker,brokerName=localhost");
final BrokerViewMBean broker = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, brokerName, BrokerViewMBean.class, true);
final ManagedRegionBroker managedRegionBroker = (ManagedRegionBroker) brokerService.getBroker().getAdaptor(ManagedRegionBroker.class);
// mbean exists
assertTrue("one sub", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getQueueSubscribers().length == 1;
return managedRegionBroker.getQueueSubscribers().length == 1;
}
}));
// but it is not registered
assertFalse(mbeanServer.isRegistered(broker.getQueueSubscribers()[0]));
assertFalse(mbeanServer.isRegistered(managedRegionBroker.getQueueSubscribers()[0]));
// verify dynamicProducer suppressed
session.createProducer(null);
@ -101,7 +95,7 @@ public class SelectiveMBeanRegistrationTest {
assertTrue("one sub", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return broker.getDynamicDestinationProducers().length == 1;
return managedRegionBroker.getDynamicDestinationProducers().length == 1;
}
}));
@ -128,22 +122,4 @@ public class SelectiveMBeanRegistrationTest {
}
}
protected ObjectName assertRegisteredObjectName(String name) throws Exception {
final ObjectName objectName = new ObjectName(name);
final AtomicBoolean result = new AtomicBoolean(false);
assertTrue("Bean registered: " + objectName, Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
try {
result.set(mbeanServer.isRegistered(objectName));
} catch (Exception ignored) {
LOG.debug(ignored.toString());
}
return result.get();
}
}));
return objectName;
}
}