@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();
  // create mock mtab
  File mockMtab =
      TestCGroupsHandlerImpl.createPremountedCgroups(cgroupDir, false);
  // create mock cgroup
  File cpuCgroupMountDir = createMockCgroupMount(
      cgroupDir, "cpu");
  // setup our handler and call init()
  handler.setMtabFile(mockMtab.getAbsolutePath());
  // check values
  // in this case, we're using all cpu so the files
  // shouldn't exist(because init won't create them
  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());
  // subset of cpu being used, files should be created
  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);
  // set cpu back to 100, quota should be -1
  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);
}