@Override
    public void setNoMorePages()
    {
        PendingRead pendingRead;
        synchronized (this) {
            state.compareAndSet(NO_MORE_BUFFERS, FLUSHING);
            noMorePages.set(true);

            pendingRead = this.pendingRead;
            this.pendingRead = null;

            log.info("Task %s: %s pages and %s bytes was written into TempStorage", taskId, totalStoragePagesAdded.get(), totalStorageBytesAdded.get());
        }

        if (pendingRead != null) {
            processPendingRead(pendingRead);
        }

        checkFlushComplete();
    }
@Test
    public void testAddAfterNoMorePages()
    {
        SpoolingOutputBuffer buffer = createSpoolingOutputBuffer();

        for (int i = 0; i < 2; i++) {
            addPage(buffer, createPage(i));
        }
        compareTotalBuffered(buffer, 2);

        buffer.setNoMorePages();

        // should not be added
        addPage(buffer, createPage(2));
        compareTotalBuffered(buffer, 2);

        // get the two pages added
        assertBufferResultEquals(TYPES, getBufferResult(buffer, BUFFER_ID, 0, sizeOfPages(3), MAX_WAIT), bufferResult(0, createPage(0), createPage(1)));

        assertBufferResultEquals(TYPES, getBufferResult(buffer, BUFFER_ID, 2, sizeOfPages(3), NO_WAIT), emptyResults(TASK_INSTANCE_ID, 2, true));
    }