Search in sources :

Example 86 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class QueueControlTest method testGetMessageCount.

@Test
public void testGetMessageCount() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, getMessageCount(queueControl));
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    assertMessageMetrics(queueControl, 1, durable);
    consumeMessages(1, session, queue);
    assertMessageMetrics(queueControl, 0, durable);
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 87 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class QueueControlTest method testListMessagesWithEmptyFilter.

@Test
public void testListMessagesWithEmptyFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    producer.send(session.createMessage(durable));
    Map<String, Object>[] messages = queueControl.listMessages("");
    Assert.assertEquals(2, messages.length);
    consumeMessages(2, session, queue);
    messages = queueControl.listMessages("");
    Assert.assertEquals(0, messages.length);
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Map(java.util.Map) HashMap(java.util.HashMap) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 88 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class QueueControlTest method testListMessagesWithNullFilter.

@Test
public void testListMessagesWithNullFilter() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    producer.send(session.createMessage(durable));
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(2, messages.length);
    consumeMessages(2, session, queue);
    messages = queueControl.listMessages(null);
    Assert.assertEquals(0, messages.length);
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Map(java.util.Map) HashMap(java.util.HashMap) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 89 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class QueueControlTest method testRemoveMessages.

/**
 * <ol>
 * <li>send 2 message to queue</li>
 * <li>remove messages from queue using management method <em>with filter</em></li>
 * <li>check there is only one message to consume from queue</li>
 * </ol>
 */
@Test
public void testRemoveMessages() throws Exception {
    SimpleString key = new SimpleString("key");
    long matchingValue = RandomUtil.randomLong();
    long unmatchingValue = matchingValue + 1;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    ClientMessage matchingMessage = session.createMessage(durable);
    matchingMessage.putLongProperty(key, matchingValue);
    producer.send(matchingMessage);
    ClientMessage unmatchingMessage = session.createMessage(durable);
    unmatchingMessage.putLongProperty(key, unmatchingValue);
    producer.send(unmatchingMessage);
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 2, durable);
    // removed matching messages to otherQueue
    int removedMatchedMessagesCount = queueControl.removeMessages(key + " =" + matchingValue);
    Assert.assertEquals(1, removedMatchedMessagesCount);
    Assert.assertEquals(1, getMessageCount(queueControl));
    // consume the unmatched message from queue
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage m = consumer.receive(500);
    Assert.assertNotNull(m);
    Assert.assertEquals(unmatchingValue, m.getObjectProperty(key));
    m.acknowledge();
    // check there is no other message to consume:
    m = consumer.receiveImmediate();
    Assert.assertNull(m);
    consumer.close();
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 90 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.

the class QueueControlTest method testMessagesAddedAndMessagesAcknowledged.

@Test
public void testMessagesAddedAndMessagesAcknowledged() throws Exception {
    final int THREAD_COUNT = 5;
    final int MSG_COUNT = 1000;
    CountDownLatch producerCountDown = new CountDownLatch(THREAD_COUNT);
    CountDownLatch consumerCountDown = new CountDownLatch(THREAD_COUNT);
    ExecutorService producerExecutor = Executors.newFixedThreadPool(THREAD_COUNT);
    ExecutorService consumerExecutor = Executors.newFixedThreadPool(THREAD_COUNT);
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    try {
        session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
        for (int i = 0; i < THREAD_COUNT; i++) {
            producerExecutor.submit(() -> {
                try (ClientSessionFactory sf = locator.createSessionFactory();
                    ClientSession session = sf.createSession(false, true, false);
                    ClientProducer producer = session.createProducer(address)) {
                    for (int j = 0; j < MSG_COUNT; j++) {
                        producer.send(session.createMessage(false));
                        Thread.sleep(5);
                    }
                    producerCountDown.countDown();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
        for (int i = 0; i < THREAD_COUNT; i++) {
            consumerExecutor.submit(() -> {
                try (ClientSessionFactory sf = locator.createSessionFactory();
                    ClientSession session = sf.createSession(false, true, false);
                    ClientConsumer consumer = session.createConsumer(queue)) {
                    session.start();
                    for (int j = 0; j < MSG_COUNT; j++) {
                        ClientMessage message = consumer.receive(500);
                        Assert.assertNotNull(message);
                        message.acknowledge();
                    }
                    session.commit();
                    consumerCountDown.countDown();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            });
        }
        producerCountDown.await(30, TimeUnit.SECONDS);
        consumerCountDown.await(30, TimeUnit.SECONDS);
        QueueControl queueControl = createManagementControl(address, queue, RoutingType.MULTICAST);
        Thread.sleep(200);
        Assert.assertEquals(0, queueControl.getMessageCount());
        Assert.assertEquals(0, queueControl.getConsumerCount());
        Assert.assertEquals(0, queueControl.getDeliveringCount());
        Assert.assertEquals(THREAD_COUNT * MSG_COUNT, queueControl.getMessagesAdded());
        Assert.assertEquals(THREAD_COUNT * MSG_COUNT, queueControl.getMessagesAcknowledged());
        session.deleteQueue(queue);
    } finally {
        shutdownExecutor(producerExecutor);
        shutdownExecutor(consumerExecutor);
    }
}
Also used : ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ExecutorService(java.util.concurrent.ExecutorService) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Aggregations

QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)109 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)87 Test (org.junit.Test)79 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)50 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)33 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)24 HashMap (java.util.HashMap)21 Map (java.util.Map)18 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)9 ArrayList (java.util.ArrayList)7 JsonObject (javax.json.JsonObject)7 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)7 MessageProducer (javax.jms.MessageProducer)6 TextMessage (javax.jms.TextMessage)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Session (javax.jms.Session)5 JsonArray (javax.json.JsonArray)5 Queue (org.apache.activemq.artemis.core.server.Queue)5