@Override
    public Optional<ReadableRegion> getReadableRegion(
            int subpartitionId, int bufferIndex, int consumingOffset) {
        synchronized (lock) {
            return getInternalRegion(subpartitionId, bufferIndex)
                    .map(
                            internalRegion ->
                                    internalRegion.toReadableRegion(bufferIndex, consumingOffset))
                    .filter(internalRegion -> internalRegion.numReadable > 0);
        }
    }
@Test
    void testGetReadableRegion() {
        final int subpartitionId = 0;

        hsDataIndex.addBuffers(createSpilledBuffers(subpartitionId, Arrays.asList(0, 1, 3, 4, 5)));
        hsDataIndex.markBufferReleased(subpartitionId, 1);
        hsDataIndex.markBufferReleased(subpartitionId, 3);
        hsDataIndex.markBufferReleased(subpartitionId, 4);

        assertThat(hsDataIndex.getReadableRegion(subpartitionId, 1, 0))
                .hasValueSatisfying(
                        readableRegion -> {
                            assertRegionStartWithTargetBufferIndex(readableRegion, 1);
                            // Readable region will not include discontinuous buffer.
                            assertThat(readableRegion.numReadable).isEqualTo(1);
                        });
        assertThat(hsDataIndex.getReadableRegion(subpartitionId, 3, 0))
                .hasValueSatisfying(
                        readableRegion -> {
                            assertRegionStartWithTargetBufferIndex(readableRegion, 3);
                            assertThat(readableRegion.numReadable)
                                    .isGreaterThanOrEqualTo(1)
                                    .isLessThanOrEqualTo(2);
                        });
        assertThat(hsDataIndex.getReadableRegion(subpartitionId, 4, 0))
                .hasValueSatisfying(
                        readableRegion -> {
                            assertRegionStartWithTargetBufferIndex(readableRegion, 4);
                            assertThat(readableRegion.numReadable).isEqualTo(1);
                        });
    }