Search in sources :

Example 1 with DestinationViewMBean

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

the class QueueProducerQoSTest method testInOutQueueProducerTTL.

@Test
public void testInOutQueueProducerTTL() throws Exception {
    mockExpiredAdvisory.expectedMessageCount(1);
    String endpoint = String.format("sjms:queue:%s?ttl=1000&exchangePattern=InOut&responseTimeOut=500", TEST_INOUT_DESTINATION_NAME);
    try {
        template.requestBody(endpoint, "test message");
        fail("we aren't expecting any consumers, so should not succeed");
    } catch (Exception e) {
    // we are expecting an exception here because there are no consumers on this queue,
    // so we will not be able to do a real InOut/request-response, but that's okay
    // we're just interested in the message becoming expired
    }
    assertMockEndpointsSatisfied();
    DestinationViewMBean queue = getQueueMBean(TEST_INOUT_DESTINATION_NAME);
    assertEquals("There were unexpected messages left in the queue: " + TEST_INOUT_DESTINATION_NAME, 0, queue.getQueueSize());
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) Test(org.junit.Test)

Example 2 with DestinationViewMBean

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

the class TwoBrokerTempQueueAdvisoryTest method createView.

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

Example 3 with DestinationViewMBean

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

the class XARecoveryBrokerTest method getProxyToDestination.

private DestinationViewMBean getProxyToDestination(ActiveMQDestination destination) throws MalformedObjectNameException, JMSException {
    final ObjectName objectName = new ObjectName("org.apache.activemq:type=Broker,brokerName=" + broker.getBrokerName() + ",destinationType=" + JMXSupport.encodeObjectNamePart(destination.getDestinationTypeAsString()) + ",destinationName=" + JMXSupport.encodeObjectNamePart(destination.getPhysicalName()));
    DestinationViewMBean proxy = (DestinationViewMBean) broker.getManagementContext().newProxyInstance(objectName, DestinationViewMBean.class, true);
    return proxy;
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ObjectName(javax.management.ObjectName)

Example 4 with DestinationViewMBean

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

the class ExpiredMessagesWithNoConsumerTest method testExpiredMessagesWithVerySlowConsumerCanContinue.

public void testExpiredMessagesWithVerySlowConsumerCanContinue() throws Exception {
    createBroker();
    final long queuePrefetch = 600;
    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 = 1500;
    final CountDownLatch receivedOneCondition = new CountDownLatch(1);
    final CountDownLatch waitCondition = new CountDownLatch(1);
    final AtomicLong received = new AtomicLong();
    MessageConsumer consumer = session.createConsumer(destination);
    consumer.setMessageListener(new MessageListener() {

        @Override
        public void onMessage(Message message) {
            try {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Got my message: " + message);
                }
                receivedOneCondition.countDown();
                received.incrementAndGet();
                waitCondition.await(5, TimeUnit.MINUTES);
                if (LOG.isDebugEnabled()) {
                    LOG.debug("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("Not 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 didn't reduce to duck", 0, view.getInFlightCount());
    assertEquals("size doesn't get back to 0 ", 0, view.getQueueSize());
    assertEquals("dequeues don't match sent/expired ", sendCount, view.getDequeueCount());
    // produce some more
    producer.setTimeToLive(0);
    long tStamp = System.currentTimeMillis();
    for (int i = 0; i < sendCount; i++) {
        producer.send(session.createTextMessage("test-" + i));
        if (i % 100 == 0) {
            LOG.info("sent: " + i + " @ " + ((System.currentTimeMillis() - tStamp) / 100) + "m/ms");
            tStamp = System.currentTimeMillis();
        }
    }
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return received.get() >= sendCount;
        }
    });
    consumer.close();
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return 0 == view.getInFlightCount();
        }
    });
    assertEquals("inflight did not go 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) AtomicLong(java.util.concurrent.atomic.AtomicLong) Wait(org.apache.activemq.util.Wait)

Example 5 with DestinationViewMBean

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

the class QueueProducerQoSTest method testInOnlyQueueProducerTTL.

@Test
public void testInOnlyQueueProducerTTL() throws Exception {
    mockExpiredAdvisory.expectedMessageCount(1);
    String endpoint = String.format("sjms:queue:%s?ttl=1000", TEST_INONLY_DESTINATION_NAME);
    template.sendBody(endpoint, "test message");
    assertMockEndpointsSatisfied();
    DestinationViewMBean queue = getQueueMBean(TEST_INONLY_DESTINATION_NAME);
    assertEquals("There were unexpected messages left in the queue: " + TEST_INONLY_DESTINATION_NAME, 0, queue.getQueueSize());
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) Test(org.junit.Test)

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