@Override
    public void destroy()
    {
        PendingRead pendingRead;
        synchronized (this) {
            if (state.setIf(FINISHED, oldState -> !oldState.isTerminal())) {
                close();
            }
            pendingRead = this.pendingRead;
            this.pendingRead = null;
        }

        if (pendingRead != null) {
            pendingRead.completeResultFutureWithEmpty();
        }
    }
@Test
    public void testAddAfterDestroy()
    {
        SpoolingOutputBuffer buffer = createSpoolingOutputBuffer();

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

        buffer.destroy();

        // nothing in buffer
        compareTotalBuffered(buffer, 0);

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

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