Search in sources :

Example 11 with DestinationViewMBean

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);
    }
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) ActiveMQMessageConsumer(org.apache.activemq.ActiveMQMessageConsumer) MessageConsumer(javax.jms.MessageConsumer) CompositeData(javax.management.openmbean.CompositeData) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) InstanceNotFoundException(javax.management.InstanceNotFoundException) Connection(javax.jms.Connection) AbortSlowConsumerStrategyViewMBean(org.apache.activemq.broker.jmx.AbortSlowConsumerStrategyViewMBean) MessageIdList(org.apache.activemq.util.MessageIdList) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Example 12 with DestinationViewMBean

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();
        }
    }));
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean)

Example 13 with DestinationViewMBean

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());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) Wait(org.apache.activemq.util.Wait)

Example 14 with DestinationViewMBean

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());
}
Also used : DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) Message(javax.jms.Message) MessageListener(javax.jms.MessageListener) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) TopicSubscriber(javax.jms.TopicSubscriber) AtomicLong(java.util.concurrent.atomic.AtomicLong) Topic(javax.jms.Topic) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) Wait(org.apache.activemq.util.Wait)

Example 15 with DestinationViewMBean

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());
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) DestinationViewMBean(org.apache.activemq.broker.jmx.DestinationViewMBean) Wait(org.apache.activemq.util.Wait)

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