Search in sources :

Example 31 with FSDataOutputStream

use of org.apache.flink.core.fs.FSDataOutputStream in project flink by apache.

the class FileSystemBlobStoreTest method fileSystemBlobStoreCallsSyncOnPut.

@Test
public void fileSystemBlobStoreCallsSyncOnPut(@TempDir Path storageDirectory) throws IOException {
    final Path blobStoreDirectory = storageDirectory.resolve("blobStore");
    final AtomicReference<TestingLocalDataOutputStream> createdOutputStream = new AtomicReference<>();
    final FunctionWithException<org.apache.flink.core.fs.Path, FSDataOutputStream, IOException> outputStreamFactory = value -> {
        final File file = new File(value.toString());
        FileUtils.createParentDirectories(file);
        final TestingLocalDataOutputStream outputStream = new TestingLocalDataOutputStream(file);
        createdOutputStream.compareAndSet(null, outputStream);
        return outputStream;
    };
    try (FileSystemBlobStore fileSystemBlobStore = new FileSystemBlobStore(new TestFs(outputStreamFactory), blobStoreDirectory.toString())) {
        final BlobKey blobKey = BlobKey.createKey(BlobKey.BlobType.PERMANENT_BLOB);
        final File localFile = storageDirectory.resolve("localFile").toFile();
        FileUtils.createParentDirectories(localFile);
        FileUtils.writeStringToFile(localFile, "foobar", StandardCharsets.UTF_8);
        fileSystemBlobStore.put(localFile, new JobID(), blobKey);
        assertThat(createdOutputStream.get().hasSyncBeenCalled()).isTrue();
    }
}
Also used : Path(java.nio.file.Path) TestFs(org.apache.flink.runtime.state.filesystem.TestFs) BeforeEach(org.junit.jupiter.api.BeforeEach) MessageDigest(java.security.MessageDigest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicReference(java.util.concurrent.atomic.AtomicReference) TestLoggerExtension(org.apache.flink.util.TestLoggerExtension) FSDataOutputStream(org.apache.flink.core.fs.FSDataOutputStream) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) FunctionWithException(org.apache.flink.util.function.FunctionWithException) TestFileSystem(org.apache.flink.testutils.TestFileSystem) Path(java.nio.file.Path) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) FileUtils(org.apache.commons.io.FileUtils) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) LocalDataOutputStream(org.apache.flink.core.fs.local.LocalDataOutputStream) Preconditions(org.apache.flink.util.Preconditions) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) JobID(org.apache.flink.api.common.JobID) TempDir(org.junit.jupiter.api.io.TempDir) InputStream(java.io.InputStream) TestFs(org.apache.flink.runtime.state.filesystem.TestFs) AtomicReference(java.util.concurrent.atomic.AtomicReference) IOException(java.io.IOException) FSDataOutputStream(org.apache.flink.core.fs.FSDataOutputStream) File(java.io.File) JobID(org.apache.flink.api.common.JobID) Test(org.junit.jupiter.api.Test)

Aggregations

FSDataOutputStream (org.apache.flink.core.fs.FSDataOutputStream)31 Path (org.apache.flink.core.fs.Path)24 FileSystem (org.apache.flink.core.fs.FileSystem)17 Test (org.junit.Test)16 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)10 IOException (java.io.IOException)8 File (java.io.File)7 Random (java.util.Random)5 LocalFileSystem (org.apache.flink.core.fs.local.LocalFileSystem)5 InputStream (java.io.InputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 FileStatus (org.apache.flink.core.fs.FileStatus)4 DataOutputStream (java.io.DataOutputStream)3 Map (java.util.Map)3 LocalDataOutputStream (org.apache.flink.core.fs.local.LocalDataOutputStream)3 BufferedReader (java.io.BufferedReader)2 EOFException (java.io.EOFException)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Arrays (java.util.Arrays)2