CGroupsHandlerImpl implements CGroupsHandler { @Override public void initializeCGroupController(CGroupController controller) throws ResourceHandlerException { if (enableCGroupMount) { mountCGroupController(controller); } initializePreMountedCGroupController(controller); } 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 testMountController() throws IOException { File parentDir = new File(tmpPath); File cgroup = new File(parentDir, controller.getName()); assertTrue("cgroup dir should be cerated", cgroup.mkdirs()); verifyZeroInteractions(privilegedOperationExecutorMock); File emptyMtab = createEmptyCgroups(); try { CGroupsHandler cGroupsHandler = new CGroupsHandlerImpl( createMountConfiguration(), privilegedOperationExecutorMock, emptyMtab.getAbsolutePath()); PrivilegedOperation expectedOp = new PrivilegedOperation( PrivilegedOperation.OperationType.MOUNT_CGROUPS); String controllerKV = controller.getName() + "=" + tmpPath + Path.SEPARATOR + controller.getName(); expectedOp.appendArgs(hierarchy, controllerKV); cGroupsHandler.initializeCGroupController(controller); try { ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass( PrivilegedOperation.class); verify(privilegedOperationExecutorMock) .executePrivilegedOperation(opCaptor.capture(), eq(false)); Assert.assertEquals(expectedOp, opCaptor.getValue()); verifyNoMoreInteractions(privilegedOperationExecutorMock); cGroupsHandler.initializeCGroupController(controller); verifyNoMoreInteractions(privilegedOperationExecutorMock); } catch (PrivilegedOperationException e) { LOG.error("Caught exception: " + e); assertTrue("Unexpected PrivilegedOperationException from mock!", false); } } catch (ResourceHandlerException e) { LOG.error("Caught exception: " + e); assertTrue("Unexpected ResourceHandler Exception!", false); } }
@Test public void testRemount() throws Exception { File parentDir = new File(tmpPath); final String oldMountPointDir = "oldmount"; final String newMountPointDir = "newmount"; File oldMountPoint = new File(parentDir, oldMountPointDir); File mtab = createPremountedCgroups( oldMountPoint, true); File newMountPoint = new File(parentDir, newMountPointDir); assertTrue("Could not create dirs", new File(newMountPoint, "cpu").mkdirs()); Configuration confMount = createMountConfiguration(); confMount.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH, parentDir.getAbsolutePath() + Path.SEPARATOR + newMountPointDir); CGroupsHandlerImpl cGroupsHandler = new CGroupsHandlerImpl(confMount, privilegedOperationExecutorMock, mtab.getAbsolutePath()); cGroupsHandler.initializeCGroupController( CGroupsHandler.CGroupController.CPU); ArgumentCaptor<PrivilegedOperation> opCaptor = ArgumentCaptor.forClass( PrivilegedOperation.class); verify(privilegedOperationExecutorMock) .executePrivilegedOperation(opCaptor.capture(), eq(false)); File hierarchyFile = new File(new File(newMountPoint, "cpu"), this.hierarchy); assertTrue("Yarn cgroup should exist", hierarchyFile.exists()); }