locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(true);
ClientSessionFactory sf = locator.createSessionFactory();
ClientSession session = sf.createSession(false, false, false);
session.createQueue(ADDRESS.toString(), "q1", true);
session.createQueue(ADDRESS.toString(), "q2", true);
ClientProducer producer = session.createProducer(PagingTest.ADDRESS);
ClientMessage message = null;
byte[] body = new byte[messageSize];
ByteBuffer bb = ByteBuffer.wrap(body);
for (int j = 1; j <= messageSize; j++)
{
bb.put(getSamplebyte(j));
}
for (int i = 0; i < numberOfMessages; i++)
{
message = session.createMessage(true);
HornetQBuffer bodyLocal = message.getBodyBuffer();
bodyLocal.writeBytes(body);
message.putIntProperty(new SimpleString("id"), i);
producer.send(message);
if (i % messagesPerTX == 0)
{
session.commit();
}
}
session.commit();
session.close();
}
finally
{
try
{
server.stop();
}
catch (Throwable ignored)
{
}
}
ArrayList<RecordInfo> records = new ArrayList<RecordInfo>();
List<PreparedTransactionInfo> list = new ArrayList<PreparedTransactionInfo>();
JournalImpl jrn = new JournalImpl(config.getJournalFileSize(),
2,
0,
0,
new NIOSequentialFileFactory(getJournalDir()),
"hornetq-data",
"hq",
1);
jrn.start();
jrn.load(records, list, null);
// Delete everything from the journal
for (RecordInfo info : records)
{
if (!info.isUpdate)
{
jrn.appendDeleteRecord(info.id, false);
}
}
jrn.stop();
server = createServer(true,
config,
PagingTest.PAGE_SIZE,
PagingTest.PAGE_MAX,
new HashMap<String, AddressSettings>());
server.start();
Page pg = server.getPagingManager().getPageStore(ADDRESS).getCurrentPage();
pg.open();
List<PagedMessage> msgs = pg.read(server.getStorageManager());
pg.close();
long queues[] = new long[] { server.locateQueue(new SimpleString("q1")).getID() };
for (long q : queues)
{
for (int i = 0; i < msgs.size(); i++)
{
server.getStorageManager().storeCursorAcknowledge(q, new PagePositionImpl(pg.getPageId(), i));
}
}
server.stop();
ServerLocator locator = createInVMNonHALocator();
locator.setBlockOnNonDurableSend(true);
locator.setBlockOnDurableSend(true);
locator.setBlockOnAcknowledge(true);
server = createServer(true,
config,
PagingTest.PAGE_SIZE,
PagingTest.PAGE_MAX,
new HashMap<String, AddressSettings>());
server.start();
ClientSessionFactory csf = locator.createSessionFactory();
ClientSession sess = csf.createSession();
sess.start();
ClientConsumer cons = sess.createConsumer("q1");
assertNull(cons.receive(500));
Thread.sleep(5000);
ClientConsumer cons2 = sess.createConsumer("q2");
assertNull(cons2.receive(500));
long timeout = System.currentTimeMillis() + 5000;
while (System.currentTimeMillis() < timeout && server.getPagingManager().getPageStore(ADDRESS).isPaging())
{
Thread.sleep(100);
}
assertFalse(server.getPagingManager().getPageStore(ADDRESS).isPaging());
sess.close();
locator.close();
server.stop();
}