@Test
public void testCgroupsHierarchySetting() throws ResourceHandlerException {

  YarnConfiguration conf = new YarnConfiguration();
  conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_MOUNT_PATH, tmpPath);
  conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY,
      "/hadoop-yarn");
  CGroupsHandlerImpl cGroupsHandler = new CGroupsHandlerImpl(conf, null);
  String expectedRelativePath = "hadoop-yarn/c1";
  Assert.assertEquals(expectedRelativePath,
      cGroupsHandler.getRelativePathForCGroup("c1"));
  conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY,
      "hadoop-yarn");
  cGroupsHandler = new CGroupsHandlerImpl(conf, null);
  Assert.assertEquals(expectedRelativePath,
      cGroupsHandler.getRelativePathForCGroup("c1"));
  conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY,
      "hadoop-yarn/");
  cGroupsHandler = new CGroupsHandlerImpl(conf, null);
  Assert.assertEquals(expectedRelativePath,
      cGroupsHandler.getRelativePathForCGroup("c1"));
  conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY,
      "//hadoop-yarn//");
  cGroupsHandler = new CGroupsHandlerImpl(conf, null);
  Assert.assertEquals(expectedRelativePath,
      cGroupsHandler.getRelativePathForCGroup("c1"));
  expectedRelativePath = "hadoop-yarn/root/c1";
  conf.set(YarnConfiguration.NM_LINUX_CONTAINER_CGROUPS_HIERARCHY,
      "//hadoop-yarn/root//");
  cGroupsHandler = new CGroupsHandlerImpl(conf, null);
  Assert.assertEquals(expectedRelativePath,
      cGroupsHandler.getRelativePathForCGroup("c1"));
}