use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testListScheduledMessages.
@Test
public void testListScheduledMessages() 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(durable);
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));
Map<String, Object>[] messages = queueControl.listScheduledMessages();
Assert.assertEquals(1, messages.length);
assertScheduledMetrics(queueControl, 1, durable);
Assert.assertEquals(intValue, Integer.parseInt((messages[0].get("key")).toString()));
Thread.sleep(delay + 500);
messages = queueControl.listScheduledMessages();
Assert.assertEquals(0, messages.length);
consumeMessages(2, session, queue);
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testRemoveMessage.
@Test
public void testRemoveMessage() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
// send 2 messages on queue
producer.send(session.createMessage(durable));
producer.send(session.createMessage(durable));
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 2, durable);
// the message IDs are set on the server
Map<String, Object>[] messages = queueControl.listMessages(null);
Assert.assertEquals(2, messages.length);
long messageID = (Long) messages[0].get("messageID");
// delete 1st message
boolean deleted = queueControl.removeMessage(messageID);
Assert.assertTrue(deleted);
assertMessageMetrics(queueControl, 1, durable);
// check there is a single message to consume from queue
consumeMessages(1, session, queue);
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testListMessagesAsJSONWithFilter.
@Test
public void testListMessagesAsJSONWithFilter() throws Exception {
SimpleString key = new SimpleString("key");
long matchingValue = RandomUtil.randomLong();
long unmatchingValue = matchingValue + 1;
String filter = key + " =" + matchingValue;
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);
ClientMessage matchingMessage = session.createMessage(durable);
matchingMessage.putLongProperty(key, matchingValue);
producer.send(matchingMessage);
ClientMessage unmatchingMessage = session.createMessage(durable);
unmatchingMessage.putLongProperty(key, unmatchingValue);
producer.send(unmatchingMessage);
String jsonString = queueControl.listMessagesAsJSON(filter);
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(matchingValue, l);
consumeMessages(2, session, queue);
jsonString = queueControl.listMessagesAsJSON(filter);
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 testChangeMessagePriorityWithInvalidValue.
@Test
public void testChangeMessagePriorityWithInvalidValue() throws Exception {
byte invalidPriority = (byte) 23;
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, durable);
ClientProducer producer = session.createProducer(address);
ClientMessage message = session.createMessage(durable);
producer.send(message);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(1, getMessageCount(queueControl));
// 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");
try {
queueControl.changeMessagePriority(messageID, invalidPriority);
Assert.fail("operation fails when priority value is < 0 or > 9");
} catch (Exception e) {
}
ClientConsumer consumer = session.createConsumer(queue);
ClientMessage m = consumer.receive(500);
Assert.assertNotNull(m);
Assert.assertTrue(invalidPriority != m.getPriority());
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 testResetMessagesAdded.
@Test
public void testResetMessagesAdded() 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, getMessagesAdded(queueControl));
ClientProducer producer = session.createProducer(address);
producer.send(session.createMessage(durable));
Assert.assertEquals(1, getMessagesAdded(queueControl));
producer.send(session.createMessage(durable));
Assert.assertEquals(2, getMessagesAdded(queueControl));
consumeMessages(2, session, queue);
Assert.assertEquals(2, getMessagesAdded(queueControl));
queueControl.resetMessagesAdded();
Assert.assertEquals(0, getMessagesAdded(queueControl));
session.deleteQueue(queue);
}
Aggregations