use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.
the class SecurityJMXTest method testBrowseExpiredMessages.
public void testBrowseExpiredMessages() 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," + "destinationType=Queue,destinationName=TEST.Q");
QueueViewMBean queueMbean = MBeanServerInvocationHandler.newProxyInstance(connection, name, QueueViewMBean.class, true);
HashMap<String, String> headers = new HashMap<>();
headers.put("timeToLive", Long.toString(2000));
headers.put("JMSDeliveryMode", Integer.toString(DeliveryMode.PERSISTENT));
queueMbean.sendTextMessage(headers, "test", "system", "manager");
// allow message to expire on the queue
TimeUnit.SECONDS.sleep(4);
Connection c = new ActiveMQConnectionFactory("vm://localhost").createConnection("system", "manager");
c.start();
// browser consumer will force expiration check on addConsumer
QueueBrowser browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("TEST.Q"));
assertTrue("no message in the q", !browser.getEnumeration().hasMoreElements());
// verify dlq got the message, no security exception as brokers context is now used
browser = c.createSession(false, Session.AUTO_ACKNOWLEDGE).createBrowser(new ActiveMQQueue("ActiveMQ.DLQ"));
assertTrue("one message in the dlq", browser.getEnumeration().hasMoreElements());
}
use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.
the class VerifyNetworkConsumersDisconnectTest method assertExactConsumersConnect.
protected void assertExactConsumersConnect(final String brokerName, final int count, final int numChecks, long timeout) throws Exception {
final ManagementContext context = brokers.get(brokerName).broker.getManagementContext();
final AtomicInteger stability = new AtomicInteger(0);
assertTrue("Expected consumers count: " + count + " on: " + brokerName, Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
try {
QueueViewMBean queueViewMBean = (QueueViewMBean) context.newProxyInstance(brokers.get(brokerName).broker.getAdminView().getQueues()[0], QueueViewMBean.class, false);
long currentCount = queueViewMBean.getConsumerCount();
LOG.info("On " + brokerName + " current consumer count for " + queueViewMBean + ", " + currentCount);
LinkedList<String> consumerIds = new LinkedList<>();
for (ObjectName objectName : queueViewMBean.getSubscriptions()) {
consumerIds.add(objectName.getKeyProperty("consumerId"));
}
LOG.info("Sub IDs: " + consumerIds);
if (currentCount == count) {
stability.incrementAndGet();
} else {
stability.set(0);
}
return stability.get() > numChecks;
} catch (Exception e) {
LOG.warn(": ", e);
return false;
}
}
}, timeout));
}
use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.
the class OpenTypeSupportTest method getProxyToQueueViewMBean.
private QueueViewMBean getProxyToQueueViewMBean() throws MalformedObjectNameException, JMSException {
final ObjectName queueViewMBeanName = new ObjectName("org.apache.activemq:type=Broker,brokerName=localhost,destinationType=Queue,destinationName=" + queue.getQueueName());
QueueViewMBean proxy = (QueueViewMBean) brokerService.getManagementContext().newProxyInstance(queueViewMBeanName, QueueViewMBean.class, true);
return proxy;
}
use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.
the class QueuePurgeTest method testPurgeLargeQueueWithConsumer.
public void testPurgeLargeQueueWithConsumer() throws Exception {
applyBrokerSpoolingPolicy();
createProducerAndSendMessages(NUM_TO_SEND);
QueueViewMBean proxy = getProxyToQueueViewMBean();
createConsumer();
long start = System.currentTimeMillis();
LOG.info("purging..");
proxy.purge();
LOG.info("purge done: " + (System.currentTimeMillis() - start) + "ms");
assertEquals("Queue size is not zero, it's " + proxy.getQueueSize(), 0, proxy.getQueueSize());
assertEquals("usage goes to duck", 0, proxy.getMemoryPercentUsage());
Message msg;
do {
msg = consumer.receive(1000);
if (msg != null) {
msg.acknowledge();
}
} while (msg != null);
assertEquals("Queue size not valid", 0, proxy.getQueueSize());
}
use of org.apache.activemq.broker.jmx.QueueViewMBean in project activemq-artemis by apache.
the class QueuePurgeTest method testRepeatedExpiryProcessingOfLargeQueue.
public void testRepeatedExpiryProcessingOfLargeQueue() throws Exception {
applyBrokerSpoolingPolicy();
final int expiryPeriod = 500;
applyExpiryDuration(expiryPeriod);
createProducerAndSendMessages(NUM_TO_SEND);
QueueViewMBean proxy = getProxyToQueueViewMBean();
LOG.info("waiting for expiry to kick in a bunch of times to verify it does not blow mem");
Thread.sleep(5000);
assertEquals("Queue size is has not changed " + proxy.getQueueSize(), NUM_TO_SEND, proxy.getQueueSize());
}
Aggregations