Search in sources :

Example 96 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class TestFind method createPathData.

private PathData createPathData(String name) throws IOException {
    Path path = new Path(name);
    FileStatus fstat = mock(FileStatus.class);
    when(fstat.getPath()).thenReturn(path);
    when(fstat.toString()).thenReturn("fileStatus:" + name);
    when(mockFs.getFileStatus(eq(path))).thenReturn(fstat);
    PathData item = new PathData(path.toString(), conf);
    return item;
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) PathData(org.apache.hadoop.fs.shell.PathData)

Example 97 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class ViewFileSystemBaseTest method testListOnInternalDirsOfMountTableInternal.

private void testListOnInternalDirsOfMountTableInternal(boolean located) throws IOException {
    // list on Slash
    FileStatus[] dirPaths = listStatusInternal(located, new Path("/"));
    FileStatus fs;
    verifyRootChildren(dirPaths);
    // list on internal dir
    dirPaths = listStatusInternal(located, new Path("/internalDir"));
    Assert.assertEquals(2, dirPaths.length);
    fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/internalDir2", dirPaths);
    Assert.assertNotNull(fs);
    Assert.assertTrue("A mount should appear as symlink", fs.isDirectory());
    fs = fileSystemTestHelper.containsPath(fsView, "/internalDir/linkToDir2", dirPaths);
    Assert.assertNotNull(fs);
    Assert.assertTrue("A mount should appear as symlink", fs.isSymlink());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Example 98 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class ViewFileSystemBaseTest method testCheckOwnerWithFileStatus.

@Test
public void testCheckOwnerWithFileStatus() throws IOException, InterruptedException {
    final UserGroupInformation userUgi = UserGroupInformation.createUserForTesting("user@HADOOP.COM", new String[] { "hadoop" });
    userUgi.doAs(new PrivilegedExceptionAction<Object>() {

        @Override
        public Object run() throws IOException {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            String doAsUserName = ugi.getUserName();
            assertEquals(doAsUserName, "user@HADOOP.COM");
            FileSystem vfs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
            FileStatus stat = vfs.getFileStatus(new Path("/internalDir"));
            assertEquals(userUgi.getShortUserName(), stat.getOwner());
            return null;
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) IOException(java.io.IOException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 99 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class ViewFileSystemBaseTest method testCreateNonRecursive.

@Test
public void testCreateNonRecursive() throws IOException {
    Path path = fileSystemTestHelper.getTestRootPath(fsView, "/user/foo");
    fsView.createNonRecursive(path, false, 1024, (short) 1, 1024L, null);
    FileStatus status = fsView.getFileStatus(new Path("/user/foo"));
    Assert.assertTrue("Created file should be type file", fsView.isFile(new Path("/user/foo")));
    Assert.assertTrue("Target of created file should be type file", fsTarget.isFile(new Path(targetTestRoot, "user/foo")));
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) Test(org.junit.Test)

Example 100 with FileStatus

use of org.apache.hadoop.fs.FileStatus in project hadoop by apache.

the class ViewFileSystemBaseTest method testListOnMountTargetDirsInternal.

private void testListOnMountTargetDirsInternal(boolean located) throws IOException {
    final Path dataPath = new Path("/data");
    FileStatus[] dirPaths = listStatusInternal(located, dataPath);
    FileStatus fs;
    Assert.assertEquals(0, dirPaths.length);
    // add a file
    long len = fileSystemTestHelper.createFile(fsView, "/data/foo");
    dirPaths = listStatusInternal(located, dataPath);
    Assert.assertEquals(1, dirPaths.length);
    fs = fileSystemTestHelper.containsPath(fsView, "/data/foo", dirPaths);
    Assert.assertNotNull(fs);
    Assert.assertTrue("Created file shoudl appear as a file", fs.isFile());
    Assert.assertEquals(len, fs.getLen());
    // add a dir
    fsView.mkdirs(fileSystemTestHelper.getTestRootPath(fsView, "/data/dirX"));
    dirPaths = listStatusInternal(located, dataPath);
    Assert.assertEquals(2, dirPaths.length);
    fs = fileSystemTestHelper.containsPath(fsView, "/data/foo", dirPaths);
    Assert.assertNotNull(fs);
    Assert.assertTrue("Created file shoudl appear as a file", fs.isFile());
    fs = fileSystemTestHelper.containsPath(fsView, "/data/dirX", dirPaths);
    Assert.assertNotNull(fs);
    Assert.assertTrue("Created dir should appear as a dir", fs.isDirectory());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus)

Aggregations

FileStatus (org.apache.hadoop.fs.FileStatus)1156 Path (org.apache.hadoop.fs.Path)910 FileSystem (org.apache.hadoop.fs.FileSystem)417 Test (org.junit.Test)372 IOException (java.io.IOException)296 Configuration (org.apache.hadoop.conf.Configuration)187 ArrayList (java.util.ArrayList)175 FileNotFoundException (java.io.FileNotFoundException)136 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)105 FsPermission (org.apache.hadoop.fs.permission.FsPermission)86 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)67 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)65 HashMap (java.util.HashMap)54 File (java.io.File)41 URI (java.net.URI)41 PathFilter (org.apache.hadoop.fs.PathFilter)38 BufferedReader (java.io.BufferedReader)30 InputStreamReader (java.io.InputStreamReader)30 BlockLocation (org.apache.hadoop.fs.BlockLocation)30 HdfsFileStatus (org.apache.hadoop.hdfs.protocol.HdfsFileStatus)30