CGroupsHandlerImpl implements CGroupsHandler { @VisibleForTesting static String findControllerInMtab(String controller, Map<String, Set<String>> entries) { for (Map.Entry<String, Set<String>> e : entries.entrySet()) { if (e.getValue().contains(controller)) { if (new File(e.getKey()).canRead()) { return e.getKey(); } else { LOG.warn(String.format( "Skipping inaccessible cgroup mount point %s", e.getKey())); } } } return null; } CGroupsHandlerImpl(Configuration conf, PrivilegedOperationExecutor
      privilegedOperationExecutor, String mtab);   CGroupsHandlerImpl(Configuration conf, PrivilegedOperationExecutor
      privilegedOperationExecutor); @Override String getControllerPath(CGroupController controller); @Override String getRelativePathForCGroup(String cGroupId); @Override String getPathForCGroup(CGroupController controller, String cGroupId); @Override String getPathForCGroupTasks(CGroupController controller,
      String cGroupId); @Override String getPathForCGroupParam(CGroupController controller,
      String cGroupId, String param); @Override void initializeCGroupController(CGroupController controller); @Override String createCGroup(CGroupController controller, String cGroupId); @Override void deleteCGroup(CGroupController controller, String cGroupId); @Override void updateCGroupParam(CGroupController controller, String cGroupId,
      String param, String value); @Override String getCGroupParam(CGroupController controller, String cGroupId,
      String param); @Override String getCGroupMountPath();  }
@Test public void testSelectCgroup() throws Exception { File cpu = new File(tmpPath, "cpu"); File cpuNoExist = new File(tmpPath, "cpuNoExist"); File memory = new File(tmpPath, "memory"); try { CGroupsHandlerImpl handler = new CGroupsHandlerImpl( createNoMountConfiguration(tmpPath), privilegedOperationExecutorMock); Map<String, Set<String>> cgroups = new LinkedHashMap<>(); Assert.assertTrue("temp dir should be created", cpu.mkdirs()); Assert.assertTrue("temp dir should be created", memory.mkdirs()); Assert.assertFalse("temp dir should not be created", cpuNoExist.exists()); cgroups.put( memory.getAbsolutePath(), Collections.singleton("memory")); cgroups.put( cpuNoExist.getAbsolutePath(), Collections.singleton("cpu")); cgroups.put(cpu.getAbsolutePath(), Collections.singleton("cpu")); String selectedCPU = handler.findControllerInMtab("cpu", cgroups); Assert.assertEquals("Wrong CPU mount point selected", cpu.getAbsolutePath(), selectedCPU); } finally { FileUtils.deleteQuietly(cpu); FileUtils.deleteQuietly(memory); } }