// add three items
for (int i = 0; i < 3; i++) {
addPage(sharedBuffer, createPage(i));
}
OutputBuffers outputBuffers = INITIAL_EMPTY_OUTPUT_BUFFERS.withBuffer("first", new UnpartitionedPagePartitionFunction());
// add a queue
sharedBuffer.setOutputBuffers(outputBuffers);
assertQueueState(sharedBuffer, "first", 3, 0);
// get the three elements
assertBufferResultEquals(sharedBuffer.get("first", 0, sizeOfPages(10), NO_WAIT), bufferResult(0, createPage(0), createPage(1), createPage(2)));
// pages not acknowledged yet so state is the same
assertQueueState(sharedBuffer, "first", 3, 0);
// try to get some more pages (acknowledge first three pages)
assertBufferResultEquals(sharedBuffer.get("first", 3, sizeOfPages(10), NO_WAIT), emptyResults(3, false));
// pages now acknowledged
assertQueueState(sharedBuffer, "first", 0, 3);
// fill the buffer (we already added 3 pages)
for (int i = 3; i < 10; i++) {
addPage(sharedBuffer, createPage(i));
}
assertQueueState(sharedBuffer, "first", 7, 3);
// try to add one more page, which should block
ListenableFuture<?> future = enqueuePage(sharedBuffer, createPage(10));
// remove a page
assertBufferResultEquals(sharedBuffer.get("first", 3, sizeOfPages(1), NO_WAIT), bufferResult(3, createPage(3)));
// page not acknowledged yet so state is the same
assertQueueState(sharedBuffer, "first", 7, 3);
// we should still be blocked
assertFalse(future.isDone());
//
// add another buffer and verify it sees all pages
outputBuffers = outputBuffers.withBuffer("second", new UnpartitionedPagePartitionFunction());
sharedBuffer.setOutputBuffers(outputBuffers);
assertQueueState(sharedBuffer, "second", 10, 0);
assertBufferResultEquals(sharedBuffer.get("second", 0, sizeOfPages(10), NO_WAIT), bufferResult(0, createPage(0),
createPage(1),
createPage(2),