|
31 | 31 | import static org.mockito.ArgumentMatchers.eq; |
32 | 32 | import static org.mockito.Mockito.inOrder; |
33 | 33 | import static org.mockito.Mockito.mock; |
| 34 | +import static org.mockito.Mockito.spy; |
34 | 35 |
|
35 | 36 | import java.io.File; |
36 | 37 | import java.io.FileNotFoundException; |
|
123 | 124 | import org.apache.hadoop.util.DataChecksum; |
124 | 125 | import org.apache.hadoop.util.Time; |
125 | 126 | import org.apache.hadoop.util.concurrent.HadoopExecutors; |
| 127 | +import org.apache.hadoop.util.functional.RemoteIterators; |
126 | 128 | import org.junit.Assert; |
127 | 129 | import org.junit.Test; |
128 | 130 | import org.mockito.InOrder; |
| 131 | +import org.mockito.Mockito; |
129 | 132 | import org.slf4j.Logger; |
130 | 133 | import org.slf4j.LoggerFactory; |
131 | 134 | import org.slf4j.event.Level; |
@@ -1557,6 +1560,33 @@ public void testListFiles() throws IOException { |
1557 | 1560 | } |
1558 | 1561 | } |
1559 | 1562 |
|
| 1563 | + @Test |
| 1564 | + public void testListFilesRecursive() throws IOException { |
| 1565 | + Configuration conf = getTestConfiguration(); |
| 1566 | + |
| 1567 | + try (MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).build();) { |
| 1568 | + DistributedFileSystem fs = cluster.getFileSystem(); |
| 1569 | + |
| 1570 | + // Create some directories and files. |
| 1571 | + Path dir = new Path("/dir"); |
| 1572 | + Path subDir1 = fs.makeQualified(new Path(dir, "subDir1")); |
| 1573 | + Path subDir2 = fs.makeQualified(new Path(dir, "subDir2")); |
| 1574 | + |
| 1575 | + fs.mkdirs(subDir1); |
| 1576 | + fs.mkdirs(subDir2); |
| 1577 | + fs.create(new Path(dir, "foo1")).close(); |
| 1578 | + fs.create(new Path(dir, "foo2")).close(); |
| 1579 | + fs.create(new Path(subDir1, "foo3")).close(); |
| 1580 | + fs.create(new Path(subDir2, "foo4")).close(); |
| 1581 | + |
| 1582 | + // Mock the filesystem, and throw FNF when listing is triggered for the subdirectory. |
| 1583 | + FileSystem mockFs = spy(fs); |
| 1584 | + Mockito.doThrow(new FileNotFoundException("")).when(mockFs).listLocatedStatus(eq(subDir1)); |
| 1585 | + List<LocatedFileStatus> str = RemoteIterators.toList(mockFs.listFiles(dir, true)); |
| 1586 | + Assert.assertEquals(str.toString(), 3, str.size()); |
| 1587 | + } |
| 1588 | + } |
| 1589 | + |
1560 | 1590 | @Test |
1561 | 1591 | public void testListStatusOfSnapshotDirs() throws IOException { |
1562 | 1592 | MiniDFSCluster cluster = new MiniDFSCluster.Builder(getTestConfiguration()) |
|
0 commit comments