@Override
    public void sync() throws IOException {
        lock();
        try {
            fileStream.flush();
            openNewPartIfNecessary(userDefinedMinPartSize);
            Committer committer = upload.snapshotAndGetCommitter();
            committer.commitAfterRecovery();
            closeForCommit();
        } finally {
            unlock();
        }
    }
@Test(expected = Exception.class)
    public void testSync() throws IOException {
        streamUnderTest.write(bytesOf("hello"));
        streamUnderTest.write(bytesOf(" world"));
        streamUnderTest.sync();
        assertThat(multipartUploadUnderTest, hasContent(bytesOf("hello world")));
        streamUnderTest.write(randomBuffer(RefCountedBufferingFileStream.BUFFER_SIZE + 1));
        assertThat(multipartUploadUnderTest, hasContent(bytesOf("hello world")));
    }