diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/SelectiveMBeanRegistrationTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/SelectiveMBeanRegistrationTest.java index 834e60c1eb..a1c6aec170 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/SelectiveMBeanRegistrationTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/jmx/SelectiveMBeanRegistrationTest.java @@ -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; - } - - }