NodeManagerHardwareUtils { public static long getContainerMemoryMB(Configuration conf) { if (!isHardwareDetectionEnabled(conf)) { return getConfiguredMemoryMB(conf); } ResourceCalculatorPlugin plugin = ResourceCalculatorPlugin.getResourceCalculatorPlugin(null, conf); if (plugin == null) { return getConfiguredMemoryMB(conf); } return getContainerMemoryMBInternal(plugin, conf); }  static int getNodeCPUs(Configuration conf); static int getNodeCPUs(ResourceCalculatorPlugin plugin,
      Configuration conf); static float getContainersCPUs(Configuration conf); static float getContainersCPUs(ResourceCalculatorPlugin plugin,
      Configuration conf); static int getNodeCpuPercentage(Configuration conf); static int getVCores(Configuration conf); static int getVCores(ResourceCalculatorPlugin plugin,
      Configuration conf); static long getContainerMemoryMB(Configuration conf); static long getContainerMemoryMB(ResourceCalculatorPlugin plugin,
      Configuration conf); static Resource getNodeResources(Configuration configuration);  }
@Test public void testGetContainerMemoryMB() throws Exception { ResourceCalculatorPlugin plugin = new TestResourceCalculatorPlugin(); long physicalMemMB = plugin.getPhysicalMemorySize() / (1024 * 1024); YarnConfiguration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.NM_ENABLE_HARDWARE_CAPABILITY_DETECTION, true); long mem = NodeManagerHardwareUtils.getContainerMemoryMB(null, conf); Assert.assertEquals(YarnConfiguration.DEFAULT_NM_PMEM_MB, mem); mem = NodeManagerHardwareUtils.getContainerMemoryMB(plugin, conf); int hadoopHeapSizeMB = (int) (Runtime.getRuntime().maxMemory() / (1024 * 1024)); int calculatedMemMB = (int) (0.8 * (physicalMemMB - (2 * hadoopHeapSizeMB))); Assert.assertEquals(calculatedMemMB, mem); conf.setInt(YarnConfiguration.NM_PMEM_MB, 1024); mem = NodeManagerHardwareUtils.getContainerMemoryMB(conf); Assert.assertEquals(1024, mem); conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.NM_ENABLE_HARDWARE_CAPABILITY_DETECTION, false); mem = NodeManagerHardwareUtils.getContainerMemoryMB(conf); Assert.assertEquals(YarnConfiguration.DEFAULT_NM_PMEM_MB, mem); conf.setInt(YarnConfiguration.NM_PMEM_MB, 10 * 1024); mem = NodeManagerHardwareUtils.getContainerMemoryMB(conf); Assert.assertEquals(10 * 1024, mem); }