// 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(TYPES, getBufferResult(sharedBuffer, 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);
// acknowledge first three pages
sharedBuffer.get(FIRST, 3, sizeOfPages(10)).cancel(true);
// 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(TYPES, getBufferResult(sharedBuffer, FIRST, 3, sizeOfPages(1), NO_WAIT), bufferResult(3, createPage(3)));
// page not acknowledged yet so sent count is the same
assertQueueState(sharedBuffer, FIRST, 8, 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, 11, 0);
assertBufferResultEquals(TYPES, getBufferResult(sharedBuffer, SECOND, 0, sizeOfPages(10), NO_WAIT), bufferResult(0, createPage(0),
createPage(1),
createPage(2),
createPage(3),
createPage(4),
createPage(5),
createPage(6),
createPage(7),
createPage(8),
createPage(9)));
// page not acknowledged yet so sent count is still zero
assertQueueState(sharedBuffer, SECOND, 11, 0);
// acknowledge the 10 pages
sharedBuffer.get(SECOND, 10, sizeOfPages(10)).cancel(true);
assertQueueState(sharedBuffer, SECOND, 1, 10);
//
// tell shared buffer there will be no more queues
outputBuffers = outputBuffers.withNoMoreBufferIds();
sharedBuffer.setOutputBuffers(outputBuffers);
// since both queues consumed the first three pages, the blocked page future from above should be done
future.get(1, TimeUnit.SECONDS);