Source:
<code>public void testDirectoriesForExclusiveAndSharedState() throws Exception { final FileSystem fs = LocalFileSystem.getSharedInstance(); final Path checkpointDir = randomTempPath(); final Path sharedStateDir = randomTempPath(); FsCheckpointStorageLocation storageLocation = new FsCheckpointStorageLocation( fs, checkpointDir, sharedStateDir, randomTempPath(), CheckpointStorageLocationReference.getDefault(), FILE_SIZE_THRESHOLD, WRITE_BUFFER_SIZE); assertNotEquals(storageLocation.getCheckpointDirectory(), storageLocation.getSharedStateDirectory()); assertEquals(0, fs.listStatus(storageLocation.getCheckpointDirectory()).length); assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length); CheckpointStateOutputStream exclusiveStream = storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE); exclusiveStream.write(new byte[FILE_SIZE_THRESHOLD + 1], 0, FILE_SIZE_THRESHOLD + 1); <START> StreamStateHandle exclusiveHandle = exclusiveStream.closeAndGetHandle(); <END> assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length); assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length); CheckpointStateOutputStream sharedStream = storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.SHARED); sharedStream.write(new byte[FILE_SIZE_THRESHOLD + 1], 0, FILE_SIZE_THRESHOLD + 1); StreamStateHandle sharedHandle = sharedStream.closeAndGetHandle(); assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length); assertEquals(1, fs.listStatus(storageLocation.getSharedStateDirectory()).length); exclusiveHandle.discardState(); sharedHandle.discardState(); }</code><technical_language>If type exclusiveStream FsCheckpointStateOutputStream, call flushToFile() directly. implicitly rely threshold logic well</technical_language>

Target:
public void testDirectoriesForExclusiveAndSharedState() throws Exception { final FileSystem fs = LocalFileSystem.getSharedInstance(); final Path checkpointDir = randomTempPath(); final Path sharedStateDir = randomTempPath(); FsCheckpointStorageLocation storageLocation = new FsCheckpointStorageLocation( fs, checkpointDir, sharedStateDir, randomTempPath(), CheckpointStorageLocationReference.getDefault(), FILE_SIZE_THRESHOLD, WRITE_BUFFER_SIZE); assertNotEquals(storageLocation.getCheckpointDirectory(), storageLocation.getSharedStateDirectory()); assertEquals(0, fs.listStatus(storageLocation.getCheckpointDirectory()).length); assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length); FsCheckpointStateOutputStream exclusiveStream = storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.EXCLUSIVE); exclusiveStream.write(42); exclusiveStream.flushToFile(); StreamStateHandle exclusiveHandle = exclusiveStream.closeAndGetHandle(); assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length); assertEquals(0, fs.listStatus(storageLocation.getSharedStateDirectory()).length); FsCheckpointStateOutputStream sharedStream = storageLocation.createCheckpointStateOutputStream(CheckpointedStateScope.SHARED); sharedStream.write(42); sharedStream.flushToFile(); StreamStateHandle sharedHandle = sharedStream.closeAndGetHandle(); assertEquals(1, fs.listStatus(storageLocation.getCheckpointDirectory()).length); assertEquals(1, fs.listStatus(storageLocation.getSharedStateDirectory()).length); exclusiveHandle.discardState(); sharedHandle.discardState(); }