}
public void testBufferMultipleLargeMessages() throws Exception
{
ClientSession session = null;
HornetQServer server = null;
final int SIZE = 10 * 1024;
final int NUMBER_OF_MESSAGES = 30;
try
{
server = createServer(true, isNetty());
server.start();
locator.setMinLargeMessageSize(1024);
locator.setConsumerWindowSize(1024 * 1024);
ClientSessionFactory sf = locator.createSessionFactory();
session = sf.createSession(null, null, false, false, false, false, 0);
session.createQueue(LargeMessageTest.ADDRESS, LargeMessageTest.ADDRESS, null, true);
ClientProducer producer = session.createProducer(LargeMessageTest.ADDRESS);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
{
ClientMessage clientFile = session.createMessage(true);
clientFile.setBodyInputStream(UnitTestCase.createFakeLargeStream(SIZE));
producer.send(clientFile);
}
session.commit();
producer.close();
session.start();
ClientConsumerInternal consumer = (ClientConsumerInternal)session.createConsumer(LargeMessageTest.ADDRESS);
// Wait the consumer to be complete with 10 messages before getting others
long timeout = System.currentTimeMillis() + 10000;
while (consumer.getBufferSize() < NUMBER_OF_MESSAGES && timeout > System.currentTimeMillis())
{
Thread.sleep(10);
}
Assert.assertEquals(NUMBER_OF_MESSAGES, consumer.getBufferSize());
// Reads the messages, rollback.. read them again
for (int trans = 0; trans < 2; trans++)
{
for (int i = 0; i < NUMBER_OF_MESSAGES; i++)
{
ClientMessage msg = consumer.receive(10000);
Assert.assertNotNull(msg);
// it will ignore the buffer (not read it) on the first try
if (trans == 0)
{
for (int byteRead = 0; byteRead < SIZE; byteRead++)
{
Assert.assertEquals(UnitTestCase.getSamplebyte(byteRead), msg.getBodyBuffer().readByte());
}
}
msg.acknowledge();
}
if (trans == 0)
{
session.rollback();
}
else
{
session.commit();
}
}
Assert.assertEquals(0,
((Queue)server.getPostOffice().getBinding(LargeMessageTest.ADDRESS).getBindable()).getDeliveringCount());
Assert.assertEquals(0,
((Queue)server.getPostOffice().getBinding(LargeMessageTest.ADDRESS).getBindable()).getMessageCount());
}
finally
{
try
{
session.close();
}
catch (Throwable ignored)
{
}
try
{
server.stop();
}
catch (Throwable ignored)
{
}
}