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 d4ee7768ef9 HDDS-14698. Abstract testCreateDoesNotAddParentDirKeys and 
testListStatusIteratorOnRoot/InBucket (#9809)
d4ee7768ef9 is described below

commit d4ee7768ef9d9df514f0a4dddf9bfb3d34f4efa2
Author: len548 <[email protected]>
AuthorDate: Tue Feb 24 12:28:34 2026 +0100

    HDDS-14698. Abstract testCreateDoesNotAddParentDirKeys and 
testListStatusIteratorOnRoot/InBucket (#9809)
---
 .../fs/ozone/AbstractOzoneFileSystemTest.java      | 48 +++--------------
 .../ozone/AbstractRootedOzoneFileSystemTest.java   | 52 +++---------------
 .../hadoop/fs/ozone/OzoneFileSystemTestBase.java   | 61 ++++++++++++++++++++++
 3 files changed, 73 insertions(+), 88 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 d1d5976097e..747b37d79b2 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
@@ -412,23 +412,12 @@ private void checkInvalidPath(Path path) {
   @Test
   public void testCreateDoesNotAddParentDirKeys() throws Exception {
     Path grandparent = new Path("/testCreateDoesNotAddParentDirKeys");
-    Path parent = new Path(grandparent, "parent");
-    Path child = new Path(parent, "child");
-    ContractTestUtils.touch(fs, child);
-
-    OzoneKeyDetails key = getKey(child, false);
-    assertEquals(key.getName(), fs.pathToKey(child));
-
-    // Creating a child should not add parent keys to the bucket
-    try {
-      getKey(parent, true);
-    } catch (OMException ome) {
-      assertEquals(KEY_NOT_FOUND, ome.getResult());
-    }
+    createDoesNotAddParentDirKeys(grandparent);
+  }
 
-    // List status on the parent should show the child file
-    assertEquals(1L, fs.listStatus(parent).length, "List status of parent 
should include the 1 child file");
-    assertTrue(fs.getFileStatus(parent).isDirectory(), "Parent directory does 
not appear to be a directory");
+  @Override
+  String getChildKeyName(Path child) {
+    return fs.pathToKey(child);
   }
 
   @Test
@@ -968,32 +957,7 @@ public void testListStatusIteratorWithDir() throws 
Exception {
    */
   @Test
   public void testListStatusIteratorOnRoot() throws Exception {
-    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);
-
-      // ListStatusIterator 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.
-      RemoteIterator<FileStatus> it = fs.listStatusIterator(ROOT);
-      int iCount = 0;
-      while (it.hasNext()) {
-        iCount++;
-        FileStatus fileStatus = it.next();
-        assertNotNull(fileStatus);
-        // Verify that dir12 is not included in the result
-        // of the listStatusIterator on root.
-        assertNotEquals(fileStatus.getPath().toUri().getPath(), 
dir12.toString());
-      }
-      assertEquals(2, iCount, "FileStatus should return only the immediate 
children");
-    } finally {
-      // Cleanup
-      fs.delete(dir2, true);
-      fs.delete(dir1, true);
-    }
+    listStatusIteratorOnRoot(ROOT);
   }
 
   @Test
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 926e323583f..5aa4cbcd126 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
@@ -286,27 +286,13 @@ void testUserHomeDirectory() {
   void testCreateDoesNotAddParentDirKeys() throws Exception {
     Path grandparent = new Path(bucketPath,
         "testCreateDoesNotAddParentDirKeys");
-    Path parent = new Path(grandparent, "parent");
-    Path child = new Path(parent, "child");
-    ContractTestUtils.touch(fs, child);
+    createDoesNotAddParentDirKeys(grandparent);
+  }
 
-    OzoneKeyDetails key = getKey(child, false);
+  @Override
+  String getChildKeyName(Path child) {
     OFSPath childOFSPath = new OFSPath(child, conf);
-    assertEquals(key.getName(), childOFSPath.getKeyName());
-
-    // Creating a child should not add parent keys to the bucket
-    try {
-      getKey(parent, true);
-    } catch (OMException ome) {
-      assertEquals(KEY_NOT_FOUND, ome.getResult());
-    }
-
-    // List status on the parent should show the child file
-    assertEquals(1L, fs.listStatus(parent).length, "List status of parent 
should include the 1 child file");
-    assertTrue(fs.getFileStatus(parent).isDirectory(), "Parent directory does 
not appear to be a directory");
-
-    // Cleanup
-    fs.delete(grandparent, true);
+    return childOFSPath.getKeyName();
   }
 
   @Test
@@ -446,33 +432,7 @@ void testListStatusIteratorWithDir() throws Exception {
   @Test
   void testListStatusIteratorInBucket() 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.
-      RemoteIterator<FileStatus> it = fs.listStatusIterator(root);
-      // Verify that dir12 is not included in the result of the listStatus on
-      // root
-      int iCount = 0;
-      while (it.hasNext()) {
-        iCount++;
-        FileStatus fileStatus = it.next();
-        assertNotNull(fileStatus);
-        assertNotEquals(fileStatus, dir12.toString());
-      }
-      assertEquals(2, iCount, "FileStatus should return only the immediate 
children");
-
-    } finally {
-      // cleanup
-      fs.delete(dir1, true);
-      fs.delete(dir2, true);
-    }
+    listStatusIteratorOnRoot(root);
   }
 
   @Test
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 807dbc2b8dd..662198f2602 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
@@ -19,10 +19,13 @@
 
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION;
 import static org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_REPLICATION_TYPE;
+import static 
org.apache.hadoop.ozone.om.exceptions.OMException.ResultCodes.KEY_NOT_FOUND;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.IOException;
 import java.net.URI;
@@ -39,6 +42,7 @@
 import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.protocol.proto.HddsProtos;
 import org.apache.hadoop.ozone.client.OzoneKeyDetails;
+import org.apache.hadoop.ozone.om.exceptions.OMException;
 
 /**
  * Common test cases for Ozone file systems.
@@ -207,6 +211,63 @@ void listStatusIteratorWithDir(Path root) throws Exception 
{
     }
   }
 
+  void createDoesNotAddParentDirKeys(Path grandparent) throws Exception {
+    Path parent = new Path(grandparent, "parent");
+    Path child = new Path(parent, "child");
+    FileSystem fs = getFs();
+    ContractTestUtils.touch(fs, child);
+
+    OzoneKeyDetails key = getKey(child, false);
+    String expectedKeyName = getChildKeyName(child);
+    assertEquals(key.getName(), expectedKeyName);
+
+    // Creating a child should not add parent keys to the bucket
+    try {
+      getKey(parent, true);
+    } catch (OMException ome) {
+      assertEquals(KEY_NOT_FOUND, ome.getResult());
+    }
+
+    // List status on the parent should show the child file
+    assertEquals(1L, fs.listStatus(parent).length, "List status of parent 
should include the 1 child file");
+    assertTrue(fs.getFileStatus(parent).isDirectory(), "Parent directory does 
not appear to be a directory");
+
+    // Cleanup
+    fs.delete(grandparent, true);
+  }
+
+  abstract String getChildKeyName(Path child);
+
+  void listStatusIteratorOnRoot(Path root) 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);
+
+      // ListStatusIterator 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.
+      RemoteIterator<FileStatus> it = fs.listStatusIterator(root);
+      int iCount = 0;
+      while (it.hasNext()) {
+        iCount++;
+        FileStatus fileStatus = it.next();
+        assertNotNull(fileStatus);
+        // Verify that dir12 is not included in the result
+        // of the listStatusIterator on root.
+        assertNotEquals(fileStatus, dir12.toString());
+      }
+      assertEquals(2, iCount, "FileStatus should return only the immediate 
children");
+    } finally {
+      // Cleanup
+      fs.delete(dir2, true);
+      fs.delete(dir1, true);
+    }
+  }
+
   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