|
@@ -24,6 +24,8 @@ import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
+import org.assertj.core.api.Assertions;
|
|
|
+
|
|
|
import org.apache.hadoop.fs.FileStatus;
|
|
|
import org.apache.hadoop.fs.FileSystem;
|
|
|
import org.apache.hadoop.fs.FilterFileSystem;
|
|
@@ -148,6 +150,7 @@ public abstract class AbstractContractGetFileStatusTest extends
|
|
|
public void testComplexDirActions() throws Throwable {
|
|
|
TreeScanResults tree = createTestTree();
|
|
|
checkListStatusStatusComplexDir(tree);
|
|
|
+ checkListStatusIteratorComplexDir(tree);
|
|
|
checkListLocatedStatusStatusComplexDir(tree);
|
|
|
checkListFilesComplexDirNonRecursive(tree);
|
|
|
checkListFilesComplexDirRecursive(tree);
|
|
@@ -169,6 +172,34 @@ public abstract class AbstractContractGetFileStatusTest extends
|
|
|
listing.assertSizeEquals("listStatus()", TREE_FILES, TREE_WIDTH, 0);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Test {@link FileSystem#listStatusIterator(Path)} on a complex
|
|
|
+ * directory tree.
|
|
|
+ * @param tree directory tree to list.
|
|
|
+ * @throws Throwable
|
|
|
+ */
|
|
|
+ protected void checkListStatusIteratorComplexDir(TreeScanResults tree)
|
|
|
+ throws Throwable {
|
|
|
+ describe("Expect listStatusIterator to list all entries in top dir only");
|
|
|
+
|
|
|
+ FileSystem fs = getFileSystem();
|
|
|
+ TreeScanResults listing = new TreeScanResults(
|
|
|
+ fs.listStatusIterator(tree.getBasePath()));
|
|
|
+ listing.assertSizeEquals("listStatus()", TREE_FILES, TREE_WIDTH, 0);
|
|
|
+
|
|
|
+ List<FileStatus> resWithoutCheckingHasNext =
|
|
|
+ iteratorToListThroughNextCallsAlone(fs
|
|
|
+ .listStatusIterator(tree.getBasePath()));
|
|
|
+
|
|
|
+ List<FileStatus> resWithCheckingHasNext = iteratorToList(fs
|
|
|
+ .listStatusIterator(tree.getBasePath()));
|
|
|
+ Assertions.assertThat(resWithCheckingHasNext)
|
|
|
+ .describedAs("listStatusIterator() should return correct " +
|
|
|
+ "results even if hasNext() calls are not made.")
|
|
|
+ .hasSameElementsAs(resWithoutCheckingHasNext);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Test {@link FileSystem#listLocatedStatus(Path)} on a complex
|
|
|
* directory tree.
|
|
@@ -322,6 +353,45 @@ public abstract class AbstractContractGetFileStatusTest extends
|
|
|
verifyStatusArrayMatchesFile(f, getFileSystem().listStatus(f));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testListStatusIteratorFile() throws Throwable {
|
|
|
+ describe("test the listStatusIterator(path) on a file");
|
|
|
+ Path f = touchf("listStItrFile");
|
|
|
+
|
|
|
+ List<FileStatus> statusList = (List<FileStatus>) iteratorToList(
|
|
|
+ getFileSystem().listStatusIterator(f));
|
|
|
+ validateListingForFile(f, statusList, false);
|
|
|
+
|
|
|
+ List<FileStatus> statusList2 =
|
|
|
+ (List<FileStatus>) iteratorToListThroughNextCallsAlone(
|
|
|
+ getFileSystem().listStatusIterator(f));
|
|
|
+ validateListingForFile(f, statusList2, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Validate listing result for an input path which is file.
|
|
|
+ * @param f file.
|
|
|
+ * @param statusList list status of a file.
|
|
|
+ * @param nextCallAlone whether the listing generated just using
|
|
|
+ * next() calls.
|
|
|
+ */
|
|
|
+ private void validateListingForFile(Path f,
|
|
|
+ List<FileStatus> statusList,
|
|
|
+ boolean nextCallAlone) {
|
|
|
+ String msg = String.format("size of file list returned using %s should " +
|
|
|
+ "be 1", nextCallAlone ?
|
|
|
+ "next() calls alone" : "hasNext() and next() calls");
|
|
|
+ Assertions.assertThat(statusList)
|
|
|
+ .describedAs(msg)
|
|
|
+ .hasSize(1);
|
|
|
+ Assertions.assertThat(statusList.get(0).getPath())
|
|
|
+ .describedAs("path returned should match with the input path")
|
|
|
+ .isEqualTo(f);
|
|
|
+ Assertions.assertThat(statusList.get(0).isFile())
|
|
|
+ .describedAs("path returned should be a file")
|
|
|
+ .isEqualTo(true);
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testListFilesFile() throws Throwable {
|
|
|
describe("test the listStatus(path) on a file");
|