Code review comment: What is the purpose of this `currentBufferWriteBytes `?

Code under review:
void testAccumulateRecordsAndGenerateBuffers() throws IOException {
        int numBuffers = 10;
        int numRecords = 1000;
        int indexEntrySize = 16;
        TieredStorageSubpartitionId subpartitionId = new TieredStorageSubpartitionId(0);
        Random random = new Random(1234);
        TieredStorageMemoryManager tieredStorageMemoryManager =
                createStorageMemoryManager(numBuffers);

        int numExpectBytes = 0;
        int numExpectBuffers = 0;
        AtomicInteger numReceivedFinishedBuffer = new AtomicInteger(0);

        try (SortBufferAccumulator bufferAccumulator =
                new SortBufferAccumulator(1, 2, BUFFER_SIZE_BYTES, tieredStorageMemoryManager)) {
            bufferAccumulator.setup(
                    ((subpartition, buffers) ->
                            buffers.forEach(
                                    buffer -> {
                                        numReceivedFinishedBuffer.incrementAndGet();
                                        buffer.recycleBuffer();
                                    })));
            int currentBufferWriteBytes = 0;
            boolean isBroadcastForPreviousRecord = false;
            for (int i = 0; i < numRecords; i++) {
                int numBytes = random.nextInt(BUFFER_SIZE_BYTES) + 1;
                ByteBuffer record = generateRandomData(numBytes, random);
                boolean isBroadcast = random.nextBoolean();
                bufferAccumulator.receive(
                        record, subpartitionId, Buffer.DataType.DATA_BUFFER, isBroadcast);
                if (numExpectBytes + numBytes + indexEntrySize > BUFFER_SIZE_BYTES
                        || i > 0 && isBroadcastForPreviousRecord != isBroadcast) {
                    numExpectBuffers++;
                    numExpectBytes = 0;
                }

                isBroadcastForPreviousRecord = isBroadcast;
                numExpectBytes += numBytes + indexEntrySize;
                currentBufferWriteBytes += numBytes + indexEntrySize;
                if (currentBufferWriteBytes >= BUFFER_SIZE_BYTES) {
                    currentBufferWriteBytes = currentBufferWriteBytes % BUFFER_SIZE_BYTES;
                }
            }
        }

        assertThat(numExpectBytes < BUFFER_SIZE_BYTES).isTrue();
        assertThat(numReceivedFinishedBuffer.get())
                .isEqualTo(
                        numExpectBuffers
                                + numExpectBytes / BUFFER_SIZE_BYTES
                                + (numExpectBytes % BUFFER_SIZE_BYTES == 0 ? 0 : 1));
    }

Line commented on: currentBufferWriteBytes += numBytes + indexEntrySize;

Revised code:
void testAccumulateRecordsAndGenerateBuffers() throws IOException {
        int numBuffers = 10;
        int numRecords = 1000;
        int indexEntrySize = 16;
        TieredStorageSubpartitionId subpartitionId = new TieredStorageSubpartitionId(0);
        Random random = new Random(1234);
        TieredStorageMemoryManager memoryManager = createStorageMemoryManager(numBuffers);

        int numExpectBuffers = 0;
        int currentBufferWrittenBytes = 0;
        AtomicInteger numReceivedFinishedBuffer = new AtomicInteger(0);

        
        
        try (SortBufferAccumulator bufferAccumulator =
                new SortBufferAccumulator(1, 2, BUFFER_SIZE_BYTES, memoryManager)) {
            bufferAccumulator.setup(
                    ((subpartition, buffers) ->
                            buffers.forEach(
                                    buffer -> {
                                        numReceivedFinishedBuffer.incrementAndGet();
                                        buffer.recycleBuffer();
                                    })));
            boolean isBroadcastForPreviousRecord = false;
            for (int i = 0; i < numRecords; i++) {
                int numBytes = random.nextInt(BUFFER_SIZE_BYTES) + 1;
                ByteBuffer record = generateRandomData(numBytes, random);
                boolean isBroadcast = random.nextBoolean();
                bufferAccumulator.receive(
                        record, subpartitionId, Buffer.DataType.DATA_BUFFER, isBroadcast);
                if (currentBufferWrittenBytes + numBytes + indexEntrySize > BUFFER_SIZE_BYTES
                        || i > 0 && isBroadcastForPreviousRecord != isBroadcast) {
                    numExpectBuffers++;
                    currentBufferWrittenBytes = 0;
                }

                isBroadcastForPreviousRecord = isBroadcast;
                currentBufferWrittenBytes += numBytes + indexEntrySize;
            }
        }

        assertThat(currentBufferWrittenBytes).isLessThan(BUFFER_SIZE_BYTES);
        numExpectBuffers += currentBufferWrittenBytes == 0 ? 0 : 1;
        assertThat(numReceivedFinishedBuffer).hasValue(numExpectBuffers);
    }