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 f9b2420067..72ae296c95 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 @@ private void checkPut(Path srcPath, Path targetDir, boolean useWindowsPath) // 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 @@ private void prepPut(Path dst, boolean create, 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 @@ private void checkPut(int exitCode, Path src, Path dest, 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 @@ private void checkPut(int exitCode, Path src, Path dest, 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 void testRepresentsDir() throws Exception { 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 void testRepresentsDir() throws Exception { "-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 void testRepresentsDir() throws Exception { 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 void testMoveFileFromLocal() throws Exception { 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 void testMoveFromWindowsLocalPath() throws Exception { shellRun(0, "-moveFromLocal", winSrcFile, target.toString()); assertFalse(lfs.exists(srcFile)); assertTrue(lfs.exists(target)); - assertTrue(lfs.isFile(target)); + assertTrue(lfs.getFileStatus(target).isFile()); } @Test