Search in sources :

Example 51 with FileStatus

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

the class BaseTestHttpFSWith method assertSameListing.

private static void assertSameListing(FileSystem expected, FileSystem actual, Path p) throws IOException {
    // Consume all the entries from both iterators
    RemoteIterator<FileStatus> exIt = expected.listStatusIterator(p);
    List<FileStatus> exStatuses = new ArrayList<>();
    while (exIt.hasNext()) {
        exStatuses.add(exIt.next());
    }
    RemoteIterator<FileStatus> acIt = actual.listStatusIterator(p);
    List<FileStatus> acStatuses = new ArrayList<>();
    while (acIt.hasNext()) {
        acStatuses.add(acIt.next());
    }
    assertEquals(exStatuses.size(), acStatuses.size());
    for (int i = 0; i < exStatuses.size(); i++) {
        FileStatus expectedStatus = exStatuses.get(i);
        FileStatus actualStatus = acStatuses.get(i);
        // Path URIs are fully qualified, so compare just the path component
        assertEquals(expectedStatus.getPath().toUri().getPath(), actualStatus.getPath().toUri().getPath());
    }
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) ArrayList(java.util.ArrayList)

Example 52 with FileStatus

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

the class BaseTestHttpFSWith method testEncryption.

private void testEncryption() throws Exception {
    if (isLocalFS()) {
        return;
    }
    FileSystem proxyFs = FileSystem.get(getProxiedFSConf());
    FileSystem httpFs = getHttpFSFileSystem();
    FileStatus proxyStatus = proxyFs.getFileStatus(TestHdfsHelper.ENCRYPTED_FILE);
    assertTrue(proxyStatus.isEncrypted());
    FileStatus httpStatus = httpFs.getFileStatus(TestHdfsHelper.ENCRYPTED_FILE);
    assertTrue(httpStatus.isEncrypted());
    proxyStatus = proxyFs.getFileStatus(new Path("/"));
    httpStatus = httpFs.getFileStatus(new Path("/"));
    assertFalse(proxyStatus.isEncrypted());
    assertFalse(httpStatus.isEncrypted());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem)

Example 53 with FileStatus

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

the class BaseTestHttpFSWith method assertSameAclBit.

private static void assertSameAclBit(FileSystem expected, FileSystem actual, Path path) throws IOException {
    FileStatus expectedFileStatus = expected.getFileStatus(path);
    FileStatus actualFileStatus = actual.getFileStatus(path);
    assertEquals(actualFileStatus.getPermission().getAclBit(), expectedFileStatus.getPermission().getAclBit());
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus)

Example 54 with FileStatus

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

the class BaseTestHttpFSWith method testSetTimes.

private void testSetTimes() throws Exception {
    if (!isLocalFS()) {
        FileSystem fs = FileSystem.get(getProxiedFSConf());
        Path path = new Path(getProxiedFSTestDir(), "foo.txt");
        OutputStream os = fs.create(path);
        os.write(1);
        os.close();
        FileStatus status1 = fs.getFileStatus(path);
        fs.close();
        long at = status1.getAccessTime();
        long mt = status1.getModificationTime();
        fs = getHttpFSFileSystem();
        fs.setTimes(path, mt - 10, at - 20);
        fs.close();
        fs = FileSystem.get(getProxiedFSConf());
        status1 = fs.getFileStatus(path);
        fs.close();
        long atNew = status1.getAccessTime();
        long mtNew = status1.getModificationTime();
        assertEquals(mtNew, mt - 10);
        assertEquals(atNew, at - 20);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream)

Example 55 with FileStatus

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

the class BaseTestHttpFSWith method testSetPermission.

protected void testSetPermission() throws Exception {
    FileSystem fs = FileSystem.get(getProxiedFSConf());
    Path path = new Path(getProxiedFSTestDir(), "foodir");
    fs.mkdirs(path);
    fs = getHttpFSFileSystem();
    FsPermission permission1 = new FsPermission(FsAction.READ_WRITE, FsAction.NONE, FsAction.NONE);
    fs.setPermission(path, permission1);
    fs.close();
    fs = FileSystem.get(getProxiedFSConf());
    FileStatus status1 = fs.getFileStatus(path);
    fs.close();
    FsPermission permission2 = status1.getPermission();
    assertEquals(permission2, permission1);
    //sticky bit
    fs = getHttpFSFileSystem();
    permission1 = new FsPermission(FsAction.READ_WRITE, FsAction.NONE, FsAction.NONE, true);
    fs.setPermission(path, permission1);
    fs.close();
    fs = FileSystem.get(getProxiedFSConf());
    status1 = fs.getFileStatus(path);
    fs.close();
    permission2 = status1.getPermission();
    assertTrue(permission2.getStickyBit());
    assertEquals(permission2, permission1);
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) FileSystem(org.apache.hadoop.fs.FileSystem) FsPermission(org.apache.hadoop.fs.permission.FsPermission)

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