CgroupsLCEResourcesHandler implements LCEResourcesHandler { public void init(LinuxContainerExecutor lce) throws IOException { this.init(lce, ResourceCalculatorPlugin.getResourceCalculatorPlugin(null, conf)); } CgroupsLCEResourcesHandler(); @Override void setConf(Configuration conf); @Override Configuration getConf(); void init(LinuxContainerExecutor lce); void preExecute(ContainerId containerId, Resource containerResource); void postExecute(ContainerId containerId); String getResourcesOption(ContainerId containerId);  }
@Test public void testInit() throws IOException { LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor(); CustomCgroupsLCEResourceHandler handler = new CustomCgroupsLCEResourceHandler(); YarnConfiguration conf = new YarnConfiguration(); final int numProcessors = 4; ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class); Mockito.doReturn(numProcessors).when(plugin).getNumProcessors(); handler.setConf(conf); handler.initConfig(); File cgroupDir = createMockCgroup(); File cgroupMountDir = createMockCgroupMount(cgroupDir); File mockMtab = createMockMTab(cgroupDir); handler.setMtabFile(mockMtab.getAbsolutePath()); handler.init(mockLCE, plugin); File periodFile = new File(cgroupMountDir, "cpu.cfs_period_us"); File quotaFile = new File(cgroupMountDir, "cpu.cfs_quota_us"); Assert.assertFalse(periodFile.exists()); Assert.assertFalse(quotaFile.exists()); conf .setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 75); handler.limits[0] = 100 * 1000; handler.limits[1] = 1000 * 1000; handler.init(mockLCE, plugin); int period = readIntFromFile(periodFile); int quota = readIntFromFile(quotaFile); Assert.assertEquals(100 * 1000, period); Assert.assertEquals(1000 * 1000, quota); conf.setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 100); handler.limits[0] = 100 * 1000; handler.limits[1] = 1000 * 1000; handler.init(mockLCE, plugin); quota = readIntFromFile(quotaFile); Assert.assertEquals(-1, quota); FileUtils.deleteQuietly(cgroupDir); }
@Test public void testInit() throws IOException { LinuxContainerExecutor mockLCE = new MockLinuxContainerExecutor(); CustomCgroupsLCEResourceHandler handler = new CustomCgroupsLCEResourceHandler(); YarnConfiguration conf = new YarnConfiguration(); final int numProcessors = 4; ResourceCalculatorPlugin plugin = Mockito.mock(ResourceCalculatorPlugin.class); Mockito.doReturn(numProcessors).when(plugin).getNumProcessors(); Mockito.doReturn(numProcessors).when(plugin).getNumCores(); handler.setConf(conf); handler.initConfig(); File mockMtab = TestCGroupsHandlerImpl.createPremountedCgroups(cgroupDir, false); File cpuCgroupMountDir = createMockCgroupMount( cgroupDir, "cpu"); handler.setMtabFile(mockMtab.getAbsolutePath()); handler.init(mockLCE, plugin); File periodFile = new File(cpuCgroupMountDir, "cpu.cfs_period_us"); File quotaFile = new File(cpuCgroupMountDir, "cpu.cfs_quota_us"); Assert.assertFalse(periodFile.exists()); Assert.assertFalse(quotaFile.exists()); conf .setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 75); handler.limits[0] = 100 * 1000; handler.limits[1] = 1000 * 1000; handler.init(mockLCE, plugin); int period = readIntFromFile(periodFile); int quota = readIntFromFile(quotaFile); Assert.assertEquals(100 * 1000, period); Assert.assertEquals(1000 * 1000, quota); conf.setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 100); handler.limits[0] = 100 * 1000; handler.limits[1] = 1000 * 1000; handler.init(mockLCE, plugin); quota = readIntFromFile(quotaFile); Assert.assertEquals(-1, quota); FileUtils.deleteQuietly(cgroupDir); }