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