use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testResetMessagesKilled.
@Test
public void testResetMessagesKilled() 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.sendMessageToDeadLetterAddress(messageID);
Assert.assertEquals(1, queueControl.getMessagesKilled());
assertMessageMetrics(queueControl, 0, durable);
message = session.createMessage(false);
producer.send(message);
// send to DLA the old-fashioned way
ClientConsumer consumer = session.createConsumer(queue);
for (int i = 0; i < server.getAddressSettingsRepository().getMatch(queue.toString()).getMaxDeliveryAttempts(); i++) {
message = consumer.receive(500);
assertNotNull(message);
message.acknowledge();
session.rollback();
}
consumer.close();
Assert.assertEquals(2, queueControl.getMessagesKilled());
queueControl.resetMessagesKilled();
Assert.assertEquals(0, queueControl.getMessagesKilled());
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetConsumerCount.
@Test
public void testGetConsumerCount() 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.getConsumerCount());
ClientConsumer consumer = session.createConsumer(queue);
Assert.assertEquals(1, queueControl.getConsumerCount());
consumer.close();
Assert.assertEquals(0, queueControl.getConsumerCount());
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testListMessageCounter.
@Test
public void testListMessageCounter() 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(100);
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(200);
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());
producer.send(session.createMessage(durable));
Thread.sleep(200);
jsonString = queueControl.listMessageCounter();
info = MessageCounterInfo.fromJSON(jsonString);
Assert.assertEquals(2, info.getDepth());
Assert.assertEquals(1, info.getDepthDelta());
Assert.assertEquals(2, info.getCount());
Assert.assertEquals(1, info.getCountDelta());
consumeMessages(2, session, queue);
Thread.sleep(200);
jsonString = queueControl.listMessageCounter();
info = MessageCounterInfo.fromJSON(jsonString);
Assert.assertEquals(0, info.getDepth());
Assert.assertEquals(-2, info.getDepthDelta());
Assert.assertEquals(2, 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 testMoveMessages2.
@Test
public void testMoveMessages2() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queueA = new SimpleString("A");
SimpleString queueB = new SimpleString("B");
SimpleString queueC = new SimpleString("C");
server.createQueue(address, RoutingType.MULTICAST, queueA, null, durable, false);
server.createQueue(address, RoutingType.MULTICAST, queueB, null, durable, false);
server.createQueue(address, RoutingType.MULTICAST, queueC, null, durable, false);
QueueControl queueControlA = createManagementControl(address, queueA);
QueueControl queueControlB = createManagementControl(address, queueB);
QueueControl queueControlC = createManagementControl(address, queueC);
// send two messages on queueA
queueControlA.sendMessage(new HashMap<String, String>(), Message.BYTES_TYPE, Base64.encodeBytes("theBody".getBytes()), true, "myUser", "myPassword");
queueControlA.sendMessage(new HashMap<String, String>(), Message.BYTES_TYPE, Base64.encodeBytes("theBody2".getBytes()), true, "myUser", "myPassword");
Wait.assertEquals(2, () -> getMessageCount(queueControlA));
Wait.assertEquals(0, () -> getMessageCount(queueControlB));
Wait.assertEquals(0, () -> getMessageCount(queueControlC));
// move 2 messages from queueA to queueB
queueControlA.moveMessages(null, queueB.toString());
Thread.sleep(500);
Wait.assertEquals(0, () -> getMessageCount(queueControlA));
Wait.assertEquals(2, () -> getMessageCount(queueControlB));
// move 1 message to queueC
queueControlA.sendMessage(new HashMap<String, String>(), Message.BYTES_TYPE, Base64.encodeBytes("theBody3".getBytes()), true, "myUser", "myPassword");
Wait.assertEquals(1, () -> getMessageCount(queueControlA));
queueControlA.moveMessages(null, queueC.toString());
Wait.assertEquals(1, () -> getMessageCount(queueControlC));
Wait.assertEquals(0, () -> getMessageCount(queueControlA));
// move all messages back to A
queueControlB.moveMessages(null, queueA.toString());
Wait.assertEquals(2, () -> getMessageCount(queueControlA));
Wait.assertEquals(0, () -> getMessageCount(queueControlB));
queueControlC.moveMessages(null, queueA.toString());
Wait.assertEquals(3, () -> getMessageCount(queueControlA));
Wait.assertEquals(0, () -> getMessageCount(queueControlC));
// consume the message from queueA
ClientConsumer consumer = session.createConsumer(queueA);
ClientMessage m1 = consumer.receive(500);
ClientMessage m2 = consumer.receive(500);
ClientMessage m3 = consumer.receive(500);
m1.acknowledge();
m2.acknowledge();
m3.acknowledge();
consumer.close();
session.deleteQueue(queueA);
session.deleteQueue(queueB);
session.deleteQueue(queueC);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetMessagesAcknowledged.
@Test
public void testGetMessagesAcknowledged() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
session.createQueue(address, RoutingType.MULTICAST, queue, null, false);
QueueControl queueControl = createManagementControl(address, queue);
Assert.assertEquals(0, queueControl.getMessagesAcknowledged());
ClientProducer producer = session.createProducer(address);
producer.send(session.createMessage(false));
consumeMessages(1, session, queue);
Assert.assertEquals(1, queueControl.getMessagesAcknowledged());
producer.send(session.createMessage(false));
consumeMessages(1, session, queue);
Assert.assertEquals(2, queueControl.getMessagesAcknowledged());
// ManagementTestBase.consumeMessages(2, session, queue);
// Assert.assertEquals(2, getMessagesAdded(queueControl));
session.deleteQueue(queue);
}
Aggregations