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);
}
}
}
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);
}
}
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());
}
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());
}
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);
}
Aggregations