Search in sources :

Example 81 with FileSystem

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

the class LocalFileSystemTest method testCreatingFileInCurrentDirectoryWithRelativePath.

/**
 * This test verifies the issue https://issues.apache.org/jira/browse/FLINK-18612.
 */
@Test
public void testCreatingFileInCurrentDirectoryWithRelativePath() throws IOException {
    FileSystem fs = FileSystem.getLocalFileSystem();
    Path filePath = new Path("local_fs_test_" + RandomStringUtils.randomAlphanumeric(16));
    try (FSDataOutputStream outputStream = fs.create(filePath, WriteMode.OVERWRITE)) {
    // Do nothing.
    } finally {
        for (int i = 0; i < 10 && fs.exists(filePath); ++i) {
            fs.delete(filePath, true);
        }
    }
}
Also used : Path(org.apache.flink.core.fs.Path) FileSystem(org.apache.flink.core.fs.FileSystem) FSDataOutputStream(org.apache.flink.core.fs.FSDataOutputStream) Test(org.junit.Test)

Example 82 with FileSystem

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

the class LocalFileSystemTest method testRenameFileWithNoAccess.

@Test
public void testRenameFileWithNoAccess() throws IOException {
    final FileSystem fs = FileSystem.getLocalFileSystem();
    final File srcFile = temporaryFolder.newFile("someFile.txt");
    final File destFile = new File(temporaryFolder.newFolder(), "target");
    // we need to make the file non-modifiable so that the rename fails
    Assume.assumeTrue(srcFile.getParentFile().setWritable(false, false));
    Assume.assumeTrue(srcFile.setWritable(false, false));
    try {
        final Path srcFilePath = new Path(srcFile.toURI());
        final Path destFilePath = new Path(destFile.toURI());
        // this cannot succeed because the source folder has no permission to remove the file
        assertFalse(fs.rename(srcFilePath, destFilePath));
    } finally {
        // make sure we give permission back to ensure proper cleanup
        // noinspection ResultOfMethodCallIgnored
        srcFile.getParentFile().setWritable(true, false);
        // noinspection ResultOfMethodCallIgnored
        srcFile.setWritable(true, false);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) FileSystem(org.apache.flink.core.fs.FileSystem) File(java.io.File) Test(org.junit.Test)

Example 83 with FileSystem

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

the class FilesystemSchemeConfigTest method testDefaultsToLocal.

// ------------------------------------------------------------------------
@Test
public void testDefaultsToLocal() throws Exception {
    URI justPath = new URI(tempFolder.newFile().toURI().getPath());
    assertNull(justPath.getScheme());
    FileSystem fs = FileSystem.get(justPath);
    assertEquals("file", fs.getUri().getScheme());
}
Also used : LocalFileSystem(org.apache.flink.core.fs.local.LocalFileSystem) FileSystem(org.apache.flink.core.fs.FileSystem) URI(java.net.URI) Test(org.junit.Test)

Example 84 with FileSystem

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

the class FilesystemSchemeConfigTest method testExplicitlySetToLocal.

@Test
public void testExplicitlySetToLocal() throws Exception {
    final Configuration conf = new Configuration();
    conf.setString(CoreOptions.DEFAULT_FILESYSTEM_SCHEME, LocalFileSystem.getLocalFsURI().toString());
    FileSystem.initialize(conf);
    URI justPath = new URI(tempFolder.newFile().toURI().getPath());
    assertNull(justPath.getScheme());
    FileSystem fs = FileSystem.get(justPath);
    assertEquals("file", fs.getUri().getScheme());
}
Also used : LocalFileSystem(org.apache.flink.core.fs.local.LocalFileSystem) FileSystem(org.apache.flink.core.fs.FileSystem) URI(java.net.URI) Test(org.junit.Test)

Example 85 with FileSystem

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

the class AvroOutputFormatTest method testCompression.

@Test
public void testCompression() throws Exception {
    // given
    final Path outputPath = new Path(File.createTempFile("avro-output-file", "avro").getAbsolutePath());
    final AvroOutputFormat<User> outputFormat = new AvroOutputFormat<>(outputPath, User.class);
    outputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE);
    final Path compressedOutputPath = new Path(File.createTempFile("avro-output-file", "compressed.avro").getAbsolutePath());
    final AvroOutputFormat<User> compressedOutputFormat = new AvroOutputFormat<>(compressedOutputPath, User.class);
    compressedOutputFormat.setWriteMode(FileSystem.WriteMode.OVERWRITE);
    compressedOutputFormat.setCodec(AvroOutputFormat.Codec.SNAPPY);
    // when
    output(outputFormat);
    output(compressedOutputFormat);
    // then
    assertTrue(fileSize(outputPath) > fileSize(compressedOutputPath));
    // cleanup
    FileSystem fs = FileSystem.getLocalFileSystem();
    fs.delete(outputPath, false);
    fs.delete(compressedOutputPath, false);
}
Also used : Path(org.apache.flink.core.fs.Path) User(org.apache.flink.formats.avro.generated.User) FileSystem(org.apache.flink.core.fs.FileSystem) Test(org.junit.Test)

Aggregations

FileSystem (org.apache.flink.core.fs.FileSystem)102 Path (org.apache.flink.core.fs.Path)80 Test (org.junit.Test)49 IOException (java.io.IOException)28 File (java.io.File)24 FileStatus (org.apache.flink.core.fs.FileStatus)20 FSDataOutputStream (org.apache.flink.core.fs.FSDataOutputStream)18 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)14 URI (java.net.URI)13 LocalFileSystem (org.apache.flink.core.fs.local.LocalFileSystem)13 ArrayList (java.util.ArrayList)10 Random (java.util.Random)8 Configuration (org.apache.flink.configuration.Configuration)8 JobID (org.apache.flink.api.common.JobID)7 FileNotFoundException (java.io.FileNotFoundException)5 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)5 InputStream (java.io.InputStream)4 URISyntaxException (java.net.URISyntaxException)4 FileBaseStatistics (org.apache.flink.api.common.io.FileInputFormat.FileBaseStatistics)4 FsCheckpointStateOutputStream (org.apache.flink.runtime.state.filesystem.FsCheckpointStreamFactory.FsCheckpointStateOutputStream)4