This test doesn't need to bind to the RMI connector to create Queue via
the JMX MBean.
This commit is contained in:
Timothy Bish 2015-02-27 15:39:03 -05:00
parent 84c1419c3d
commit 0683d8be94
1 changed files with 29 additions and 27 deletions

View File

@ -16,6 +16,14 @@
*/
package org.apache.activemq.broker.advisory;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.BrokerViewMBean;
@ -23,16 +31,9 @@ import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.DestinationInfo;
import javax.jms.*;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
public class AdvisoryJmxTest extends EmbeddedBrokerTestSupport {
@Override
protected BrokerService createBroker() throws Exception {
BrokerService answer = new BrokerService();
answer.setPersistent(isPersistent());
@ -43,13 +44,16 @@ public class AdvisoryJmxTest extends EmbeddedBrokerTestSupport {
return answer;
}
protected BrokerViewMBean getProxyToBroker() throws MalformedObjectNameException, JMSException {
ObjectName brokerViewMBean = new ObjectName(
"org.apache.activemq:type=Broker,brokerName=localhost");
BrokerViewMBean proxy = (BrokerViewMBean) broker.getManagementContext()
.newProxyInstance(brokerViewMBean, BrokerViewMBean.class, true);
return proxy;
}
public void testCreateDeleteDestinations() throws Exception {
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:1199/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(url, null);
connector.connect();
MBeanServerConnection connection = connector.getMBeanServerConnection();
ObjectName name = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost");
BrokerViewMBean brokerMbean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(connection, name, BrokerViewMBean.class, true);
BrokerViewMBean brokerMbean = getProxyToBroker();
Connection conn = createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = sess.createConsumer(sess.createTopic("ActiveMQ.Advisory.Queue"));
@ -72,7 +76,6 @@ public class AdvisoryJmxTest extends EmbeddedBrokerTestSupport {
assertEquals(((DestinationInfo) msg.getDataStructure()).getDestination(), dest);
assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 1);
brokerMbean.addQueue("test");
msg = (ActiveMQMessage) consumer.receive(1000);
assertNotNull(msg);
@ -82,5 +85,4 @@ public class AdvisoryJmxTest extends EmbeddedBrokerTestSupport {
assertEquals(((DestinationInfo) msg.getDataStructure()).getOperationType(), 0);
}
}