You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by we...@apache.org on 2019/06/18 01:30:12 UTC

[hadoop] branch trunk updated: HDFS-11949. Add testcase for ensuring that FsShell cann't move file to the target directory that file exists. Contributed by legend.

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

weichiu pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/hadoop.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 1e92db5  HDFS-11949. Add testcase for ensuring that FsShell cann't move file to the target directory that file exists. Contributed by legend.
1e92db5 is described below

commit 1e92db5a1e293fea6b696d9bf51d91e712b33127
Author: Wei-Chiu Chuang <we...@apache.org>
AuthorDate: Mon Jun 17 18:29:34 2019 -0700

    HDFS-11949. Add testcase for ensuring that FsShell cann't move file to the target directory that file exists. Contributed by legend.
---
 .../java/org/apache/hadoop/fs/TestFsShellCopy.java | 47 +++++++++++++++++-----
 1 file changed, 36 insertions(+), 11 deletions(-)

diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java
index f9b2420..72ae296 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java
@@ -189,7 +189,7 @@ public class TestFsShellCopy {
     // copy to new file, then again
     prepPut(dstPath, false, false);
     checkPut(0, srcPath, dstPath, useWindowsPath);
-    if (lfs.isFile(srcPath)) {
+    if (lfs.getFileStatus(srcPath).isFile()) {
       checkPut(1, srcPath, dstPath, useWindowsPath);
     } else { // directory works because it copies into the dir
       // clear contents so the check won't think there are extra paths
@@ -228,11 +228,11 @@ public class TestFsShellCopy {
     if (create) {
       if (isDir) {
         lfs.mkdirs(dst);
-        assertTrue(lfs.isDirectory(dst));
+        assertTrue(lfs.getFileStatus(dst).isDirectory());
       } else {
         lfs.mkdirs(new Path(dst.getName()));
         lfs.create(dst).close();
-        assertTrue(lfs.isFile(dst));
+        assertTrue(lfs.getFileStatus(dst).isFile());
       }
     }
   }
@@ -253,7 +253,7 @@ public class TestFsShellCopy {
     
     Path target;
     if (lfs.exists(dest)) {
-      if (lfs.isDirectory(dest)) {
+      if (lfs.getFileStatus(dest).isDirectory()) {
         target = new Path(pathAsString(dest), src.getName());
       } else {
         target = dest;
@@ -276,7 +276,8 @@ public class TestFsShellCopy {
     
     if (exitCode == 0) {
       assertTrue(lfs.exists(target));
-      assertTrue(lfs.isFile(src) == lfs.isFile(target));
+      assertTrue(lfs.getFileStatus(src).isFile() ==
+          lfs.getFileStatus(target).isFile());
       assertEquals(1, lfs.listStatus(lfs.makeQualified(target).getParent()).length);      
     } else {
       assertEquals(targetExists, lfs.exists(target));
@@ -293,7 +294,7 @@ public class TestFsShellCopy {
 
     argv = new String[]{ "-put", srcPath.toString(), dstPath.toString() };
     assertEquals(0, shell.run(argv));
-    assertTrue(lfs.exists(dstPath) && lfs.isFile(dstPath));
+    assertTrue(lfs.exists(dstPath) && lfs.getFileStatus(dstPath).isFile());
 
     lfs.delete(dstPath, true);
     assertFalse(lfs.exists(dstPath));
@@ -319,7 +320,7 @@ public class TestFsShellCopy {
           "-put", srcPath.toString(), dstPath.toString()+suffix };
       assertEquals(0, shell.run(argv));
       assertTrue(lfs.exists(subdirDstPath));
-      assertTrue(lfs.isFile(subdirDstPath));
+      assertTrue(lfs.getFileStatus(subdirDstPath).isFile());
     }
 
     // ensure .. is interpreted as a dir
@@ -329,7 +330,7 @@ public class TestFsShellCopy {
     argv = new String[]{ "-put", srcPath.toString(), dotdotDst };
     assertEquals(0, shell.run(argv));
     assertTrue(lfs.exists(subdirDstPath));
-    assertTrue(lfs.isFile(subdirDstPath));
+    assertTrue(lfs.getFileStatus(subdirDstPath).isFile());
   }
   
   @Test
@@ -442,9 +443,33 @@ public class TestFsShellCopy {
     assertEquals(0, exit);
     assertFalse(lfs.exists(srcFile));
     assertTrue(lfs.exists(target));
-    assertTrue(lfs.isFile(target));
+    assertTrue(lfs.getFileStatus(target).isFile());
   }
-  
+
+  @Test
+  public void testMoveFileFromLocalDestExists() throws Exception{
+    Path testRoot = new Path(testRootDir, "testPutFile");
+    lfs.delete(testRoot, true);
+    lfs.mkdirs(testRoot);
+
+    Path target = new Path(testRoot, "target");
+    Path srcFile = new Path(testRoot, new Path("srcFile"));
+    lfs.createNewFile(srcFile);
+
+    int exit = shell.run(new String[]{
+        "-moveFromLocal", srcFile.toString(), target.toString()});
+    assertEquals(0, exit);
+    assertFalse(lfs.exists(srcFile));
+    assertTrue(lfs.exists(target));
+    assertTrue(lfs.getFileStatus(target).isFile());
+
+    lfs.createNewFile(srcFile);
+    exit = shell.run(new String[]{
+        "-moveFromLocal", srcFile.toString(), target.toString()});
+    assertEquals(1, exit);
+    assertTrue(lfs.exists(srcFile));
+  }
+
   @Test
   public void testMoveDirFromLocal() throws Exception {    
     Path testRoot = new Path(testRootDir, "testPutDir");
@@ -502,7 +527,7 @@ public class TestFsShellCopy {
     shellRun(0, "-moveFromLocal", winSrcFile, target.toString());
     assertFalse(lfs.exists(srcFile));
     assertTrue(lfs.exists(target));
-    assertTrue(lfs.isFile(target));
+    assertTrue(lfs.getFileStatus(target).isFile());
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org