Search in sources :

Example 76 with QueueControl

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

the class QueueControlTest method testListScheduledMessagesAsJSON.

@Test
public void testListScheduledMessagesAsJSON() throws Exception {
    long delay = 2000;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    int intValue = RandomUtil.randomInt();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(false);
    message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, System.currentTimeMillis() + delay);
    message.putIntProperty(new SimpleString("key"), intValue);
    producer.send(message);
    // unscheduled message
    producer.send(session.createMessage(durable));
    String jsonString = queueControl.listScheduledMessagesAsJSON();
    Assert.assertNotNull(jsonString);
    JsonArray array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(1, array.size());
    int i = Integer.parseInt(array.getJsonObject(0).get("key").toString().replaceAll("\"", ""));
    Assert.assertEquals(intValue, i);
    Thread.sleep(delay + 500);
    jsonString = queueControl.listScheduledMessagesAsJSON();
    Assert.assertNotNull(jsonString);
    array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(0, array.size());
    consumeMessages(2, session, queue);
    session.deleteQueue(queue);
}
Also used : JsonArray(javax.json.JsonArray) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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 77 with QueueControl

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

the class QueueControlTest method testResetMessagesExpired.

@Test
public void testResetMessagesExpired() 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, queueControl.getMessagesExpired());
    ClientProducer producer = session.createProducer(address);
    ClientMessage message = session.createMessage(durable);
    producer.send(message);
    // the message IDs are set on the server
    Map<String, Object>[] messages = queueControl.listMessages(null);
    Assert.assertEquals(1, messages.length);
    long messageID = (Long) messages[0].get("messageID");
    queueControl.expireMessage(messageID);
    Assert.assertEquals(1, queueControl.getMessagesExpired());
    message = session.createMessage(durable);
    producer.send(message);
    // the message IDs are set on the server
    messages = queueControl.listMessages(null);
    Assert.assertEquals(1, messages.length);
    messageID = (Long) messages[0].get("messageID");
    queueControl.expireMessage(messageID);
    Assert.assertEquals(2, queueControl.getMessagesExpired());
    queueControl.resetMessagesExpired();
    Assert.assertEquals(0, queueControl.getMessagesExpired());
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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 78 with QueueControl

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

the class QueueControlTest method testGetDeadLetterAddress.

@Test
public void testGetDeadLetterAddress() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    final SimpleString deadLetterAddress = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertNull(queueControl.getDeadLetterAddress());
    server.getAddressSettingsRepository().addMatch(address.toString(), new AddressSettings() {

        private static final long serialVersionUID = -4919035864731465338L;

        @Override
        public SimpleString getDeadLetterAddress() {
            return deadLetterAddress;
        }
    });
    Assert.assertEquals(deadLetterAddress.toString(), queueControl.getDeadLetterAddress());
    session.deleteQueue(queue);
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 79 with QueueControl

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

the class QueueControlTest method testCountMessagesWithInvalidFilter.

@Test
public void testCountMessagesWithInvalidFilter() throws Exception {
    SimpleString key = new SimpleString("key");
    String matchingValue = "MATCH";
    String nonMatchingValue = "DIFFERENT";
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    for (int i = 0; i < 100; i++) {
        ClientMessage msg = session.createMessage(durable);
        msg.putStringProperty(key, SimpleString.toSimpleString(matchingValue));
        producer.send(msg);
    }
    for (int i = 0; i < 10; i++) {
        ClientMessage msg = session.createMessage(durable);
        msg.putStringProperty(key, SimpleString.toSimpleString(nonMatchingValue));
        producer.send(msg);
    }
    // this is just to guarantee a round trip and avoid in transit messages, so they are all accounted for
    session.commit();
    ClientConsumer consumer = session.createConsumer(queue, SimpleString.toSimpleString("nonExistentProperty like \'%Temp/88\'"));
    session.start();
    assertNull(consumer.receiveImmediate());
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 110, durable);
    Assert.assertEquals(0, queueControl.countMessages("nonExistentProperty like \'%Temp/88\'"));
    Assert.assertEquals(100, queueControl.countMessages(key + "=\'" + matchingValue + "\'"));
    Assert.assertEquals(10, queueControl.countMessages(key + " = \'" + nonMatchingValue + "\'"));
    consumer.close();
    session.deleteQueue(queue);
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 80 with QueueControl

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

the class QueueControlTest method testListMessageCounterHistoryAsHTML.

@Test
public void testListMessageCounterHistoryAsHTML() throws Exception {
    long counterPeriod = 1000;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    QueueControl queueControl = createManagementControl(address, queue);
    ActiveMQServerControl serverControl = ManagementControlHelper.createActiveMQServerControl(mbeanServer);
    serverControl.enableMessageCounters();
    serverControl.setMessageCounterSamplePeriod(counterPeriod);
    String history = queueControl.listMessageCounterHistoryAsHTML();
    Assert.assertNotNull(history);
    session.deleteQueue(queue);
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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