Author: suresh
Date: Tue Apr 13 17:00:26 2010
New Revision: 933705
URL: http://svn.apache.org/viewvc?rev=933705&view=rev
Log:
HADOOP-6689. Add directory renaming test to existing FileContext tests.
Contributed by Eli Collins.
Modified:
hadoop/common/trunk/CHANGES.txt
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
Modified: hadoop/common/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/CHANGES.txt?rev=933705&r1=933704&r2=933705&view=diff
==============================================================================
--- hadoop/common/trunk/CHANGES.txt (original)
+++ hadoop/common/trunk/CHANGES.txt Tue Apr 13 17:00:26 2010
@@ -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
Modified:
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
URL:
http://svn.apache.org/viewvc/hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java?rev=933705&r1=933704&r2=933705&view=diff
==============================================================================
---
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
(original)
+++
hadoop/common/trunk/src/test/core/org/apache/hadoop/fs/FileContextMainOperationsBaseTest.java
Tue Apr 13 17:00:26 2010
@@ -750,14 +750,14 @@ public abstract class FileContextMainOpe
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 abstract class FileContextMainOpe
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 abstract class FileContextMainOpe
// 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 abstract class FileContextMainOpe
// 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 abstract class FileContextMainOpe
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 @@ public abstract class FileContextMainOpe
}
@Test
- public void testRenameDirectoryAsNonEmptyDirectory() throws Exception {
+ public void testRenameDirectoryAsEmptyDirectory() throws Exception {
if (!renameSupported()) return;
Path src = getTestRootPath(fc, "test/hadoop/dir");
@@ -904,20 +904,45 @@ public abstract class FileContextMainOpe
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 abstract class FileContextMainOpe
// 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) {
}
}