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);
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations