serverManager.createQueue(false, otherQueueName, null, true, otherQueueName);
HornetQDestination otherQueue = (HornetQDestination)HornetQJMSClient.createQueue(otherQueueName);
ServerLocator locator = createInVMNonHALocator();
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(true, true);
ClientProducer prod1 = session.createProducer(queue.getAddress());
ClientProducer prod2 = session.createProducer(otherQueue.getAddress());
for (int i = 0; i < 10; i++)
{
ClientMessage msg = session.createMessage(true);
msg.putStringProperty(org.hornetq.api.core.Message.HDR_DUPLICATE_DETECTION_ID, new SimpleString("dupl-" + i));
prod1.send(msg);
if (i < 5)
{
prod2.send(msg);
}
}
session.commit();
JMSQueueControl queueControl = createManagementControl();
JMSQueueControl otherQueueControl = ManagementControlHelper.createJMSQueueControl((HornetQQueue)otherQueue,
mbeanServer);
Assert.assertEquals(10, queueControl.getMessageCount());
int moved = queueControl.moveMessages(null, otherQueueName, true);
assertEquals(10, moved);
assertEquals(0, queueControl.getDeliveringCount());
session.start();
ClientConsumer cons1 = session.createConsumer(queue.getAddress());
assertNull(cons1.receiveImmediate());
cons1.close();
ClientConsumer cons2 = session.createConsumer(otherQueue.getAddress());
for (int i = 0; i < 10; i++)
{
ClientMessage msg = cons2.receive(10000);
assertNotNull(msg);
msg.acknowledge();
}
cons2.close();
session.close();
sf.close();
locator.close();
Assert.assertEquals(0, queueControl.getMessageCount());