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