From 230eb421da15ad212d056b78c3b908a235e643b2 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Thu, 18 Oct 2018 13:48:52 +0200 Subject: [PATCH] test: fix for hadoop >=2.6.0 Signed-off-by: Santiago M. Mola --- .../test/unit/HcfsMainOperationsBaseTest.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/hadoop/fs/test/unit/HcfsMainOperationsBaseTest.java b/src/test/java/org/apache/hadoop/fs/test/unit/HcfsMainOperationsBaseTest.java index 89629e8e..db6200a1 100644 --- a/src/test/java/org/apache/hadoop/fs/test/unit/HcfsMainOperationsBaseTest.java +++ b/src/test/java/org/apache/hadoop/fs/test/unit/HcfsMainOperationsBaseTest.java @@ -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)); } @@ -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())); + } + }