This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new bf01924cc7a HDDS-14828. Extract listStatus tests to 
OzoneFileSystemTestBase (#9917)
bf01924cc7a is described below

commit bf01924cc7a8f94fd54fde9f8e4cfa0ae3db878b
Author: len548 <[email protected]>
AuthorDate: Sat Mar 14 06:48:10 2026 +0100

    HDDS-14828. Extract listStatus tests to OzoneFileSystemTestBase (#9917)
---
 .../fs/ozone/AbstractOzoneFileSystemTest.java      | 159 +---------------
 .../ozone/AbstractRootedOzoneFileSystemTest.java   | 188 +-----------------
 .../hadoop/fs/ozone/OzoneFileSystemTestBase.java   | 209 ++++++++++++++++++++-
 3 files changed, 226 insertions(+), 330 deletions(-)

diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
index 747b37d79b2..d7ee934b8f7 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractOzoneFileSystemTest.java
@@ -428,30 +428,14 @@ public void testCreateKeyWithECReplicationConfig() throws 
Exception {
 
   @Test
   public void testDeleteCreatesFakeParentDir() throws Exception {
-    Path grandparent = new Path("/testDeleteCreatesFakeParentDir");
-    Path parent = new Path(grandparent, "parent");
-    Path child = new Path(parent, "child");
-    ContractTestUtils.touch(fs, child);
-
-    // Verify that parent dir key does not exist
-    // Creating a child should not add parent keys to the bucket
-    try {
-      getKey(parent, true);
-    } catch (OMException ome) {
-      assertEquals(KEY_NOT_FOUND, ome.getResult());
-    }
-
-    // Delete the child key
-    assertTrue(fs.delete(child, false));
+    deleteCreatesFakeParentDir(ROOT);
+  }
 
-    // Deleting the only child should create the parent dir key if it does
-    // not exist
+  @Override
+  void verifyDeleteCreatesFakeParentDir(Path parent) throws IOException {
     FileStatus fileStatus = fs.getFileStatus(parent);
     assertTrue(fileStatus.isDirectory());
     assertEquals(parent.toString(), fileStatus.getPath().toUri().getPath());
-
-    // Recursive delete with DeleteIterator
-    assertTrue(fs.delete(grandparent, true));
   }
 
   @Test
@@ -581,32 +565,7 @@ public void testFileDelete() throws Exception {
 
   @Test
   public void testListStatus() throws Exception {
-    Path parent = new Path(ROOT, "/testListStatus");
-    Path file1 = new Path(parent, "key1");
-    Path file2 = new Path(parent, "key2");
-
-    FileStatus[] fileStatuses = fs.listStatus(ROOT, EXCLUDE_TRASH);
-    assertEquals(0, fileStatuses.length, "Should be empty");
-
-    ContractTestUtils.touch(fs, file1);
-    ContractTestUtils.touch(fs, file2);
-
-    fileStatuses = fs.listStatus(ROOT, EXCLUDE_TRASH);
-    assertEquals(1, fileStatuses.length, "Should have created parent");
-    assertEquals(fileStatuses[0].getPath().toUri().getPath(), 
parent.toString(), "Parent path doesn't match");
-
-    // ListStatus on a directory should return all subdirs along with
-    // files, even if there exists a file and sub-dir with the same name.
-    fileStatuses = fs.listStatus(parent);
-    assertEquals(2, fileStatuses.length, "FileStatus did not return all 
children of the directory");
-
-    // ListStatus should return only the immediate children of a directory.
-    Path file3 = new Path(parent, "dir1/key3");
-    Path file4 = new Path(parent, "dir1/key4");
-    ContractTestUtils.touch(fs, file3);
-    ContractTestUtils.touch(fs, file4);
-    fileStatuses = fs.listStatus(parent);
-    assertEquals(3, fileStatuses.length, "FileStatus did not return all 
children of the directory");
+    verifyListStatus(ROOT, EXCLUDE_TRASH);
   }
 
   @Test
@@ -785,23 +744,7 @@ public void 
testListStatusWithIntermediateDirWithECEnabled()
    */
   @Test
   public void testListStatusOnRoot() throws Exception {
-    Path dir1 = new Path(ROOT, "dir1");
-    Path dir12 = new Path(dir1, "dir12");
-    Path dir2 = new Path(ROOT, "dir2");
-    fs.mkdirs(dir12);
-    fs.mkdirs(dir2);
-
-    // ListStatus on root should return dir1 (even though /dir1 key does not
-    // exist) and dir2 only. dir12 is not an immediate child of root and
-    // hence should not be listed.
-    FileStatus[] fileStatuses = fs.listStatus(ROOT, EXCLUDE_TRASH);
-    assertEquals(2, fileStatuses.length, "FileStatus should return only the 
immediate children");
-
-    // Verify that dir12 is not included in the result of the listStatus on 
root
-    String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
-    String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
-    assertNotEquals(fileStatus1, dir12.toString());
-    assertNotEquals(fileStatus2, dir12.toString());
+    listStatusOnRoot(ROOT, EXCLUDE_TRASH);
   }
 
   /**
@@ -911,37 +854,7 @@ private void deleteRootRecursively(FileStatus[] 
fileStatuses)
    */
   @Test
   public void testListStatusOnSubDirs() throws Exception {
-    // Create the following key structure
-    //      /dir1/dir11/dir111
-    //      /dir1/dir12
-    //      /dir1/dir12/file121
-    //      /dir2
-    // ListStatus on /dir1 should return all its immediate subdirs only
-    // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
-    // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
-    // listStatus.
-    Path dir1 = new Path("/dir1");
-    Path dir11 = new Path(dir1, "dir11");
-    Path dir111 = new Path(dir11, "dir111");
-    Path dir12 = new Path(dir1, "dir12");
-    Path file121 = new Path(dir12, "file121");
-    Path dir2 = new Path("/dir2");
-    fs.mkdirs(dir111);
-    fs.mkdirs(dir12);
-    ContractTestUtils.touch(fs, file121);
-    fs.mkdirs(dir2);
-
-    FileStatus[] fileStatuses = fs.listStatus(dir1);
-    assertEquals(2, fileStatuses.length, "FileStatus should return only the 
immediate children");
-
-    // Verify that the two children of /dir1 returned by listStatus operation
-    // are /dir1/dir11 and /dir1/dir12.
-    String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
-    String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
-    assertTrue(fileStatus1.equals(dir11.toString()) ||
-        fileStatus1.equals(dir12.toString()));
-    assertTrue(fileStatus2.equals(dir11.toString()) ||
-        fileStatus2.equals(dir12.toString()));
+    listStatusOnSubDirs(ROOT);
   }
 
   /**
@@ -971,44 +884,7 @@ public void testListStatusIteratorOnPageSize() throws 
Exception {
    */
   @Test
   public void testListStatusIteratorOnSubDirs() throws Exception {
-    // Create the following key structure
-    //      /dir1/dir11/dir111
-    //      /dir1/dir12
-    //      /dir1/dir12/file121
-    //      /dir2
-    // ListStatusIterator on /dir1 should return file status for
-    // all its immediate subdirs only which are /dir1/dir11 and
-    // /dir1/dir12. Super child files/dirs (/dir1/dir12/file121
-    // and /dir1/dir11/dir111) should not be returned by
-    // listStatusIterator.
-    Path dir1 = new Path("/dir1");
-    Path dir11 = new Path(dir1, "dir11");
-    Path dir111 = new Path(dir11, "dir111");
-    Path dir12 = new Path(dir1, "dir12");
-    Path file121 = new Path(dir12, "file121");
-    Path dir2 = new Path("/dir2");
-    try {
-      fs.mkdirs(dir111);
-      fs.mkdirs(dir12);
-      ContractTestUtils.touch(fs, file121);
-      fs.mkdirs(dir2);
-
-      RemoteIterator<FileStatus> it = fs.listStatusIterator(dir1);
-      int iCount = 0;
-      while (it.hasNext()) {
-        iCount++;
-        FileStatus fileStatus = it.next();
-        assertNotNull(fileStatus);
-        assertTrue(fileStatus.getPath().toUri().getPath().
-            equals(dir11.toString()) || fileStatus.getPath().toUri().getPath()
-            .equals(dir12.toString()));
-      }
-      assertEquals(2, iCount, "FileStatus should return only the immediate 
children");
-    } finally {
-      // Cleanup
-      fs.delete(dir2, true);
-      fs.delete(dir1, true);
-    }
+    listStatusIteratorOnSubDirs(ROOT);
   }
 
   @Test
@@ -1076,24 +952,7 @@ public void testDeleteRoot() throws IOException {
   @Test
   public void testNonExplicitlyCreatedPathExistsAfterItsLeafsWereRemoved()
       throws Exception {
-    Path source = new Path("/source");
-    Path interimPath = new Path(source, "interimPath");
-    Path leafInsideInterimPath = new Path(interimPath, "leaf");
-    Path target = new Path("/target");
-    Path leafInTarget = new Path(target, "leaf");
-
-    fs.mkdirs(source);
-    fs.mkdirs(target);
-    fs.mkdirs(leafInsideInterimPath);
-    assertTrue(fs.rename(leafInsideInterimPath, leafInTarget));
-
-    // after rename listStatus for interimPath should succeed and
-    // interimPath should have no children
-    FileStatus[] statuses = fs.listStatus(interimPath);
-    assertNotNull(statuses, "liststatus returns a null array");
-    assertEquals(0, statuses.length, "Statuses array is not empty");
-    FileStatus fileStatus = fs.getFileStatus(interimPath);
-    assertEquals(interimPath.getName(), fileStatus.getPath().getName(), 
"FileStatus does not point to interimPath");
+    nonExplicitlyCreatedPathExistsAfterItsLeafsWereRemoved(ROOT);
   }
 
   /**
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
index 5aa4cbcd126..3125414163a 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/AbstractRootedOzoneFileSystemTest.java
@@ -82,7 +82,6 @@
 import org.apache.hadoop.fs.InvalidPathException;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.fs.PathIsNotEmptyDirectoryException;
-import org.apache.hadoop.fs.RemoteIterator;
 import org.apache.hadoop.fs.StreamCapabilities;
 import org.apache.hadoop.fs.Trash;
 import org.apache.hadoop.fs.TrashPolicy;
@@ -340,34 +339,15 @@ void testDeleteCreatesFakeParentDir() throws Exception {
     //  If possible, improve this to test when FS Path is enabled.
     assumeTrue(!enabledFileSystemPaths, "FS Path is enabled. Skipping this 
test as it is not " +
             "tuned for FS Path yet");
+    deleteCreatesFakeParentDir(bucketPath);
+  }
 
-    Path grandparent = new Path(bucketPath,
-        "testDeleteCreatesFakeParentDir");
-    Path parent = new Path(grandparent, "parent");
-    Path child = new Path(parent, "child");
-    ContractTestUtils.touch(fs, child);
-
-    // Verify that parent dir key does not exist
-    // Creating a child should not add parent keys to the bucket
-    try {
-      getKey(parent, true);
-    } catch (OMException ome) {
-      assertEquals(KEY_NOT_FOUND, ome.getResult());
-    }
-
-
-    // Delete the child key
-    assertTrue(fs.delete(child, false));
-
-    // Deleting the only child should create the parent dir key if it does
-    // not exist
+  @Override
+  void verifyDeleteCreatesFakeParentDir(Path parent) throws IOException {
     OFSPath parentOFSPath = new OFSPath(parent, conf);
     String parentKey = parentOFSPath.getKeyName() + "/";
     OzoneKeyDetails parentKeyInfo = getKey(parent, true);
     assertEquals(parentKey, parentKeyInfo.getName());
-
-    // Recursive delete with DeleteIterator
-    assertTrue(fs.delete(grandparent, true));
   }
 
   @Test
@@ -385,37 +365,7 @@ void testListLocatedStatusForZeroByteFile() throws 
Exception {
 
   @Test
   void testListStatus() throws Exception {
-    Path parent = new Path(bucketPath, "testListStatus");
-    Path file1 = new Path(parent, "key1");
-    Path file2 = new Path(parent, "key2");
-
-    FileStatus[] fileStatuses = fs.listStatus(bucketPath);
-    assertEquals(0, fileStatuses.length, "Should be empty");
-
-    ContractTestUtils.touch(fs, file1);
-    ContractTestUtils.touch(fs, file2);
-
-    fileStatuses = fs.listStatus(bucketPath);
-    assertEquals(1, fileStatuses.length, "Should have created parent");
-    assertEquals(fileStatuses[0].getPath().toUri().getPath(), 
parent.toString(), "Parent path doesn't match");
-
-    // ListStatus on a directory should return all subdirs along with
-    // files, even if there exists a file and sub-dir with the same name.
-    fileStatuses = fs.listStatus(parent);
-    assertEquals(2, fileStatuses.length, "FileStatus did not return all 
children of the directory");
-
-    // ListStatus should return only the immediate children of a directory.
-    Path file3 = new Path(parent, "dir1/key3");
-    Path file4 = new Path(parent, "dir1/key4");
-    ContractTestUtils.touch(fs, file3);
-    ContractTestUtils.touch(fs, file4);
-    fileStatuses = fs.listStatus(parent);
-    assertEquals(3, fileStatuses.length, "FileStatus did not return all 
children of" +
-        " the directory : Got " + Arrays.toString(
-        fileStatuses));
-
-    // Cleanup
-    fs.delete(parent, true);
+    verifyListStatus(bucketPath, null);
   }
 
   /**
@@ -461,48 +411,7 @@ void testListStatusIteratorOnPageSize() throws Exception {
    */
   @Test
   void testListStatusIteratorOnSubDirs() throws Exception {
-    // Create the following key structure
-    //      /dir1/dir11/dir111
-    //      /dir1/dir12
-    //      /dir1/dir12/file121
-    //      /dir2
-    // listStatusIterator on /dir1 should return all its immediated subdirs 
only
-    // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
-    // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
-    // listStatusIterator.
-    Path dir1 = new Path(bucketPath, "dir1");
-    Path dir11 = new Path(dir1, "dir11");
-    Path dir111 = new Path(dir11, "dir111");
-    Path dir12 = new Path(dir1, "dir12");
-    Path file121 = new Path(dir12, "file121");
-    Path dir2 = new Path(bucketPath, "dir2");
-    try {
-      fs.mkdirs(dir111);
-      fs.mkdirs(dir12);
-      ContractTestUtils.touch(fs, file121);
-      fs.mkdirs(dir2);
-
-      RemoteIterator<FileStatus> it = fs.listStatusIterator(dir1);
-      int iCount = 0;
-      while (it.hasNext()) {
-        iCount++;
-        FileStatus fileStatus = it.next();
-        assertNotNull(fileStatus);
-        assertNotEquals(fileStatus, dir12.toString());
-        // Verify that the two children of /dir1
-        // returned by listStatusIterator operation
-        // are /dir1/dir11 and /dir1/dir12.
-        assertTrue(fileStatus.getPath().toUri().getPath().
-            equals(dir11.toString()) ||
-            fileStatus.getPath().toUri().getPath().
-                equals(dir12.toString()));
-      }
-      assertEquals(2, iCount, "Iterator should return only the immediate 
children");
-    } finally {
-      // Cleanup
-      fs.delete(dir2, true);
-      fs.delete(dir1, true);
-    }
+    listStatusIteratorOnSubDirs(bucketPath);
   }
 
   /**
@@ -650,30 +559,7 @@ void testGetFileStatusRoot() throws Exception {
   @Test
   void testListStatusInBucket() throws Exception {
     Path root = new Path("/" + volumeName + "/" + bucketName);
-    Path dir1 = new Path(root, "dir1");
-    Path dir12 = new Path(dir1, "dir12");
-    Path dir2 = new Path(root, "dir2");
-    try {
-      fs.mkdirs(dir12);
-      fs.mkdirs(dir2);
-
-      // ListStatus on root should return dir1 (even though /dir1 key does not
-      // exist) and dir2 only. dir12 is not an immediate child of root and
-      // hence should not be listed.
-      FileStatus[] fileStatuses = fs.listStatus(root);
-      assertEquals(2, fileStatuses.length, "FileStatus should return only the 
immediate children");
-
-      // Verify that dir12 is not included in the result of the listStatus on
-      // root
-      String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
-      String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
-      assertNotEquals(fileStatus1, dir12.toString());
-      assertNotEquals(fileStatus2, dir12.toString());
-    } finally {
-      // cleanup
-      fs.delete(dir1, true);
-      fs.delete(dir2, true);
-    }
+    listStatusOnRoot(root, null);
   }
 
   /**
@@ -711,69 +597,13 @@ void testListStatusOnLargeDirectory() throws Exception {
    */
   @Test
   void testListStatusOnSubDirs() throws Exception {
-    // Create the following key structure
-    //      /dir1/dir11/dir111
-    //      /dir1/dir12
-    //      /dir1/dir12/file121
-    //      /dir2
-    // ListStatus on /dir1 should return all its immediated subdirs only
-    // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
-    // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
-    // listStatus.
-    Path dir1 = new Path(bucketPath, "dir1");
-    Path dir11 = new Path(dir1, "dir11");
-    Path dir111 = new Path(dir11, "dir111");
-    Path dir12 = new Path(dir1, "dir12");
-    Path file121 = new Path(dir12, "file121");
-    Path dir2 = new Path(bucketPath, "dir2");
-    fs.mkdirs(dir111);
-    fs.mkdirs(dir12);
-    ContractTestUtils.touch(fs, file121);
-    fs.mkdirs(dir2);
-
-    FileStatus[] fileStatuses = fs.listStatus(dir1);
-    assertEquals(2, fileStatuses.length, "FileStatus should return only the 
immediate children");
-
-    // Verify that the two children of /dir1 returned by listStatus operation
-    // are /dir1/dir11 and /dir1/dir12.
-    String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
-    String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
-    assertTrue(fileStatus1.equals(dir11.toString()) ||
-        fileStatus1.equals(dir12.toString()));
-    assertTrue(fileStatus2.equals(dir11.toString()) ||
-        fileStatus2.equals(dir12.toString()));
-
-    // Cleanup
-    fs.delete(dir2, true);
-    fs.delete(dir1, true);
+    listStatusOnSubDirs(bucketPath);
   }
 
   @Test
   void testNonExplicitlyCreatedPathExistsAfterItsLeafsWereRemoved()
       throws Exception {
-    Path source = new Path(bucketPath, "source");
-    Path interimPath = new Path(source, "interimPath");
-    Path leafInsideInterimPath = new Path(interimPath, "leaf");
-    Path target = new Path(bucketPath, "target");
-    Path leafInTarget = new Path(target, "leaf");
-
-    fs.mkdirs(source);
-    fs.mkdirs(target);
-    fs.mkdirs(leafInsideInterimPath);
-
-    assertTrue(fs.rename(leafInsideInterimPath, leafInTarget));
-
-    // after rename listStatus for interimPath should succeed and
-    // interimPath should have no children
-    FileStatus[] statuses = fs.listStatus(interimPath);
-    assertNotNull(statuses, "liststatus returns a null array");
-    assertEquals(0, statuses.length, "Statuses array is not empty");
-    FileStatus fileStatus = fs.getFileStatus(interimPath);
-    assertEquals(interimPath.getName(), fileStatus.getPath().getName(), 
"FileStatus does not point to interimPath");
-
-    // Cleanup
-    fs.delete(target, true);
-    fs.delete(source, true);
+    nonExplicitlyCreatedPathExistsAfterItsLeafsWereRemoved(bucketPath);
   }
 
   /**
diff --git 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTestBase.java
 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTestBase.java
index 662198f2602..b690610edd5 100644
--- 
a/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTestBase.java
+++ 
b/hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/OzoneFileSystemTestBase.java
@@ -37,6 +37,7 @@
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.LocatedFileStatus;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.PathFilter;
 import org.apache.hadoop.fs.RemoteIterator;
 import org.apache.hadoop.fs.contract.ContractTestUtils;
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
@@ -258,7 +259,7 @@ void listStatusIteratorOnRoot(Path root) throws Exception {
         assertNotNull(fileStatus);
         // Verify that dir12 is not included in the result
         // of the listStatusIterator on root.
-        assertNotEquals(fileStatus, dir12.toString());
+        assertNotEquals(fileStatus.getPath().toUri().getPath(), 
dir12.toString());
       }
       assertEquals(2, iCount, "FileStatus should return only the immediate 
children");
     } finally {
@@ -268,6 +269,212 @@ void listStatusIteratorOnRoot(Path root) throws Exception 
{
     }
   }
 
+  void deleteCreatesFakeParentDir(Path root) throws IOException {
+    Path grandparent = new Path(root, "testDeleteCreatesFakeParentDir");
+    Path parent = new Path(grandparent, "parent");
+    Path child = new Path(parent, "child");
+    FileSystem fs = getFs();
+    ContractTestUtils.touch(fs, child);
+
+    // Verify that parent dir key does not exist
+    // Creating a child should not add parent keys to the bucket
+    try {
+      getKey(parent, true);
+    } catch (OMException ome) {
+      assertEquals(KEY_NOT_FOUND, ome.getResult());
+    }
+
+    // Delete the child key
+    assertTrue(fs.delete(child, false));
+
+    // Deleting the only child should create the parent dir key if it does
+    // not exist
+    verifyDeleteCreatesFakeParentDir(parent);
+
+    // Recursive delete with DeleteIterator
+    assertTrue(fs.delete(grandparent, true));
+  }
+
+  void verifyListStatus(Path root, PathFilter filter) throws Exception {
+    Path parent = new Path(root, "testListStatus");
+    Path file1 = new Path(parent, "key1");
+    Path file2 = new Path(parent, "key2");
+    FileSystem fs = getFs();
+
+    FileStatus[] fileStatuses = filter != null
+        ? fs.listStatus(root, filter)
+        : fs.listStatus(root);
+    assertEquals(0, fileStatuses.length, "Should be empty");
+
+    ContractTestUtils.touch(fs, file1);
+    ContractTestUtils.touch(fs, file2);
+
+    fileStatuses = filter != null
+        ? fs.listStatus(root, filter)
+        : fs.listStatus(root);
+    assertEquals(1, fileStatuses.length, "Should have created parent");
+    assertEquals(fileStatuses[0].getPath().toUri().getPath(), 
parent.toString(), "Parent path doesn't match");
+
+    // ListStatus on a directory should return all subdirs along with
+    // files, even if there exists a file and sub-dir with the same name.
+    fileStatuses = fs.listStatus(parent);
+    assertEquals(2, fileStatuses.length, "FileStatus did not return all 
children of the directory");
+
+    // ListStatus should return only the immediate children of a directory.
+    Path file3 = new Path(parent, "dir1/key3");
+    Path file4 = new Path(parent, "dir1/key4");
+    ContractTestUtils.touch(fs, file3);
+    ContractTestUtils.touch(fs, file4);
+    fileStatuses = fs.listStatus(parent);
+    assertEquals(3, fileStatuses.length, "FileStatus did not return all 
children of the directory");
+
+    // Cleanup
+    fs.delete(parent, true);
+  }
+
+  void listStatusIteratorOnSubDirs(Path root) throws Exception {
+    // Create the following key structure
+    //      /dir1/dir11/dir111
+    //      /dir1/dir12
+    //      /dir1/dir12/file121
+    //      /dir2
+    // listStatusIterator on /dir1 should return all its immediated subdirs 
only
+    // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
+    // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
+    // listStatusIterator.
+    Path dir1 = new Path(root, "dir1");
+    Path dir11 = new Path(dir1, "dir11");
+    Path dir111 = new Path(dir11, "dir111");
+    Path dir12 = new Path(dir1, "dir12");
+    Path file121 = new Path(dir12, "file121");
+    Path dir2 = new Path(root, "dir2");
+    FileSystem fs = getFs();
+    try {
+      fs.mkdirs(dir111);
+      fs.mkdirs(dir12);
+      ContractTestUtils.touch(fs, file121);
+      fs.mkdirs(dir2);
+
+      RemoteIterator<FileStatus> it = fs.listStatusIterator(dir1);
+      int iCount = 0;
+      while (it.hasNext()) {
+        iCount++;
+        FileStatus fileStatus = it.next();
+        assertNotNull(fileStatus);
+        // Verify that the two children of /dir1
+        // returned by listStatusIterator operation
+        // are /dir1/dir11 and /dir1/dir12.
+        assertTrue(fileStatus.getPath().toUri().getPath().
+            equals(dir11.toString()) ||
+            fileStatus.getPath().toUri().getPath().
+                equals(dir12.toString()));
+      }
+      assertEquals(2, iCount, "Iterator should return only the immediate 
children");
+    } finally {
+      // Cleanup
+      fs.delete(dir2, true);
+      fs.delete(dir1, true);
+    }
+  }
+
+  void listStatusOnRoot(Path root, PathFilter filter) throws Exception {
+    Path dir1 = new Path(root, "dir1");
+    Path dir12 = new Path(dir1, "dir12");
+    Path dir2 = new Path(root, "dir2");
+    FileSystem fs = getFs();
+    try {
+      fs.mkdirs(dir12);
+      fs.mkdirs(dir2);
+
+      // ListStatus on root should return dir1 (even though /dir1 key does not
+      // exist) and dir2 only. dir12 is not an immediate child of root and
+      // hence should not be listed.
+      FileStatus[] fileStatuses = filter != null
+          ? fs.listStatus(root, filter)
+          : fs.listStatus(root);
+      assertEquals(2, fileStatuses.length, "FileStatus should return only the 
immediate children");
+
+      // Verify that dir12 is not included in the result of the listStatus on
+      // root
+      String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
+      String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
+      assertNotEquals(fileStatus1, dir12.toString());
+      assertNotEquals(fileStatus2, dir12.toString());
+    } finally {
+      // cleanup
+      fs.delete(dir1, true);
+      fs.delete(dir2, true);
+    }
+  }
+
+  void listStatusOnSubDirs(Path root) throws Exception {
+    // Create the following key structure
+    //      /dir1/dir11/dir111
+    //      /dir1/dir12
+    //      /dir1/dir12/file121
+    //      /dir2
+    // ListStatus on /dir1 should return all its immediated subdirs only
+    // which are /dir1/dir11 and /dir1/dir12. Super child files/dirs
+    // (/dir1/dir12/file121 and /dir1/dir11/dir111) should not be returned by
+    // listStatus.
+    Path dir1 = new Path(root, "dir1");
+    Path dir11 = new Path(dir1, "dir11");
+    Path dir111 = new Path(dir11, "dir111");
+    Path dir12 = new Path(dir1, "dir12");
+    Path file121 = new Path(dir12, "file121");
+    Path dir2 = new Path(root, "dir2");
+    FileSystem fs = getFs();
+    fs.mkdirs(dir111);
+    fs.mkdirs(dir12);
+    ContractTestUtils.touch(fs, file121);
+    fs.mkdirs(dir2);
+
+    FileStatus[] fileStatuses = fs.listStatus(dir1);
+    assertEquals(2, fileStatuses.length, "FileStatus should return only the 
immediate children");
+
+    // Verify that the two children of /dir1 returned by listStatus operation
+    // are /dir1/dir11 and /dir1/dir12.
+    String fileStatus1 = fileStatuses[0].getPath().toUri().getPath();
+    String fileStatus2 = fileStatuses[1].getPath().toUri().getPath();
+    assertTrue(fileStatus1.equals(dir11.toString()) ||
+        fileStatus1.equals(dir12.toString()));
+    assertTrue(fileStatus2.equals(dir11.toString()) ||
+        fileStatus2.equals(dir12.toString()));
+
+    // Cleanup
+    fs.delete(dir2, true);
+    fs.delete(dir1, true);
+  }
+
+  void nonExplicitlyCreatedPathExistsAfterItsLeafsWereRemoved(Path root)
+      throws Exception {
+    Path source = new Path(root, "source");
+    Path interimPath = new Path(source, "interimPath");
+    Path leafInsideInterimPath = new Path(interimPath, "leaf");
+    Path target = new Path(root, "target");
+    Path leafInTarget = new Path(target, "leaf");
+    FileSystem fs = getFs();
+
+    fs.mkdirs(source);
+    fs.mkdirs(target);
+    fs.mkdirs(leafInsideInterimPath);
+    assertTrue(fs.rename(leafInsideInterimPath, leafInTarget));
+
+    // after rename listStatus for interimPath should succeed and
+    // interimPath should have no children
+    FileStatus[] statuses = fs.listStatus(interimPath);
+    assertNotNull(statuses, "liststatus returns a null array");
+    assertEquals(0, statuses.length, "Statuses array is not empty");
+    FileStatus fileStatus = fs.getFileStatus(interimPath);
+    assertEquals(interimPath.getName(), fileStatus.getPath().getName(), 
"FileStatus does not point to interimPath");
+
+    // Cleanup
+    fs.delete(target, true);
+    fs.delete(source, true);
+  }
+
+  abstract void verifyDeleteCreatesFakeParentDir(Path parent) throws 
IOException;
+
   abstract OzoneKeyDetails getKey(Path keyPath, boolean isDirectory) throws 
IOException;
 
   abstract FileSystem getFs();


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to