use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testMoveMessageToUnknownQueue.
@Test
public void testMoveMessageToUnknownQueue() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString queue = RandomUtil.randomSimpleString();
SimpleString unknownQueue = 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));
QueueControl queueControl = createManagementControl(address, queue);
assertMessageMetrics(queueControl, 1, durable);
// 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");
// moved all messages to unknown queue
try {
queueControl.moveMessage(messageID, unknownQueue.toString());
Assert.fail("operation must fail if the other queue does not exist");
} catch (Exception e) {
}
Assert.assertEquals(1, getMessageCount(queueControl));
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 testChangeMessagePriority.
@Test
public void testChangeMessagePriority() throws Exception {
byte originalPriority = (byte) 1;
byte newPriority = (byte) 8;
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);
message.setPriority(originalPriority);
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");
boolean priorityChanged = queueControl.changeMessagePriority(messageID, newPriority);
Assert.assertTrue(priorityChanged);
ClientConsumer consumer = session.createConsumer(queue);
ClientMessage m = consumer.receive(500);
Assert.assertNotNull(m);
Assert.assertEquals(newPriority, 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 testMoveMessagesBack.
@Test
public void testMoveMessagesBack() throws Exception {
server.createQueue(new SimpleString("q1"), RoutingType.MULTICAST, new SimpleString("q1"), null, durable, false);
server.createQueue(new SimpleString("q2"), RoutingType.MULTICAST, new SimpleString("q2"), null, durable, false);
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = createSessionFactory(locator);
ClientSession session = sf.createSession(true, true);
ClientProducer prod1 = session.createProducer("q1");
for (int i = 0; i < 10; i++) {
ClientMessage msg = session.createMessage(durable);
msg.putStringProperty(Message.HDR_DUPLICATE_DETECTION_ID, new SimpleString("dupl-" + i));
prod1.send(msg);
}
session.commit();
ClientConsumer consumer = session.createConsumer("q1", true);
session.start();
assertNotNull(consumer.receive(5000));
consumer.close();
QueueControl q1Control = ManagementControlHelper.createQueueControl(new SimpleString("q1"), new SimpleString("q1"), mbeanServer);
QueueControl q2Control = ManagementControlHelper.createQueueControl(new SimpleString("q2"), new SimpleString("q2"), mbeanServer);
assertEquals(10, q1Control.moveMessages(null, "q2"));
consumer = session.createConsumer("q2", true);
assertNotNull(consumer.receive(500));
consumer.close();
q2Control.moveMessages(null, "q1", false);
session.start();
consumer = session.createConsumer("q1");
for (int i = 0; i < 10; i++) {
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
msg.acknowledge();
}
consumer.close();
session.deleteQueue("q1");
session.deleteQueue("q2");
session.close();
locator.close();
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testGetFirstMessage.
@Test
public void testGetFirstMessage() 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));
// It's empty, so it's supposed to be like this
assertEquals("[{}]", queueControl.getFirstMessageAsJSON());
long beforeSend = System.currentTimeMillis();
ClientProducer producer = session.createProducer(address);
producer.send(session.createMessage(false).putStringProperty("x", "valueX").putStringProperty("y", "valueY"));
System.out.println("first:" + queueControl.getFirstMessageAsJSON());
long firstMessageTimestamp = queueControl.getFirstMessageTimestamp();
System.out.println("first message timestamp: " + firstMessageTimestamp);
assertTrue(beforeSend <= firstMessageTimestamp);
assertTrue(firstMessageTimestamp <= System.currentTimeMillis());
long firstMessageAge = queueControl.getFirstMessageAge();
System.out.println("first message age: " + firstMessageAge);
assertTrue(firstMessageAge <= (System.currentTimeMillis() - firstMessageTimestamp));
session.deleteQueue(queue);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testMoveMessage.
@Test
public void testMoveMessage() 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 2 messages on queue
producer.send(session.createMessage(durable));
producer.send(session.createMessage(durable));
QueueControl queueControl = createManagementControl(address, queue);
QueueControl otherQueueControl = createManagementControl(otherAddress, otherQueue);
assertMessageMetrics(queueControl, 2, durable);
assertMessageMetrics(otherQueueControl, 0, 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");
boolean moved = queueControl.moveMessage(messageID, otherQueue.toString());
Assert.assertTrue(moved);
assertMessageMetrics(queueControl, 1, durable);
assertMessageMetrics(otherQueueControl, 1, durable);
consumeMessages(1, session, queue);
consumeMessages(1, session, otherQueue);
session.deleteQueue(queue);
session.deleteQueue(otherQueue);
}
Aggregations