use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class AbortSlowConsumer0Test method testSlowConsumerIsAbortedViaJmx.
@Test
public void testSlowConsumerIsAbortedViaJmx() throws Exception {
// so jmx does the abort
underTest.setMaxSlowDuration(60 * 1000);
startConsumers(withPrefetch(2, destination));
Entry<MessageConsumer, MessageIdList> consumertoAbort = consumers.entrySet().iterator().next();
consumertoAbort.getValue().setProcessingDelay(8 * 1000);
for (Connection c : connections) {
c.setExceptionListener(this);
}
startProducers(destination, 100);
consumertoAbort.getValue().assertMessagesReceived(1);
ActiveMQDestination amqDest = (ActiveMQDestination) destination;
ObjectName destinationViewMBean = new ObjectName("org.apache.activemq:destinationType=" + (amqDest.isTopic() ? "Topic" : "Queue") + ",destinationName=" + amqDest.getPhysicalName() + ",type=Broker,brokerName=localhost");
DestinationViewMBean queue = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(destinationViewMBean, DestinationViewMBean.class, true);
ObjectName slowConsumerPolicyMBeanName = queue.getSlowConsumerStrategy();
assertNotNull(slowConsumerPolicyMBeanName);
AbortSlowConsumerStrategyViewMBean abortPolicy = (AbortSlowConsumerStrategyViewMBean) broker.getManagementContext().newProxyInstance(slowConsumerPolicyMBeanName, AbortSlowConsumerStrategyViewMBean.class, true);
TimeUnit.SECONDS.sleep(3);
TabularData slowOnes = abortPolicy.getSlowConsumers();
assertEquals("one slow consumers", 1, slowOnes.size());
LOG.info("slow ones:" + slowOnes);
CompositeData slowOne = (CompositeData) slowOnes.values().iterator().next();
LOG.info("Slow one: " + slowOne);
assertTrue("we have an object name", slowOne.get("subscription") instanceof ObjectName);
abortPolicy.abortConsumer((ObjectName) slowOne.get("subscription"));
consumertoAbort.getValue().assertAtMostMessagesReceived(1);
slowOnes = abortPolicy.getSlowConsumers();
assertEquals("no slow consumers left", 0, slowOnes.size());
// verify mbean gone with destination
broker.getAdminView().removeTopic(amqDest.getPhysicalName());
try {
abortPolicy.getSlowConsumers();
fail("expect not found post destination removal");
} catch (UndeclaredThrowableException expected) {
assertTrue("correct exception: " + expected.getCause(), expected.getCause() instanceof InstanceNotFoundException);
}
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class TwoBrokerTempQueueAdvisoryTest method testTemporaryQueueAdvisory.
public void testTemporaryQueueAdvisory() throws Exception {
LOG.info("Running testTemporaryQueueAdvisory()");
bridgeBrokers("BrokerA", "BrokerB");
bridgeBrokers("BrokerB", "BrokerA");
startAllBrokers();
waitForBridgeFormation();
waitForMinTopicRegionConsumerCount("BrokerB", 1);
waitForMinTopicRegionConsumerCount("BrokerA", 1);
final int iterations = 30;
for (int i = 0; i < iterations; i++) {
sendReceiveTempQueueMessage("BrokerA");
}
waitForMinTopicRegionConsumerCount("BrokerB", 1);
waitForMinTopicRegionConsumerCount("BrokerA", 1);
final DestinationViewMBean brokerAView = createView("BrokerA", "ActiveMQ.Advisory.TempQueue", ActiveMQDestination.TOPIC_TYPE);
assertTrue("exact amount of advisories created on A, one each for creation/deletion", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("BrokerA temp advisory enque count: " + brokerAView.getEnqueueCount());
return iterations * 2 == brokerAView.getEnqueueCount();
}
}));
final DestinationViewMBean brokerBView = createView("BrokerB", "ActiveMQ.Advisory.TempQueue", ActiveMQDestination.TOPIC_TYPE);
assertTrue("exact amount of advisories created on B, one each for creation/deletion", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("BrokerB temp advisory enque count: " + brokerBView.getEnqueueCount());
return iterations * 2 == brokerBView.getEnqueueCount();
}
}));
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class ExpiredMessagesWithNoConsumerTest method testExpiredNonPersistentMessagesWithNoConsumer.
public void testExpiredNonPersistentMessagesWithNoConsumer() throws Exception {
createBrokerWithMemoryLimit(2000);
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
producer.setTimeToLive(1000);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
connection.start();
final long sendCount = 2000;
final Thread producingThread = new Thread("Producing Thread") {
@Override
public void run() {
try {
int i = 0;
long tStamp = System.currentTimeMillis();
while (i++ < sendCount) {
producer.send(session.createTextMessage("test"));
if (i % 100 == 0) {
LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms");
tStamp = System.currentTimeMillis();
}
if (135 == i) {
// allow pending messages to expire, before usage limit kicks in to flush them
TimeUnit.SECONDS.sleep(5);
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
};
producingThread.start();
assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
producingThread.join(TimeUnit.SECONDS.toMillis(3000));
return !producingThread.isAlive();
}
}));
TimeUnit.SECONDS.sleep(5);
final DestinationViewMBean view = createView(destination);
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
try {
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
return view.getDequeueCount() != 0 && view.getDequeueCount() == view.getExpiredCount() && view.getDequeueCount() == view.getEnqueueCount() && view.getQueueSize() == 0;
} catch (Exception ignored) {
LOG.info(ignored.toString());
}
return false;
}
}, Wait.MAX_WAIT_MILLIS * 10);
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
assertEquals("memory usage doesn't go to duck egg", 0, view.getMemoryPercentUsage());
assertEquals("0 queue", 0, view.getQueueSize());
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class ExpiredMessagesWithNoConsumerTest method testExpireMessagesForDurableSubscriber.
public void testExpireMessagesForDurableSubscriber() throws Exception {
createBroker();
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
connection = factory.createConnection();
connection.setClientID("myConnection");
session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
connection.start();
Topic destination = session.createTopic("test");
producer = session.createProducer(destination);
final int ttl = 1000;
producer.setTimeToLive(ttl);
final long sendCount = 10;
TopicSubscriber sub = session.createDurableSubscriber(destination, "mySub");
sub.close();
for (int i = 0; i < sendCount; i++) {
producer.send(session.createTextMessage("test"));
}
DestinationViewMBean view = createView((ActiveMQTopic) destination);
LOG.info("messages sent");
LOG.info("expired=" + view.getExpiredCount() + " " + view.getEnqueueCount());
assertEquals(0, view.getExpiredCount());
assertEquals(10, view.getEnqueueCount());
Thread.sleep(5000);
LOG.info("expired=" + view.getExpiredCount() + " " + view.getEnqueueCount());
assertEquals(10, view.getExpiredCount());
assertEquals(10, view.getEnqueueCount());
final AtomicLong received = new AtomicLong();
sub = session.createDurableSubscriber(destination, "mySub");
sub.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
received.incrementAndGet();
}
});
LOG.info("Waiting for messages to arrive");
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return received.get() >= sendCount;
}
}, 1000);
LOG.info("received=" + received.get());
LOG.info("expired=" + view.getExpiredCount() + " " + view.getEnqueueCount());
assertEquals(0, received.get());
assertEquals(10, view.getExpiredCount());
assertEquals(10, view.getEnqueueCount());
}
use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.
the class ExpiredMessagesWithNoConsumerTest method testExpiredMessagesWithNoConsumer.
public void testExpiredMessagesWithNoConsumer() throws Exception {
createBrokerWithMemoryLimit();
ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri);
connection = factory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
producer.setTimeToLive(1000);
connection.start();
final long sendCount = 2000;
final Thread producingThread = new Thread("Producing Thread") {
@Override
public void run() {
try {
int i = 0;
long tStamp = System.currentTimeMillis();
while (i++ < sendCount) {
producer.send(session.createTextMessage("test"));
if (i % 100 == 0) {
LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms");
tStamp = System.currentTimeMillis();
}
}
} catch (Throwable ex) {
ex.printStackTrace();
}
}
};
producingThread.start();
assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
producingThread.join(TimeUnit.SECONDS.toMillis(3000));
return !producingThread.isAlive();
}
}));
final DestinationViewMBean view = createView(destination);
Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
return sendCount == view.getExpiredCount();
}
}, Wait.MAX_WAIT_MILLIS * 10);
LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
assertEquals("Not all sent messages have expired", sendCount, view.getExpiredCount());
assertEquals("memory usage doesn't go to duck egg", 0, view.getMemoryPercentUsage());
}
Aggregations