Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,28 @@ public void testMkdirsFailsForSubdirectoryOfExistingFile() throws Exception {
createFile(getTestRootPath(fSys, "test/hadoop/file"));

Path testSubDir = getTestRootPath(fSys, "test/hadoop/file/subdir");


boolean thrown = false;
try{
Assert.assertFalse(fSys.mkdirs(testSubDir));
}catch(FileAlreadyExistsException ex){
// catch exception as expected.
fSys.mkdirs(testSubDir);
}catch(Exception ex){
thrown = true;
assertParentNotDirectoryException(ex);
}
Assert.assertTrue(thrown);

Assert.assertFalse(exists(fSys, testSubDir));

Path testDeepSubDir = getTestRootPath(fSys, "test/hadoop/file/deep/sub/dir");
Assert.assertFalse(exists(fSys, testSubDir));
thrown = false;
try{
Assert.assertFalse(fSys.mkdirs(testDeepSubDir));
}catch(FileAlreadyExistsException ex){
// catch exception as expected.
}catch(Exception ex){
thrown = true;
assertParentNotDirectoryException(ex);
}
Assert.assertTrue(thrown);
Assert.assertFalse(exists(fSys, testDeepSubDir));

}
Expand Down Expand Up @@ -97,4 +103,14 @@ protected Path getDefaultWorkingDirectory() throws IOException {
}


private void assertParentNotDirectoryException(Exception ex) {
// Hadoop <=2.5 uses FileAlreadyExistsException (HADOOP-9361)
// Hadoop >=2.6 uses ParentNotDirectoryException
String errorMsg = "expected FileAlreadyExistsException or ParentNotDirectoryException, got " + ex.getClass().getName();
Assert.assertTrue(
errorMsg,
"org.apache.hadoop.fs.FileAlreadyExistsException".equals(ex.getClass().getName())
|| "org.apache.hadoop.fs.ParentNotDirectoryException".equals(ex.getClass().getName()));
}

}