@Override public FileStatus next() throws IOException { if (!hasNext) { throw new NoSuchElementException(); } hasNext = false; return getFileStatus(absolutePath); } };
@Test public void testGetFileStatusForUnaccessibleDirectory() throws IOException { doThrow(new AccessControlException()).when(mockRemoteFS).getFileStatus(new Path("/foo/baz")); Path path = new Path("/foo/baz"); try { fs.getFileStatus(path); fail("Expected some IOException"); } catch(AccessControlException e) { // ignore } }
@Test public void testGetFileStatusWithUnknownRemotePath() throws IOException { Path path = new Path("/tmp/10.0.0.3@file"); try { fs.getFileStatus(path); fail("Expected getFileStatus to throw FileNotFoundException"); } catch (FileNotFoundException e) { // ok } }
@Test public void testGetFileStatusForInvalidPath() throws IOException { Path path = new Path("/foo/baz"); try { fs.getFileStatus(path); fail("Expected getFileStatus to throw FileNotFoundException"); } catch (FileNotFoundException e) { } }
@Test public void testGetFileStatusWithLocalPath() throws IOException { try { Path path = new Path("/tmp/file"); @SuppressWarnings("unused") FileStatus status = fs.getFileStatus(path); fail("Expected getFileStatus call to throw an exception"); } catch (IOException e) { // ok } }
@Test public void testGetFileStatusForValidDirectory() throws IOException { Path path = new Path("/foo/bar"); FileStatus status = fs.getFileStatus(path); assertEquals(new Path("pdfs:/foo/bar"), status.getPath()); assertTrue(status.isDirectory()); assertEquals(69, status.getModificationTime()); assertEquals(90, status.getAccessTime()); }
@Test public void testGetFileStatusRoot() throws IOException { Path root = new Path("/"); FileStatus status = fs.getFileStatus(root); assertEquals(new Path("pdfs:/"), status.getPath()); assertTrue(status.isDirectory()); assertEquals(0555, status.getPermission().toExtendedShort()); }
@Test public void testGetFileStatusWithValidRemotePath() throws IOException { doReturn(new FileStatus(1024, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", new Path("sabot://10.0.0.2:1234/tmp/file"))) .when(mockRemoteFS).getFileStatus(new Path("/tmp/file")); Path path = new Path("/tmp/10.0.0.2@file"); FileStatus status = fs.getFileStatus(path); // getFileStatus returns qualified path assertEquals(new Path("pdfs:/tmp/10.0.0.2@file"), status.getPath()); assertFalse(status.isDirectory()); assertEquals(1024, status.getLen()); assertEquals(1, status.getReplication()); assertEquals(4096, status.getBlockSize()); assertEquals(42, status.getAccessTime()); assertEquals(37, status.getModificationTime()); assertEquals("root", status.getOwner()); assertEquals("wheel", status.getGroup()); assertEquals(0644, status.getPermission().toExtendedShort()); }
@Test public void testGetFileStatusWithValidLocalPath() throws IOException { Path tmpPath = new Path("/tmp/file"); doReturn(new FileStatus(1024, false, 1, 4096, 37, 42, FsPermission.createImmutable((short) 0644), "root", "wheel", tmpPath)).when(mockLocalFS).getFileStatus(tmpPath); Path path = new Path("/tmp/10.0.0.1@file"); FileStatus status = fs.getFileStatus(path); assertEquals(new Path("pdfs:/tmp/10.0.0.1@file"), status.getPath()); assertFalse(status.isDirectory()); assertEquals(1024, status.getLen()); assertEquals(1, status.getReplication()); assertEquals(4096, status.getBlockSize()); assertEquals(42, status.getAccessTime()); assertEquals(37, status.getModificationTime()); assertEquals("root", status.getOwner()); assertEquals("wheel", status.getGroup()); assertEquals(0644, status.getPermission().toExtendedShort()); }