int numberOfPages = addMessages(NUM_MESSAGES, 1024 * 1024);
System.out.println("NumberOfPages = " + numberOfPages);
PageCursorProvider cursorProvider = lookupCursorProvider();
PageCache cache = cursorProvider.getPageCache(new PagePositionImpl(5, 0));
PageSubscription cursor = cursorProvider.getSubscription(queue.getID());
PagePosition startingPos = new PagePositionImpl(5, cache.getNumberOfMessages() / 2);
cursor.bookmark(startingPos);
// We can't proceed until the operation has finished
server.getStorageManager().waitOnOperations();
PagedMessage msg = cache.getMessage(startingPos.getMessageNr() + 1);
msg.initMessage(server.getStorageManager());
int initialKey = msg.getMessage().getIntProperty("key").intValue();
int key = initialKey;
msg = null;
cache = null;
LinkedListIterator<PagedReference> iterator = cursor.iterator();
PagedReference msgCursor = null;
while ((msgCursor = iterator.next()) != null)
{
assertEquals(key++, msgCursor.getMessage().getIntProperty("key").intValue());
}
assertEquals(NUM_MESSAGES, key);
server.stop();
OperationContextImpl.clearContext();
createServer();
cursorProvider = lookupCursorProvider();
cursor = cursorProvider.getSubscription(queue.getID());
key = initialKey;
iterator = cursor.iterator();
while ((msgCursor = iterator.next()) != null)
{
assertEquals(key++, msgCursor.getMessage().getIntProperty("key").intValue());
cursor.ack(msgCursor);
}
forceGC();
assertTrue(cursorProvider.getCacheSize() < numberOfPages);
server.stop();
createServer();
waitCleanup();
assertEquals(1, lookupPageStore(ADDRESS).getNumberOfPages());