Search in sources :

Example 6 with Stat

use of org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat in project hadoop by apache.

the class TestNativeIO method testFstat.

@Test(timeout = 30000)
public void testFstat() throws Exception {
    FileOutputStream fos = new FileOutputStream(new File(TEST_DIR, "testfstat"));
    NativeIO.POSIX.Stat stat = NativeIO.POSIX.getFstat(fos.getFD());
    fos.close();
    LOG.info("Stat: " + String.valueOf(stat));
    String owner = stat.getOwner();
    String expectedOwner = System.getProperty("user.name");
    if (Path.WINDOWS) {
        UserGroupInformation ugi = UserGroupInformation.createRemoteUser(expectedOwner);
        final String adminsGroupString = "Administrators";
        if (Arrays.asList(ugi.getGroupNames()).contains(adminsGroupString)) {
            expectedOwner = adminsGroupString;
        }
    }
    assertEquals(expectedOwner, owner);
    assertNotNull(stat.getGroup());
    assertTrue(!stat.getGroup().isEmpty());
    assertEquals("Stat mode field should indicate a regular file", S_IFREG, stat.getMode() & S_IFMT);
}
Also used : FileOutputStream(java.io.FileOutputStream) Stat(org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) POSIX(org.apache.hadoop.io.nativeio.NativeIO.POSIX) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Aggregations

Stat (org.apache.hadoop.io.nativeio.NativeIO.POSIX.Stat)6 RandomAccessFile (java.io.RandomAccessFile)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 File (java.io.File)3 FileOutputStream (java.io.FileOutputStream)3 POSIX (org.apache.hadoop.io.nativeio.NativeIO.POSIX)3 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 Path (org.apache.hadoop.fs.Path)1 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)1