LocalDirAllocator { public Path getLocalPathForWrite(String pathStr, Configuration conf) throws IOException { return getLocalPathForWrite(pathStr, SIZE_UNKNOWN, conf); } LocalDirAllocator(String contextCfgItemName);  LocalDirAllocator(String contextCfgItemName,
          DiskValidator diskValidator); Path getLocalPathForWrite(String pathStr, 
      Configuration conf); Path getLocalPathForWrite(String pathStr, long size, 
      Configuration conf); Path getLocalPathForWrite(String pathStr, long size, 
                                   Configuration conf,
                                   boolean checkWrite); Path getLocalPathToRead(String pathStr, 
      Configuration conf); Iterable<Path> getAllLocalPathsToRead(String pathStr, 
                                               Configuration conf
                                               ); File createTmpFileForWrite(String pathStr, long size, 
      Configuration conf); static boolean isContextValid(String contextCfgItemName); @Deprecated @InterfaceAudience.LimitedPrivate({"MapReduce"}) static void removeContext(String contextCfgItemName); boolean ifExists(String pathStr,Configuration conf); static final int SIZE_UNKNOWN; }
@Test (timeout = 30000) public void testLocalPathForWriteDirCreation() throws IOException { String dir0 = buildBufferDir(ROOT, 0); String dir1 = buildBufferDir(ROOT, 1); try { conf.set(CONTEXT, dir0 + "," + dir1); assertTrue(localFs.mkdirs(new Path(dir1))); BUFFER_ROOT.setReadOnly(); Path p1 = dirAllocator.getLocalPathForWrite("p1/x", SMALL_FILE_SIZE, conf); assertTrue(localFs.getFileStatus(p1.getParent()).isDirectory()); Path p2 = dirAllocator.getLocalPathForWrite("p2/x", SMALL_FILE_SIZE, conf, false); try { localFs.getFileStatus(p2.getParent()); } catch (Exception e) { assertEquals(e.getClass(), FileNotFoundException.class); } } finally { Shell.execCommand(Shell.getSetPermissionCommand("u+w", false, BUFFER_DIR_ROOT)); rmBufferDirs(); } }
@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()); } }