*/
public void testDrain() throws JMSException, InterruptedException
{
final String queueName = "direct://amq.direct//queue" + UUID.randomUUID().toString();
QpidClientConnection conn = new QpidClientConnection(BROKER);
conn.connect();
// clear queue
conn.consume(queueName, consumeTimeout);
// load test data
_logger.info("creating test data, " + numTestMessages + " messages");
conn.put(queueName, payload, numTestMessages);
// close this connection
conn.disconnect();
conn = new QpidClientConnection(BROKER);
conn.connect();
_logger.info("consuming queue " + queueName);
Queue q = conn.getSession().createQueue(queueName);
final MessageConsumer consumer = conn.getSession().createConsumer(q);
int messagesReceived = 0;
long[] messageLog = new long[numTestMessages + 1];
_logger.info("consuming...");
Message msg = consumer.receive(1000);
while (msg != null)
{
messagesReceived++;
long dt = ((AbstractJMSMessage) msg).getDeliveryTag();
int msgindex = msg.getIntProperty("index");
if (messageLog[msgindex] != 0)
{
_logger.error("Received Message(" + msgindex + ":" + ((AbstractJMSMessage) msg).getDeliveryTag()
+ ") more than once.");
}
if (_logger.isInfoEnabled())
{
_logger.info("Received Message(" + System.identityHashCode(msgindex) + ") " + "DT:" + dt + "IN:" + msgindex);
}
if (dt == 0)
{
_logger.error("DT is zero for msg:" + msgindex);
}
messageLog[msgindex] = dt;
// get Next message
msg = consumer.receive(1000);
}
conn.getSession().commit();
consumer.close();
assertEquals("number of consumed messages does not match initial data", (int) numTestMessages, messagesReceived);
int index = 0;
StringBuilder list = new StringBuilder();
list.append("Failed to receive:");
int failed = 0;
for (long b : messageLog)
{
if ((b == 0) && (index != 0)) // delivery tag of zero shouldn't exist
{
_logger.error("Index: " + index + " was not received.");
list.append(" ");
list.append(index);
list.append(":");
list.append(b);
failed++;
}
index++;
}
assertEquals(list.toString(), 0, failed);
_logger.info("consumed: " + messagesReceived);
conn.disconnect();
passed = true;
}