use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class ContractTestUtils method assertIsDirectory.
/**
* Assert that a path refers to a directory.
* @param fs filesystem
* @param path path of the directory
* @throws IOException on File IO problems
*/
public static void assertIsDirectory(FileSystem fs, Path path) throws IOException {
FileStatus fileStatus = fs.getFileStatus(path);
assertIsDirectory(fileStatus);
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class ContractTestUtils method assertIsFile.
/**
* Assert that a file exists and whose {@link FileStatus} entry
* declares that this is a file and not a symlink or directory.
* @param fileSystem filesystem to resolve path against
* @param filename name of the file
* @throws IOException IO problems during file operations
*/
public static void assertIsFile(FileSystem fileSystem, Path filename) throws IOException {
assertPathExists(fileSystem, "Expected file", filename);
FileStatus status = fileSystem.getFileStatus(filename);
assertIsFile(filename, status);
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class TestChRootedFileSystem method testList.
@Test
public void testList() throws IOException {
FileStatus fs = fSys.getFileStatus(new Path("/"));
Assert.assertTrue(fs.isDirectory());
// should return the full path not the chrooted path
Assert.assertEquals(fs.getPath(), chrootedTo);
// list on Slash
FileStatus[] dirPaths = fSys.listStatus(new Path("/"));
Assert.assertEquals(0, dirPaths.length);
fileSystemTestHelper.createFile(fSys, "/foo");
fileSystemTestHelper.createFile(fSys, "/bar");
fSys.mkdirs(new Path("/dirX"));
fSys.mkdirs(fileSystemTestHelper.getTestRootPath(fSys, "/dirY"));
fSys.mkdirs(new Path("/dirX/dirXX"));
dirPaths = fSys.listStatus(new Path("/"));
// note 2 crc files
Assert.assertEquals(4, dirPaths.length);
// Note the the file status paths are the full paths on target
fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "foo"), dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isFile());
fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "bar"), dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isFile());
fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "dirX"), dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isDirectory());
fs = FileSystemTestHelper.containsPath(new Path(chrootedTo, "dirY"), dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isDirectory());
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class TestChRootedFs method testList.
@Test
public void testList() throws IOException {
FileStatus fs = fc.getFileStatus(new Path("/"));
Assert.assertTrue(fs.isDirectory());
// should return the full path not the chrooted path
Assert.assertEquals(fs.getPath(), chrootedTo);
// list on Slash
FileStatus[] dirPaths = fc.util().listStatus(new Path("/"));
Assert.assertEquals(0, dirPaths.length);
fileContextTestHelper.createFileNonRecursive(fc, "/foo");
fileContextTestHelper.createFileNonRecursive(fc, "/bar");
fc.mkdir(new Path("/dirX"), FileContext.DEFAULT_PERM, false);
fc.mkdir(fileContextTestHelper.getTestRootPath(fc, "/dirY"), FileContext.DEFAULT_PERM, false);
fc.mkdir(new Path("/dirX/dirXX"), FileContext.DEFAULT_PERM, false);
dirPaths = fc.util().listStatus(new Path("/"));
Assert.assertEquals(4, dirPaths.length);
// Note the the file status paths are the full paths on target
fs = fileContextTestHelper.containsPath(fcTarget, "foo", dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isFile());
fs = fileContextTestHelper.containsPath(fcTarget, "bar", dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isFile());
fs = fileContextTestHelper.containsPath(fcTarget, "dirX", dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isDirectory());
fs = fileContextTestHelper.containsPath(fcTarget, "dirY", dirPaths);
Assert.assertNotNull(fs);
Assert.assertTrue(fs.isDirectory());
}
use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.
the class AbstractContractGetFileStatusTest method testListStatusFiltering.
@Test
public void testListStatusFiltering() throws Throwable {
describe("Call listStatus() against paths and directories with filtering");
Path file1 = touchf("file-1.txt");
touchf("file-2.txt");
Path parent = file1.getParent();
FileStatus[] result;
verifyListStatus(0, parent, NO_PATHS);
verifyListStatus(2, parent, ALL_PATHS);
MatchesNameFilter file1Filter = new MatchesNameFilter("file-1.txt");
result = verifyListStatus(1, parent, file1Filter);
assertEquals(file1, result[0].getPath());
verifyListStatus(0, file1, NO_PATHS);
result = verifyListStatus(1, file1, ALL_PATHS);
assertEquals(file1, result[0].getPath());
result = verifyListStatus(1, file1, file1Filter);
assertEquals(file1, result[0].getPath());
// empty subdirectory
Path subdir = path("subdir");
mkdirs(subdir);
verifyListStatus(0, subdir, NO_PATHS);
verifyListStatus(0, subdir, ALL_PATHS);
verifyListStatus(0, subdir, new MatchesNameFilter("subdir"));
}
Aggregations