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



##########
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:
       >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?
   
   Yes, you are right. Can we transform this to the case below:
   dir: /a/b/c/d
   file: /a/d, 
   Rename from /a/b/c/d to /a, should be failed since /a/d is a existed file.
   
   >I think you are saying that, Rename from "/a/b/c" to "/a". It will succeed 
and result will be "/a/c"
   
   Yes, this is what I want to say.
   
   Hope makes sense to you.
   




----------------------------------------------------------------
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