Search in sources :

Example 61 with FileStatus

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

the class ViewFsBaseTest method testOwnerForInternalDir.

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

        @Override
        public Object run() throws IOException, URISyntaxException {
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            String doAsUserName = ugi.getUserName();
            assertEquals(doAsUserName, "user@HADOOP.COM");
            FileContext viewFS = FileContext.getFileContext(FsConstants.VIEWFS_URI, conf);
            FileStatus stat = viewFS.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) FileContextTestHelper.checkFileStatus(org.apache.hadoop.fs.FileContextTestHelper.checkFileStatus) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) Matchers.anyString(org.mockito.Matchers.anyString) FileContext(org.apache.hadoop.fs.FileContext) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Test(org.junit.Test)

Example 62 with FileStatus

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

the class TestDiskChecker method _mkdirs.

private void _mkdirs(boolean exists, FsPermission before, FsPermission after) throws Throwable {
    File localDir = make(stub(File.class).returning(exists).from.exists());
    when(localDir.mkdir()).thenReturn(true);
    // use default stubs
    Path dir = mock(Path.class);
    LocalFileSystem fs = make(stub(LocalFileSystem.class).returning(localDir).from.pathToFile(dir));
    FileStatus stat = make(stub(FileStatus.class).returning(after).from.getPermission());
    when(fs.getFileStatus(dir)).thenReturn(stat);
    try {
        DiskChecker.mkdirsWithExistsAndPermissionCheck(fs, dir, before);
        if (!exists)
            verify(fs).setPermission(dir, before);
        else {
            verify(fs).getFileStatus(dir);
            verify(stat).getPermission();
        }
    } catch (DiskErrorException e) {
        if (before != after)
            assertTrue(e.getMessage().startsWith("Incorrect permission"));
    }
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) LocalFileSystem(org.apache.hadoop.fs.LocalFileSystem) DiskErrorException(org.apache.hadoop.util.DiskChecker.DiskErrorException)

Example 63 with FileStatus

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

the class TestViewFsFileStatusHdfs method testFileStatusSerialziation.

@Test
public void testFileStatusSerialziation() throws IOException, URISyntaxException {
    long len = fileSystemTestHelper.createFile(fHdfs, testfilename);
    FileStatus stat = vfs.getFileStatus(new Path(testfilename));
    assertEquals(len, stat.getLen());
    // check serialization/deserialization
    DataOutputBuffer dob = new DataOutputBuffer();
    stat.write(dob);
    DataInputBuffer dib = new DataInputBuffer();
    dib.reset(dob.getData(), 0, dob.getLength());
    FileStatus deSer = new FileStatus();
    deSer.readFields(dib);
    assertEquals(len, deSer.getLen());
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) Test(org.junit.Test)

Example 64 with FileStatus

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

the class AppendTestUtil method check.

public static void check(FileSystem fs, Path p, long length) throws IOException {
    int i = -1;
    try {
        final FileStatus status = fs.getFileStatus(p);
        FSDataInputStream in = fs.open(p);
        if (in.getWrappedStream() instanceof DFSInputStream) {
            long len = ((DFSInputStream) in.getWrappedStream()).getFileLength();
            assertEquals(length, len);
        } else {
            assertEquals(length, status.getLen());
        }
        for (i++; i < length; i++) {
            assertEquals((byte) i, (byte) in.read());
        }
        i = -(int) length;
        //EOF  
        assertEquals(-1, in.read());
        in.close();
    } catch (IOException ioe) {
        throw new IOException("p=" + p + ", length=" + length + ", i=" + i, ioe);
    }
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Example 65 with FileStatus

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

the class AppendTestUtil method checkFullFile.

public static void checkFullFile(FileSystem fs, Path name, int len, final byte[] compareContent, String message, boolean checkFileStatus) throws IOException {
    if (checkFileStatus) {
        final FileStatus status = fs.getFileStatus(name);
        assertEquals("len=" + len + " but status.getLen()=" + status.getLen(), len, status.getLen());
    }
    FSDataInputStream stm = fs.open(name);
    byte[] actual = new byte[len];
    stm.readFully(0, actual);
    checkData(actual, 0, compareContent, message);
    stm.close();
}
Also used : FileStatus(org.apache.hadoop.fs.FileStatus) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream)

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