long unmatchingValue = matchingValue + 1;
String filter = "key = " + matchingValue;
String deadLetterQueue = RandomUtil.randomString();
serverManager.createQueue(false, deadLetterQueue, null, true, deadLetterQueue);
HornetQQueue dlq = (HornetQQueue)HornetQJMSClient.createQueue(deadLetterQueue);
Connection conn = createConnection();
Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
// send 2 messages on queue
JMSUtil.sendMessageWithProperty(sess, queue, key, matchingValue);
JMSUtil.sendMessageWithProperty(sess, queue, key, unmatchingValue);
JMSQueueControl queueControl = createManagementControl();
JMSQueueControl dlqControl = ManagementControlHelper.createJMSQueueControl(dlq, mbeanServer);
Assert.assertEquals(2, queueControl.getMessageCount());
Assert.assertEquals(0, dlqControl.getMessageCount());
queueControl.setDeadLetterAddress(dlq.getAddress());
int deadMessageCount = queueControl.sendMessagesToDeadLetterAddress(filter);
Assert.assertEquals(1, deadMessageCount);
Assert.assertEquals(1, queueControl.getMessageCount());
Assert.assertEquals(1, dlqControl.getMessageCount());