Search in sources :

Example 16 with DestinationViewMBean

use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.

the class ExpiredMessagesWithNoConsumerTest method testExpiredMessagesWithVerySlowConsumer.

// first ack delivered after expiry
public void testExpiredMessagesWithVerySlowConsumer() throws Exception {
    createBroker();
    final long queuePrefetch = 5;
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(connectionUri + "?jms.prefetchPolicy.queuePrefetch=" + queuePrefetch);
    connection = factory.createConnection();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    producer = session.createProducer(destination);
    final int ttl = 4000;
    producer.setTimeToLive(ttl);
    final long sendCount = 10;
    final CountDownLatch receivedOneCondition = new CountDownLatch(1);
    final CountDownLatch waitCondition = new CountDownLatch(1);
    MessageConsumer consumer = session.createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                LOG.info("Got my message: " + message);
                receivedOneCondition.countDown();
                waitCondition.await(6, TimeUnit.MINUTES);
                LOG.info("acking message: " + message);
                message.acknowledge();
            } catch (Exception e) {
                e.printStackTrace();
                fail(e.toString());
            }
        }
    });
    connection.start();
    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("got one message", receivedOneCondition.await(20, TimeUnit.SECONDS));
    assertTrue("producer failed to complete within allocated time", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            producingThread.join(1000);
            return !producingThread.isAlive();
        }
    }, Wait.MAX_WAIT_MILLIS * 10));
    final DestinationViewMBean view = createView(destination);
    assertTrue("all dispatched up to default prefetch ", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return queuePrefetch == view.getDispatchCount();
        }
    }));
    assertTrue("all non inflight have expired ", 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 view.getExpiredCount() > 0 && (view.getEnqueueCount() - view.getInFlightCount()) == view.getExpiredCount();
        }
    }));
    LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
    // let the ack happen
    waitCondition.countDown();
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 0 == view.getInFlightCount();
        }
    });
    LOG.info("enqueue=" + view.getEnqueueCount() + ", dequeue=" + view.getDequeueCount() + ", inflight=" + view.getInFlightCount() + ", expired= " + view.getExpiredCount() + ", size= " + view.getQueueSize());
    assertEquals("inflight reduced to duck", 0, view.getInFlightCount());
    assertEquals("size didn't get back to 0 ", 0, view.getQueueSize());
    assertEquals("dequeues didn't match sent/expired ", sendCount, view.getDequeueCount());
    consumer.close();
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 0 == view.getInFlightCount();
        }
    });
    assertEquals("inflight goes to zero on close", 0, view.getInFlightCount());
    LOG.info("done: " + getName());
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) CountDownLatch(java.util.concurrent.CountDownLatch) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) Wait(org.apache.activemq.util.Wait)

Example 17 with DestinationViewMBean

use of org.apache.activemq.broker.jmx.DestinationViewMBean in project activemq-artemis by apache.

the class ExpiredMessagesWithNoConsumerTest method createView.

protected DestinationViewMBean createView(ActiveMQDestination destination) throws Exception {
    String domain = "org.apache.activemq";
    ObjectName name;
    if (destination.isQueue()) {
        name = new ObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Queue,destinationName=test");
    } else {
        name = new ObjectName(domain + ":type=Broker,brokerName=localhost,destinationType=Topic,destinationName=test");
    }
    return (DestinationViewMBean) broker.getManagementContext().newProxyInstance(name, DestinationViewMBean.class, true);
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ObjectName(javax.management.ObjectName)

Aggregations

DestinationViewMBean (org.apache.activemq.broker.jmx.DestinationViewMBean)17 ObjectName (javax.management.ObjectName)6 ActiveMQConnectionFactory (org.apache.activemq.ActiveMQConnectionFactory)6 Wait (org.apache.activemq.util.Wait)5 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)4 Test (org.junit.Test)4 Message (javax.jms.Message)3 MessageConsumer (javax.jms.MessageConsumer)3 MessageListener (javax.jms.MessageListener)3 InstanceNotFoundException (javax.management.InstanceNotFoundException)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Connection (javax.jms.Connection)2 ActiveMQMessageConsumer (org.apache.activemq.ActiveMQMessageConsumer)2 ConnectionInfo (org.apache.activemq.command.ConnectionInfo)2 ConsumerInfo (org.apache.activemq.command.ConsumerInfo)2 DataArrayResponse (org.apache.activemq.command.DataArrayResponse)2 Message (org.apache.activemq.command.Message)2 ProducerInfo (org.apache.activemq.command.ProducerInfo)2 SessionInfo (org.apache.activemq.command.SessionInfo)2