rakeshadr commented on a change in pull request #1557:
URL: https://github.com/apache/ozone/pull/1557#discussion_r520733078



##########
File path: 
hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/fs/ozone/TestOzoneFileSystemV1.java
##########
@@ -260,6 +260,44 @@ private void testListFilesRecursive() throws Exception {
             expectedFilesCount, actualCount);
   }
 
+
+  protected void testRenameDir() throws Exception {
+    final String root = "/root_dir";
+    final String dir = root + "/dir1";
+    final Path source = new Path(fs.getUri().toString() + dir);
+    final Path dest = new Path(source.toString() + ".renamed");
+    // Add a sub-dir to the directory to be moved.
+    final Path subdir = new Path(source, "sub_dir1");
+    fs.mkdirs(subdir);
+    LOG.info("Created dir {}", subdir);
+
+    // case-1) source is a sub-dir to destin
+    final Path sourceRoot = new Path(fs.getUri().toString() + root);
+    LOG.info("Rename op-> source:/root_dir to destin:/root_dir/dir1/sub_dir1");
+    try {
+      fs.rename(sourceRoot, subdir);
+      Assert.fail("Should throw exception : Cannot rename a directory to" +
+              " its own subdirectory");
+    } catch (OMException e) {
+      // expected
+    }
+
+    LOG.info("Will move {} to {}", source, dest);
+    fs.rename(source, dest);
+
+    assertTrue("Directory rename failed", fs.exists(dest));
+    // Verify that the subdir is also renamed i.e. keys corresponding to the
+    // sub-directories of the renamed directory have also been renamed.
+    assertTrue("Keys under the renamed directory not renamed",
+            fs.exists(new Path(dest, "sub_dir1")));
+
+    // Test if one path belongs to other FileSystem.
+    Path fakeDir = new Path(fs.getUri().toString() + "fake" + dir);
+    LambdaTestUtils.intercept(IllegalArgumentException.class, "Wrong FS",
+            () -> fs.rename(fakeDir, dest));

Review comment:
       @linyiqun  Thanks a lot for the review comments.
   
   Sure, I will add tests. Can you please help me to understand about case1 
with some example.
   >case1: parent folder does't exist, and then failed
   Rename from /a/b/c/d to /a. Are you talking about this? How would I simulate 
non-existent "/a", which is already a valid root of the source path, right?
   
   >case2: parent folder existed, then succeed
   I think you are saying that, Rename from "/a/b/c" to "/a". It will succeed 
and result will be "/a/c"
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to