@Test
public void testGetContainerCores() {

  YarnConfiguration conf = new YarnConfiguration();
  float ret;
  final int numProcessors = 4;
  ResourceCalculatorPlugin plugin =
      Mockito.mock(ResourceCalculatorPlugin.class);
  Mockito.doReturn(numProcessors).when(plugin).getNumProcessors();
  conf.setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 0);
  try {
    NodeManagerHardwareUtils.getContainersCores(plugin, conf);
    Assert.fail("getContainerCores should have thrown exception");
  } catch (IllegalArgumentException ie) {
    // expected
  }
  conf.setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT,
    100);
  ret = NodeManagerHardwareUtils.getContainersCores(plugin, conf);
  Assert.assertEquals(4, (int) ret);
  conf
    .setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 50);
  ret = NodeManagerHardwareUtils.getContainersCores(plugin, conf);
  Assert.assertEquals(2, (int) ret);
  conf
    .setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 75);
  ret = NodeManagerHardwareUtils.getContainersCores(plugin, conf);
  Assert.assertEquals(3, (int) ret);
  conf
    .setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT, 85);
  ret = NodeManagerHardwareUtils.getContainersCores(plugin, conf);
  Assert.assertEquals(3.4, ret, 0.1);
  conf.setInt(YarnConfiguration.NM_RESOURCE_PERCENTAGE_PHYSICAL_CPU_LIMIT,
    110);
  ret = NodeManagerHardwareUtils.getContainersCores(plugin, conf);
  Assert.assertEquals(4, (int) ret);
}