use of org.apache.hadoop.fs.FileSystem in project hadoop by apache.
the class AbstractContractRenameTest method testRenameWithNonEmptySubDir.
@Test
public void testRenameWithNonEmptySubDir() throws Throwable {
final Path renameTestDir = path("testRenameWithNonEmptySubDir");
final Path srcDir = new Path(renameTestDir, "src1");
final Path srcSubDir = new Path(srcDir, "sub");
final Path finalDir = new Path(renameTestDir, "dest");
FileSystem fs = getFileSystem();
boolean renameRemoveEmptyDest = isSupported(RENAME_REMOVE_DEST_IF_EMPTY_DIR);
rm(fs, renameTestDir, true, false);
fs.mkdirs(srcDir);
fs.mkdirs(finalDir);
writeTextFile(fs, new Path(srcDir, "source.txt"), "this is the file in src dir", false);
writeTextFile(fs, new Path(srcSubDir, "subfile.txt"), "this is the file in src/sub dir", false);
assertPathExists("not created in src dir", new Path(srcDir, "source.txt"));
assertPathExists("not created in src/sub dir", new Path(srcSubDir, "subfile.txt"));
fs.rename(srcDir, finalDir);
// Accept both POSIX rename behavior and CLI rename behavior
if (renameRemoveEmptyDest) {
// POSIX rename behavior
assertPathExists("not renamed into dest dir", new Path(finalDir, "source.txt"));
assertPathExists("not renamed into dest/sub dir", new Path(finalDir, "sub/subfile.txt"));
} else {
// CLI rename behavior
assertPathExists("not renamed into dest dir", new Path(finalDir, "src1/source.txt"));
assertPathExists("not renamed into dest/sub dir", new Path(finalDir, "src1/sub/subfile.txt"));
}
assertPathDoesNotExist("not deleted", new Path(srcDir, "source.txt"));
}
use of org.apache.hadoop.fs.FileSystem in project hadoop by apache.
the class AbstractContractCreateTest method testCreatedFileIsVisibleOnFlush.
@Test
public void testCreatedFileIsVisibleOnFlush() throws Throwable {
describe("verify that a newly created file exists once a flush has taken " + "place");
Path path = path("testCreatedFileIsVisibleOnFlush");
FileSystem fs = getFileSystem();
try (FSDataOutputStream out = fs.create(path, false, 4096, (short) 1, 1024)) {
out.write('a');
out.flush();
if (!fs.exists(path)) {
if (isSupported(IS_BLOBSTORE)) {
// object store: downgrade to a skip so that the failure is visible
// in test results
skip("Filesystem is an object store and newly created files are not " + "immediately visible");
}
assertPathExists("expected path to be visible before file closed", path);
}
}
}
use of org.apache.hadoop.fs.FileSystem in project hadoop by apache.
the class AbstractContractCreateTest method testFileStatusBlocksizeEmptyFile.
@Test
public void testFileStatusBlocksizeEmptyFile() throws Throwable {
describe("check that an empty file may return a 0-byte blocksize");
FileSystem fs = getFileSystem();
Path path = path("testFileStatusBlocksizeEmptyFile");
ContractTestUtils.touch(fs, path);
validateBlockSize(fs, path, 0);
}
use of org.apache.hadoop.fs.FileSystem in project hadoop by apache.
the class TestChRootedFileSystem method testSetStoragePolicy.
@Test(timeout = 30000)
public void testSetStoragePolicy() throws Exception {
Path storagePolicyPath = new Path("/storagePolicy");
Path chRootedStoragePolicyPath = new Path("/a/b/storagePolicy");
Configuration conf = new Configuration();
conf.setClass("fs.mockfs.impl", MockFileSystem.class, FileSystem.class);
URI chrootUri = URI.create("mockfs://foo/a/b");
ChRootedFileSystem chrootFs = new ChRootedFileSystem(chrootUri, conf);
FileSystem mockFs = ((FilterFileSystem) chrootFs.getRawFileSystem()).getRawFileSystem();
chrootFs.setStoragePolicy(storagePolicyPath, "HOT");
verify(mockFs).setStoragePolicy(chRootedStoragePolicyPath, "HOT");
}
use of org.apache.hadoop.fs.FileSystem in project hadoop by apache.
the class TestChRootedFileSystem method testGetStoragePolicy.
@Test(timeout = 30000)
public void testGetStoragePolicy() throws Exception {
Path storagePolicyPath = new Path("/storagePolicy");
Path chRootedStoragePolicyPath = new Path("/a/b/storagePolicy");
Configuration conf = new Configuration();
conf.setClass("fs.mockfs.impl", MockFileSystem.class, FileSystem.class);
URI chrootUri = URI.create("mockfs://foo/a/b");
ChRootedFileSystem chrootFs = new ChRootedFileSystem(chrootUri, conf);
FileSystem mockFs = ((FilterFileSystem) chrootFs.getRawFileSystem()).getRawFileSystem();
chrootFs.getStoragePolicy(storagePolicyPath);
verify(mockFs).getStoragePolicy(chRootedStoragePolicyPath);
}
Aggregations