### Question:
LocalDirAllocator { int getCurrentDirectoryIndex() { AllocatorPerContext context = obtainContext(contextCfgItemName); return context.getCurrentDirectoryIndex(); } LocalDirAllocator(String contextCfgItemName); 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; }### Answer:
@Test public void testDirsNotExist() throws Exception { if (isWindows) return; String dir2 = buildBufferDir(ROOT, 2); String dir3 = buildBufferDir(ROOT, 3); try { conf.set(CONTEXT, dir2 + "," + dir3); createTempFile(SMALL_FILE_SIZE); int firstDirIdx = (dirAllocator.getCurrentDirectoryIndex() == 0) ? 2 : 3; int secondDirIdx = (firstDirIdx == 2) ? 3 : 2; validateTempDirCreation(buildBufferDir(ROOT, firstDirIdx)); validateTempDirCreation(buildBufferDir(ROOT, secondDirIdx)); validateTempDirCreation(buildBufferDir(ROOT, firstDirIdx)); } finally { rmBufferDirs(); } }
@Test public void testRWBufferDirBecomesRO() throws Exception { if (isWindows) return; String dir3 = buildBufferDir(ROOT, 3); String dir4 = buildBufferDir(ROOT, 4); try { conf.set(CONTEXT, dir3 + "," + dir4); assertTrue(localFs.mkdirs(new Path(dir3))); assertTrue(localFs.mkdirs(new Path(dir4))); createTempFile(SMALL_FILE_SIZE); int nextDirIdx = (dirAllocator.getCurrentDirectoryIndex() == 0) ? 3 : 4; validateTempDirCreation(buildBufferDir(ROOT, nextDirIdx)); new File(new Path(dir4).toUri().getPath()).setReadOnly(); validateTempDirCreation(dir3); validateTempDirCreation(dir3); } finally { rmBufferDirs(); } }