resolve intermiittent failures related to broker start and async mbean registration

This commit is contained in:
gtully 2015-01-22 13:42:24 +00:00
parent 4648dbee41
commit 2a62b74232
1 changed files with 16 additions and 7 deletions

View File

@ -23,6 +23,7 @@ import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.BytesMessage; import javax.jms.BytesMessage;
import javax.jms.Connection; import javax.jms.Connection;
@ -60,6 +61,7 @@ import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTempQueue; import org.apache.activemq.command.ActiveMQTempQueue;
import org.apache.activemq.util.JMXSupport; import org.apache.activemq.util.JMXSupport;
import org.apache.activemq.util.URISupport; import org.apache.activemq.util.URISupport;
import org.apache.activemq.util.Wait;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -735,13 +737,20 @@ public class MBeanTest extends EmbeddedBrokerTestSupport {
assertEquals("broker Topic Producer count", 0, broker.getTopicProducers().length); assertEquals("broker Topic Producer count", 0, broker.getTopicProducers().length);
} }
protected ObjectName assertRegisteredObjectName(String name) throws MalformedObjectNameException, NullPointerException { protected ObjectName assertRegisteredObjectName(String name) throws MalformedObjectNameException, Exception {
ObjectName objectName = new ObjectName(name); final ObjectName objectName = new ObjectName(name);
if (mbeanServer.isRegistered(objectName)) { final AtomicBoolean result = new AtomicBoolean(false);
echo("Bean Registered: " + objectName); assertTrue("Bean registered: " + objectName, Wait.waitFor(new Wait.Condition() {
} else { @Override
fail("Could not find MBean!: " + objectName); public boolean isSatisified() throws Exception {
} try {
result.set(mbeanServer.isRegistered(objectName));
} catch (Exception ignored) {
LOG.debug(ignored.toString());
}
return result.get();
}
}));
return objectName; return objectName;
} }