diff --git a/CHANGES.txt b/CHANGES.txt index ee3098b48a..0b0264be6b 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -215,6 +215,9 @@ Trunk (unreleased changes) HADOOP-6569. FsShell#cat should avoid calling unecessary getFileStatus before opening a file to read. (hairong) + HADOOP-6689. Add directory renaming test to existing FileContext tests. + (Eli Collins via suresh) + BUG FIXES HADOOP-6293. Fix FsShell -text to work on filesystems other than the diff --git a/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java b/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java index 9a619fbe06..5be803a669 100644 --- a/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java +++ b/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java @@ -750,14 +750,14 @@ public void testRenameFileToNonExistentDirectory() throws Exception { try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); } @@ -774,13 +774,13 @@ public void testRenameFileToDestinationWithParentFile() throws Exception { try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { } try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { } } @@ -808,7 +808,7 @@ public void testRenameFileAsExistingFile() throws Exception { // Fails without overwrite option try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } @@ -829,14 +829,14 @@ public void testRenameFileAsExistingDirectory() throws Exception { // Fails without overwrite option try { rename(src, dst, false, false, true, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { } // File cannot be renamed as directory try { rename(src, dst, false, false, true, Rename.OVERWRITE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { } } @@ -851,14 +851,14 @@ public void testRenameDirectoryToNonExistentParent() throws Exception { try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); } try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { Assert.assertTrue(unwrapException(e) instanceof FileNotFoundException); } @@ -894,7 +894,7 @@ private void testRenameDirectoryAsNonExistentDirectory(Rename... options) throws } @Test - public void testRenameDirectoryAsNonEmptyDirectory() throws Exception { + public void testRenameDirectoryAsEmptyDirectory() throws Exception { if (!renameSupported()) return; Path src = getTestRootPath(fc, "test/hadoop/dir"); @@ -902,22 +902,47 @@ public void testRenameDirectoryAsNonEmptyDirectory() throws Exception { createFile(getTestRootPath(fc, "test/hadoop/dir/file1")); createFile(getTestRootPath(fc, "test/hadoop/dir/subdir/file2")); + Path dst = getTestRootPath(fc, "test/new/newdir"); + fc.mkdir(dst, FileContext.DEFAULT_PERM, true); + + // Fails without overwrite option + try { + rename(src, dst, false, true, false, Rename.NONE); + Assert.fail("Expected exception was not thrown"); + } catch (IOException e) { + // Expected (cannot over-write non-empty destination) + Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); + } + // Succeeds with the overwrite option + rename(src, dst, true, false, true, Rename.OVERWRITE); + } + + @Test + public void testRenameDirectoryAsNonEmptyDirectory() throws Exception { + if (!renameSupported()) return; + + Path src = getTestRootPath(fc, "test/hadoop/dir"); + fc.mkdir(src, FileContext.DEFAULT_PERM, true); + createFile(getTestRootPath(fc, "test/hadoop/dir/file1")); + createFile(getTestRootPath(fc, "test/hadoop/dir/subdir/file2")); + Path dst = getTestRootPath(fc, "test/new/newdir"); fc.mkdir(dst, FileContext.DEFAULT_PERM, true); createFile(getTestRootPath(fc, "test/new/newdir/file1")); // Fails without overwrite option try { rename(src, dst, false, true, false, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { + // Expected (cannot over-write non-empty destination) Assert.assertTrue(unwrapException(e) instanceof FileAlreadyExistsException); } - // Succeeds with overwrite option + // Fails even with the overwrite option try { rename(src, dst, false, true, false, Rename.OVERWRITE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException ex) { - // Expected exception + // Expected (cannot over-write non-empty destination) } } @@ -932,13 +957,13 @@ public void testRenameDirectoryAsFile() throws Exception { // Fails without overwrite option try { rename(src, dst, false, true, true, Rename.NONE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException e) { } // Directory cannot be renamed as existing file try { rename(src, dst, false, true, true, Rename.OVERWRITE); - Assert.fail("Expected exception is not thrown"); + Assert.fail("Expected exception was not thrown"); } catch (IOException ex) { } }