int NUMBER_OF_MESSAGES = 100;
for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++)
{
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[512]);
producerA.send(msg);
producerB.send(msg);
}
session.commit(); // commit was called to clean the buffer only (making sure everything is on the server side)
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_A).isPaging());
Assert.assertFalse(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());
for (int i = 0; i < NUMBER_MESSAGES_BEFORE_PAGING; i++)
{
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[512]);
producerA.send(msg);
producerB.send(msg);
}
session.commit(); // commit was called to clean the buffer only (making sure everything is on the server side)
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_A).isPaging());
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());
for (int i = NUMBER_MESSAGES_BEFORE_PAGING * 2; i < NUMBER_OF_MESSAGES; i++)
{
ClientMessage msg = session.createMessage(true);
msg.getBodyBuffer().writeBytes(new byte[512]);
producerA.send(msg);
producerB.send(msg);
}
session.close();
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_A).isPaging());
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());
session = sf.createSession(null, null, false, true, true, false, 0);
session.start();
ClientConsumer consumerA = session.createConsumer(PAGED_ADDRESS_A);
ClientConsumer consumerB = session.createConsumer(PAGED_ADDRESS_B);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
{
ClientMessage msg = consumerA.receive(5000);
Assert.assertNotNull("Couldn't receive a message on consumerA, iteration = " + i, msg);
msg.acknowledge();
}
Assert.assertNull(consumerA.receiveImmediate());
consumerA.close();
Assert.assertTrue(server.getPostOffice().getPagingManager().getPageStore(PAGED_ADDRESS_B).isPaging());
for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
{
ClientMessage msg = consumerB.receive(5000);
Assert.assertNotNull(msg);
msg.acknowledge();
session.commit();
}
Assert.assertNull(consumerB.receiveImmediate());