ServerLocator locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(true);
ClientSessionFactory sf = locator.createSessionFactory();
byte[] body = new byte[messageSize];
ClientSession sessionTransacted = sf.createSession(null, null, false, false, false, false, 0);
ClientProducer producerTransacted = sessionTransacted.createProducer(PagingTest.ADDRESS);
ClientSession session = sf.createSession(null, null, false, true, true, false, 0);
session.createQueue(PagingTest.ADDRESS, PagingTest.ADDRESS, null, true);
ClientMessage firstMessage = sessionTransacted.createMessage(IS_DURABLE_MESSAGE);
firstMessage.getBodyBuffer().writeBytes(body);
firstMessage.putIntProperty(new SimpleString("id"), 0);
producerTransacted.send(firstMessage);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
int numberOfMessages = 0;
while (true)
{
message = session.createMessage(IS_DURABLE_MESSAGE);
message.getBodyBuffer().writeBytes(body);
message.putIntProperty("id", numberOfMessages);
message.putBooleanProperty("new", false);
// Stop sending message as soon as we start paging
if (server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging())
{
break;
}
numberOfMessages++;
producer.send(message);
}
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PagingTest.ADDRESS).isPaging());
session.start();
for (int i = 1; i < 10; i++)
{
message = session.createMessage(true);
message.getBodyBuffer().writeBytes(body);
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();
locator.close();
}
finally
{