@Override
    public long getPos() throws IOException {
        // The starting position is not determined until a physical file has been assigned, so
        // we return the relative value to the starting position in this method
        return bufferPos + curPosRelative;
    }
@Test
    public void testGetPos() throws Exception {
        FileMergingCheckpointStateOutputStream stream = getNewStream();

        // write one byte one time
        for (int i = 0; i < 64; ++i) {
            assertThat(stream.getPos()).isEqualTo(i);
            stream.write(0x42);
        }

        stream.closeAndGetHandle();

        // write random number of bytes one time
        stream = getNewStream();

        Random rnd = new Random();
        long expectedPos = 0;
        for (int i = 0; i < 7; ++i) {
            int numBytes = rnd.nextInt(16);
            expectedPos += numBytes;
            stream.write(new byte[numBytes]);
            assertThat(stream.getPos()).isEqualTo(expectedPos);
        }

        physicalFileCanBeReused = true;
        SegmentFileStateHandle stateHandle = stream.closeAndGetHandle();

        // reuse the last physical file
        assertThat(stateHandle).isNotNull();
        expectedPos = 0;
        stream = getNewStream(true);
        stream.flushToFile();
        for (int i = 0; i < 7; ++i) {
            int numBytes = rnd.nextInt(16);
            expectedPos += numBytes;
            stream.write(new byte[numBytes]);
            assertThat(stream.getPos()).isEqualTo(expectedPos);
        }

        stream.closeAndGetHandle();
    }