use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class QueueControlTest method testMoveMessagesBack2.
@Test
public void testMoveMessagesBack2() 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");
int NUMBER_OF_MSGS = 10;
for (int i = 0; i < NUMBER_OF_MSGS; 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(NUMBER_OF_MSGS, q1Control.moveMessages(null, "q2"));
long[] messageIDs = new long[NUMBER_OF_MSGS];
consumer = session.createConsumer("q2", true);
for (int i = 0; i < NUMBER_OF_MSGS; i++) {
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
messageIDs[i] = msg.getMessageID();
}
assertNull(consumer.receiveImmediate());
consumer.close();
for (int i = 0; i < NUMBER_OF_MSGS; i++) {
q2Control.moveMessage(messageIDs[i], "q1");
}
session.start();
consumer = session.createConsumer("q1");
for (int i = 0; i < NUMBER_OF_MSGS; i++) {
ClientMessage msg = consumer.receive(5000);
assertNotNull(msg);
msg.acknowledge();
}
consumer.close();
session.deleteQueue("q1");
session.deleteQueue("q2");
session.close();
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCreateAndDestroyQueue_2.
@Test
public void testCreateAndDestroyQueue_2() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString name = RandomUtil.randomSimpleString();
String filter = "color = 'green'";
boolean durable = true;
ActiveMQServerControl serverControl = createManagementControl();
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
serverControl.createAddress(address.toString(), "ANYCAST");
serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), filter, durable, -1, false, false);
checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
Assert.assertEquals(address.toString(), queueControl.getAddress());
Assert.assertEquals(name.toString(), queueControl.getName());
Assert.assertEquals(filter, queueControl.getFilter());
Assert.assertEquals(durable, queueControl.isDurable());
Assert.assertEquals(false, queueControl.isTemporary());
serverControl.destroyQueue(name.toString());
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class ActiveMQServerControlTest method testCreateAndDestroyQueue_3.
@Test
public void testCreateAndDestroyQueue_3() throws Exception {
SimpleString address = RandomUtil.randomSimpleString();
SimpleString name = RandomUtil.randomSimpleString();
boolean durable = true;
ActiveMQServerControl serverControl = createManagementControl();
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
serverControl.createAddress(address.toString(), "ANYCAST");
serverControl.createQueue(address.toString(), "ANYCAST", name.toString(), null, durable, -1, false, false);
checkResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
QueueControl queueControl = ManagementControlHelper.createQueueControl(address, name, RoutingType.ANYCAST, mbeanServer);
Assert.assertEquals(address.toString(), queueControl.getAddress());
Assert.assertEquals(name.toString(), queueControl.getName());
Assert.assertNull(queueControl.getFilter());
Assert.assertEquals(durable, queueControl.isDurable());
Assert.assertEquals(false, queueControl.isTemporary());
serverControl.destroyQueue(name.toString());
checkNoResource(ObjectNameBuilder.DEFAULT.getQueueObjectName(address, name, RoutingType.ANYCAST));
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class BridgeTestBase method removeAllMessages.
protected void removeAllMessages(final String queueName, final int index) throws Exception {
ManagementService managementService = server0.getManagementService();
if (index == 1) {
managementService = server1.getManagementService();
}
QueueControl queueControl = (QueueControl) managementService.getResource("queue." + queueName);
queueControl.removeMessages(null);
}
use of org.apache.activemq.artemis.api.core.management.QueueControl in project activemq-artemis by apache.
the class AdvisoryOpenWireTest method testTempQueueLeak.
@Test
public void testTempQueueLeak() throws Exception {
Connection connection = null;
try {
connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
TemporaryQueue temporaryQueue = session.createTemporaryQueue();
temporaryQueue.delete();
Object[] queueResources = server.getManagementService().getResources(QueueControl.class);
for (Object queueResource : queueResources) {
if (((QueueControl) queueResource).getAddress().equals("ActiveMQ.Advisory.TempQueue")) {
QueueControl queueControl = (QueueControl) queueResource;
Wait.waitFor(() -> queueControl.getMessageCount() == 0);
assertNotNull("addressControl for temp advisory", queueControl);
Wait.assertEquals(0, queueControl::getMessageCount);
Wait.assertEquals(2, queueControl::getMessagesAdded);
}
}
} finally {
if (connection != null) {
connection.close();
}
}
}
Aggregations