HADOOP-8437. getLocalPathForWrite should throw IOException for invalid paths. Contributed by Brahma Reddy Battula

(cherry picked from commit fd026f535c)
This commit is contained in:
Zhihai Xu 2015-10-01 11:56:49 -07:00
parent db145e0c9a
commit 07f9405692
3 changed files with 24 additions and 2 deletions

View File

@ -601,6 +601,9 @@ Release 2.8.0 - UNRELEASED
HADOOP-10296. Incorrect null check in SwiftRestClient#buildException().
(Rahul Palamuttam and Kanaka Kumar Avvaru via aajisaka)
HADOOP-8437. getLocalPathForWrite should throw IOException for invalid
paths. (Brahma Reddy Battula via zxu)
OPTIMIZATIONS
HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

View File

@ -304,8 +304,10 @@ public class LocalDirAllocator {
dirDF = dfList.toArray(new DF[dirs.size()]);
savedLocalDirs = newLocalDirs;
// randomize the first disk picked in the round-robin selection
dirNumLastAccessed = dirIndexRandomizer.nextInt(dirs.size());
if (dirs.size() > 0) {
// randomize the first disk picked in the round-robin selection
dirNumLastAccessed = dirIndexRandomizer.nextInt(dirs.size());
}
}
}

View File

@ -458,4 +458,21 @@ public class TestLocalDirAllocator {
}
}
/**
* Test to check the LocalDirAllocation for the invalid path HADOOP-8437
*
* @throws Exception
*/
@Test(timeout = 30000)
public void testGetLocalPathForWriteForInvalidPaths() throws Exception {
conf.set(CONTEXT, " ");
try {
dirAllocator.getLocalPathForWrite("/test", conf);
fail("not throwing the exception");
} catch (IOException e) {
assertEquals("Incorrect exception message",
"No space available in any of the local directories.", e.getMessage());
}
}
}