HADOOP-6689. Add directory renaming test to existing FileContext tests. Contributed by Eli Collins.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@933705 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
631f45618d
commit
87c788d2e1
|
@ -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
|
||||
|
|
|
@ -750,14 +750,14 @@ public abstract class FileContextMainOperationsBaseTest {
|
|||
|
||||
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 FileContextMainOperationsBaseTest {
|
|||
|
||||
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 FileContextMainOperationsBaseTest {
|
|||
// 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 FileContextMainOperationsBaseTest {
|
|||
// 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 FileContextMainOperationsBaseTest {
|
|||
|
||||
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);
|
||||
}
|
||||
|
@ -893,6 +893,30 @@ public abstract class FileContextMainOperationsBaseTest {
|
|||
fc.exists(getTestRootPath(fc, "test/new/newdir/subdir/file2")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRenameDirectoryAsEmptyDirectory() 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);
|
||||
|
||||
// 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;
|
||||
|
@ -908,16 +932,17 @@ public abstract class FileContextMainOperationsBaseTest {
|
|||
// 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 FileContextMainOperationsBaseTest {
|
|||
// 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) {
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue