DefaultContainerExecutor extends ContainerExecutor { @Private @VisibleForTesting int pickDirectory(long randomPosition, final long[] availableOnDisk) { int dir = 0; while (availableOnDisk[dir] == 0L) { dir++; } while (randomPosition >= availableOnDisk[dir]) { randomPosition -= availableOnDisk[dir++]; } return dir; } @VisibleForTesting  DefaultContainerExecutor();   DefaultContainerExecutor(FileContext lfs); @Override void init(Context nmContext); @Override void startLocalizer(LocalizerStartContext ctx); @Override int launchContainer(ContainerStartContext ctx); @Override int relaunchContainer(ContainerStartContext ctx); @Override boolean signalContainer(ContainerSignalContext ctx); @Override boolean reapContainer(ContainerReapContext ctx); @Override boolean isContainerAlive(ContainerLivenessContext ctx); @VisibleForTesting static boolean containerIsAlive(String pid); @Override void deleteAsUser(DeletionAsUserContext ctx); @Override void symLink(String target, String symlink); @VisibleForTesting String getLogDirPermissions(); @VisibleForTesting void clearLogDirPermissions(); @Override IOStreamPair execContainer(ContainerExecContext ctx); @Override void updateYarnSysFS(Context ctx, String user,
      String appId, String spec);  }
@Test public void testPickDirectory() throws Exception { Configuration conf = new Configuration(); FileContext lfs = FileContext.getLocalFSFileContext(conf); DefaultContainerExecutor executor = new DefaultContainerExecutor(lfs); long[] availableOnDisk = new long[2]; availableOnDisk[0] = 100; availableOnDisk[1] = 100; assertEquals(0, executor.pickDirectory(0L, availableOnDisk)); assertEquals(0, executor.pickDirectory(99L, availableOnDisk)); assertEquals(1, executor.pickDirectory(100L, availableOnDisk)); assertEquals(1, executor.pickDirectory(101L, availableOnDisk)); assertEquals(1, executor.pickDirectory(199L, availableOnDisk)); long[] availableOnDisk2 = new long[5]; availableOnDisk2[0] = 100; availableOnDisk2[1] = 10; availableOnDisk2[2] = 400; availableOnDisk2[3] = 200; availableOnDisk2[4] = 350; assertEquals(0, executor.pickDirectory(0L, availableOnDisk2)); assertEquals(0, executor.pickDirectory(99L, availableOnDisk2)); assertEquals(1, executor.pickDirectory(100L, availableOnDisk2)); assertEquals(1, executor.pickDirectory(105L, availableOnDisk2)); assertEquals(2, executor.pickDirectory(110L, availableOnDisk2)); assertEquals(2, executor.pickDirectory(259L, availableOnDisk2)); assertEquals(3, executor.pickDirectory(700L, availableOnDisk2)); assertEquals(4, executor.pickDirectory(710L, availableOnDisk2)); assertEquals(4, executor.pickDirectory(910L, availableOnDisk2)); }