* @throws javax.jms.JMSException if a JMS problem occurs
* @throws InterruptedException on timeout
*/
public void testDrain() throws Exception
{
QpidClientConnection conn = new QpidClientConnection(BROKER);
conn.connect();
_logger.info("consuming queue " + queue);
Queue q = conn.getSession().createQueue(queue);
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);
}
_logger.info("consuming done.");
conn.getSession().commit();
consumer.close();
int index = 0;
StringBuilder list = new StringBuilder();
list.append("Failed to receive:");
int failed = 0;
_logger.info("consumed: " + messagesReceived);
assertEquals("number of consumed messages does not match initial data", (int) numTestMessages, messagesReceived);
// with 0_10 we can have a delivery tag of 0
if (!conn.isBroker010())
{
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);
}
conn.disconnect();
passed = true;
}