Search in sources :

Example 71 with QueueControl

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

the class ManagementWithPagingServerTest method testListMessagesAsJSONWhilePagingOnGoing.

// In this test, the management api listMessageAsJSon is called while
// paging/depaging is going on. It makes sure that the implementation
// of the api doesn't cause any exceptions during internal queue
// message iteration.
@Test
public void testListMessagesAsJSONWhilePagingOnGoing() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session1.createQueue(address, queue, null, true);
    QueueControl queueControl = createManagementControl(address, queue);
    int num = 1000;
    SenderThread sender = new SenderThread(address, num, 1);
    ReceiverThread receiver = new ReceiverThread(queue, num, 2);
    ManagementThread console = new ManagementThread(queueControl);
    // kick off sender
    sender.start();
    // kick off jmx client
    console.start();
    // wait for all messages sent
    sender.join();
    assertNull(sender.getError());
    // kick off receiver
    receiver.start();
    receiver.join();
    assertNull(receiver.getError());
    console.exit();
    console.join();
    assertNull(console.getError());
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 72 with QueueControl

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

the class QueueControlTest method testMoveMessages.

/**
 * <ol>
 * <li>send a message to queue</li>
 * <li>move all messages from queue to otherQueue using management method</li>
 * <li>check there is no message to consume from queue</li>
 * <li>consume the message from otherQueue</li>
 * </ol>
 */
@Test
public void testMoveMessages() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    SimpleString otherAddress = RandomUtil.randomSimpleString();
    SimpleString otherQueue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    session.createQueue(otherAddress, RoutingType.MULTICAST, otherQueue, null, durable);
    ClientProducer producer = session.createProducer(address);
    // send on queue
    ClientMessage message = session.createMessage(durable);
    SimpleString key = RandomUtil.randomSimpleString();
    long value = RandomUtil.randomLong();
    message.putLongProperty(key, value);
    producer.send(message);
    final LocalQueueBinding binding = (LocalQueueBinding) server.getPostOffice().getBinding(queue);
    Queue q = binding.getQueue();
    Field queueMemorySizeField = QueueImpl.class.getDeclaredField("queueMemorySize");
    queueMemorySizeField.setAccessible(true);
    // Get memory size counters to verify
    AtomicInteger queueMemorySize = (AtomicInteger) queueMemorySizeField.get(q);
    QueueControl queueControl = createManagementControl(address, queue);
    assertMessageMetrics(queueControl, 1, durable);
    // verify memory usage is greater than 0
    Assert.assertTrue(queueMemorySize.get() > 0);
    // moved all messages to otherQueue
    int movedMessagesCount = queueControl.moveMessages(null, otherQueue.toString());
    Assert.assertEquals(1, movedMessagesCount);
    assertMessageMetrics(queueControl, 0, durable);
    // verify memory usage is 0 after move
    Assert.assertEquals(0, queueMemorySize.get());
    // check there is no message to consume from queue
    consumeMessages(0, session, queue);
    // consume the message from otherQueue
    ClientConsumer otherConsumer = session.createConsumer(otherQueue);
    ClientMessage m = otherConsumer.receive(500);
    Assert.assertEquals(value, m.getObjectProperty(key));
    m.acknowledge();
    session.deleteQueue(queue);
    otherConsumer.close();
    session.deleteQueue(otherQueue);
}
Also used : LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) Field(java.lang.reflect.Field) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Queue(org.apache.activemq.artemis.core.server.Queue) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) Test(org.junit.Test)

Example 73 with QueueControl

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

the class QueueControlTest method testResetMessageCounter.

@Test
public void testResetMessageCounter() throws Exception {
    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(MessageCounterManagerImpl.MIN_SAMPLE_PERIOD);
    String jsonString = queueControl.listMessageCounter();
    MessageCounterInfo info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(0, info.getDepth());
    Assert.assertEquals(0, info.getCount());
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    Thread.sleep(MessageCounterManagerImpl.MIN_SAMPLE_PERIOD * 2);
    jsonString = queueControl.listMessageCounter();
    info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(1, info.getDepth());
    Assert.assertEquals(1, info.getDepthDelta());
    Assert.assertEquals(1, info.getCount());
    Assert.assertEquals(1, info.getCountDelta());
    consumeMessages(1, session, queue);
    Thread.sleep(MessageCounterManagerImpl.MIN_SAMPLE_PERIOD * 2);
    jsonString = queueControl.listMessageCounter();
    info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(0, info.getDepth());
    Assert.assertEquals(-1, info.getDepthDelta());
    Assert.assertEquals(1, info.getCount());
    Assert.assertEquals(0, info.getCountDelta());
    queueControl.resetMessageCounter();
    Thread.sleep(MessageCounterManagerImpl.MIN_SAMPLE_PERIOD * 2);
    jsonString = queueControl.listMessageCounter();
    info = MessageCounterInfo.fromJSON(jsonString);
    Assert.assertEquals(0, info.getDepth());
    Assert.assertEquals(0, info.getDepthDelta());
    Assert.assertEquals(0, info.getCount());
    Assert.assertEquals(0, info.getCountDelta());
    session.deleteQueue(queue);
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) MessageCounterInfo(org.apache.activemq.artemis.api.core.management.MessageCounterInfo) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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 74 with QueueControl

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

the class QueueControlTest method testListMessagesAsJSONWithNullFilter.

@Test
public void testListMessagesAsJSONWithNullFilter() throws Exception {
    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(durable);
    message.putIntProperty(new SimpleString("key"), intValue);
    producer.send(message);
    String jsonString = queueControl.listMessagesAsJSON(null);
    Assert.assertNotNull(jsonString);
    JsonArray array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(1, array.size());
    long l = Long.parseLong(array.getJsonObject(0).get("key").toString().replaceAll("\"", ""));
    Assert.assertEquals(intValue, l);
    consumeMessages(1, session, queue);
    jsonString = queueControl.listMessagesAsJSON(null);
    Assert.assertNotNull(jsonString);
    array = JsonUtil.readJsonArray(jsonString);
    Assert.assertEquals(0, array.size());
    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 75 with QueueControl

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

the class QueueControlTest method testGetDeliveringCount.

@Test
public void testGetDeliveringCount() throws Exception {
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    QueueControl queueControl = createManagementControl(address, queue);
    Assert.assertEquals(0, queueControl.getDeliveringCount());
    ClientConsumer consumer = session.createConsumer(queue);
    ClientMessage message = consumer.receive(500);
    Assert.assertNotNull(message);
    assertDeliveringMetrics(queueControl, 1, durable);
    message.acknowledge();
    session.commit();
    assertDeliveringMetrics(queueControl, 0, durable);
    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)

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