@Override
    public boolean tryWrite(
            TieredStorageSubpartitionId subpartitionId,
            Buffer finishedBuffer,
            Object bufferOwner,
            int numRemainingConsecutiveBuffers) {
        int subpartitionIndex = subpartitionId.getSubpartitionId();
        if (currentSubpartitionWriteBuffers[subpartitionIndex] != 0
                && currentSubpartitionWriteBuffers[subpartitionIndex]
                                + 1
                                + numRemainingConsecutiveBuffers
                        > numBuffersPerSegment) {
            appendEndOfSegmentEvent(subpartitionIndex);
            currentSubpartitionWriteBuffers[subpartitionIndex] = 0;
            return false;
        }
        Buffer compressedBuffer = compressBufferIfPossible(finishedBuffer, bufferCompressor);
        if (compressedBuffer.isBuffer()) {
            memoryManager.transferBufferOwnership(
                    bufferOwner, getMemoryTierName(), compressedBuffer);
        }
        currentSubpartitionWriteBuffers[subpartitionIndex]++;
        addFinishedBuffer(compressedBuffer, subpartitionIndex);
        return true;
    }
@Test
    void testTryWrite() {
        try (MemoryTierProducerAgent memoryTierProducerAgent =
                createMemoryTierProducerAgent(
                        false, BUFFER_SIZE, new TieredStorageResourceRegistry())) {
            memoryTierProducerAgent.connectionEstablished(
                    SUBPARTITION_ID, new TestingNettyConnectionWriter.Builder().build());
            assertThat(
                            memoryTierProducerAgent.tryWrite(
                                    SUBPARTITION_ID,
                                    BufferBuilderTestUtils.buildSomeBuffer(),
                                    this,
                                    0))
                    .isTrue();
            assertThat(
                            memoryTierProducerAgent.tryWrite(
                                    SUBPARTITION_ID,
                                    BufferBuilderTestUtils.buildSomeBuffer(),
                                    this,
                                    0))
                    .isFalse();
        }
    }