Example usage for org.apache.hadoop.hdfs DFSTestUtil getFileSystemAs

List of usage examples for org.apache.hadoop.hdfs DFSTestUtil getFileSystemAs

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs DFSTestUtil getFileSystemAs.

Prototype

static public FileSystem getFileSystemAs(UserGroupInformation ugi, final Configuration conf)
        throws IOException 

Source Link

Document

Get a FileSystem instance as specified user in a doAs block.

Usage

From source file:com.mellanox.r4h.TestReadWhileWriting.java

License:Apache License

static void checkFile(Path p, int expectedsize, final Configuration conf)
        throws IOException, InterruptedException {
    //open the file with another user account
    final String username = UserGroupInformation.getCurrentUser().getShortUserName() + "_" + ++userCount;

    UserGroupInformation ugi = UserGroupInformation.createUserForTesting(username,
            new String[] { "supergroup" });

    final FileSystem fs = DFSTestUtil.getFileSystemAs(ugi, conf);

    final HdfsDataInputStream in = (HdfsDataInputStream) fs.open(p);

    //Check visible length
    Assert.assertTrue(in.getVisibleLength() >= expectedsize);

    //Able to read?
    for (int i = 0; i < expectedsize; i++) {
        Assert.assertEquals((byte) i, (byte) in.read());
    }/*from  w w w  . ja  v  a  2s . c om*/

    in.close();
}

From source file:org.apache.sentry.tests.e2e.hdfs.TestHDFSIntegration.java

License:Apache License

private void verifyAccessToPath(String user, String group, String path, boolean hasPermission)
        throws Exception {
    Path p = new Path(path);
    UserGroupInformation hadoopUser = UserGroupInformation.createUserForTesting(user, new String[] { group });
    FileSystem fs = DFSTestUtil.getFileSystemAs(hadoopUser, hadoopConf);
    try {//from w  ww.  j  a v  a  2 s. co  m
        fs.listFiles(p, true);
        if (!hasPermission) {
            Assert.assertFalse("Expected listing files to fail", false);
        }
    } catch (Exception e) {
        if (hasPermission) {
            throw e;
        }
    }
}