message.putIntProperty(new SimpleString("id"), i);
// Consume messages to force an eventual out of order delivery
if (i == 5)
{
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
for (int j = 0; j < numberOfMessages; j++)
{
ClientMessage msg = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
msg.acknowledge();
assertEquals(j, msg.getIntProperty("id").intValue());
assertFalse(msg.getBooleanProperty("new"));
Assert.assertNotNull(msg);
}
ClientMessage msgReceived = consumer.receiveImmediate();
if (msgReceived != null)
{
System.out.println("new = " + msgReceived.getBooleanProperty("new") +
" id = " +
msgReceived.getIntProperty("id"));
}
Assert.assertNull(msgReceived);
consumer.close();
}
Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));
Assert.assertNotNull(messageID);
Assert.assertEquals(messageID.intValue(), i);
producerTransacted.send(message);
}
ClientConsumer consumer = session.createConsumer(PagingTest.ADDRESS);
Assert.assertNull(consumer.receiveImmediate());
sessionTransacted.commit();
sessionTransacted.close();
for (int i = 0; i < 10; i++)
{
message = consumer.receive(PagingTest.RECEIVE_TIMEOUT);
Assert.assertNotNull(message);
Integer messageID = (Integer)message.getObjectProperty(new SimpleString("id"));
// System.out.println(messageID);
Assert.assertNotNull(messageID);
Assert.assertEquals("message received out of order", i, messageID.intValue());
message.acknowledge();
}
Assert.assertNull(consumer.receiveImmediate());
consumer.close();
session.close();
sf.close();