server.start();
final int messageSize = 1024;
ServerLocator locator = null;
ClientSessionFactory sf = null;
ClientSession session = null;
try
{
locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(true);
sf = locator.createSessionFactory();
session = sf.createSession(false, false, false);
session.createQueue(ADDRESS, ADDRESS, true);
session.createQueue("DLA", "DLA");
PagingStore pgStoreAddress = server.getPagingManager().getPageStore(ADDRESS);
pgStoreAddress.startPaging();
PagingStore pgStoreDLA = server.getPagingManager().getPageStore(new SimpleString("DLA"));
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
for (int i = 0; i < 100; i++)
{
log.debug("send message #" + i);
ClientMessage message = session.createMessage(true);
message.putStringProperty("id", "str" + i);
message.setBodyInputStream(createFakeLargeStream(messageSize));
producer.send(message);
if ((i + 1) % 2 == 0)
{
session.commit();
}
}
session.commit();
session.start();
ClientConsumer cons = session.createConsumer(ADDRESS);
for (int msgNr = 0; msgNr < 2; msgNr++)
{
for (int i = 0; i < 5; i++)
{
ClientMessage msg = cons.receive(5000);
assertNotNull(msg);
msg.acknowledge();
assertEquals("str" + msgNr, msg.getStringProperty("id"));
for (int j = 0; j < messageSize; j++)
{
assertEquals(getSamplebyte(j), msg.getBodyBuffer().readByte());
}
session.rollback();
}
pgStoreDLA.startPaging();
}
for (int i = 2; i < 100; i++)
{
log.debug("Received message " + i);
ClientMessage message = cons.receive(5000);
assertNotNull("Message " + i + " wasn't received", message);
message.acknowledge();
final AtomicInteger bytesOutput = new AtomicInteger(0);
message.setOutputStream(new OutputStream()
{
@Override
public void write(int b) throws IOException
{
bytesOutput.incrementAndGet();
}
});
try
{
if (!message.waitOutputStreamCompletion(10000))
{
log.info(threadDump("dump"));
fail("Couldn't finish large message receiving");
}
}
catch (Throwable e)
{
log.info("output bytes = " + bytesOutput);
log.info(threadDump("dump"));
fail("Couldn't finish large message receiving for id=" + message.getStringProperty("id") +
" with messageID=" +
message.getMessageID());
}
}
assertNull(cons.receiveImmediate());
cons.close();
cons = session.createConsumer("DLA");
for (int i = 0; i < 2; i++)
{
assertNotNull(cons.receive(5000));
}
sf.close();
session.close();
locator.close();
server.stop();
server.start();
locator = createInVMNonHALocator();
sf = locator.createSessionFactory();
session = sf.createSession(false, false);
session.start();
cons = session.createConsumer(ADDRESS);
for (int i = 2; i < 100; i++)
{
log.debug("Received message " + i);
ClientMessage message = cons.receive(5000);
assertNotNull(message);
assertEquals("str" + i, message.getStringProperty("id"));
message.acknowledge();
message.setOutputStream(new OutputStream()
{
@Override
public void write(int b) throws IOException
{
}
});
assertTrue(message.waitOutputStreamCompletion(5000));
}
assertNull(cons.receiveImmediate());
cons.close();
cons = session.createConsumer("DLA");
for (int msgNr = 0; msgNr < 2; msgNr++)
{
ClientMessage msg = cons.receive(10000);
assertNotNull(msg);
assertEquals("str" + msgNr, msg.getStringProperty("id"));
for (int i = 0; i < messageSize; i++)
{
assertEquals(getSamplebyte(i), msg.getBodyBuffer().readByte());
}
msg.acknowledge();
}
cons.close();
cons = session.createConsumer(ADDRESS);
session.commit();
assertNull(cons.receiveImmediate());
long timeout = System.currentTimeMillis() + 5000;
pgStoreAddress = server.getPagingManager().getPageStore(ADDRESS);
pgStoreAddress.getCursorProvier().getSubscription(server.locateQueue(ADDRESS).getID()).cleanupEntries();
pgStoreAddress.getCursorProvier().cleanup();
while (timeout > System.currentTimeMillis() && pgStoreAddress.isPaging())
{
Thread.sleep(50);
}
assertFalse(pgStoreAddress.isPaging());
session.commit();
}
finally
{
session.close();
sf.close();
locator.close();
try
{
server.stop();
}