CGroupsResourceCalculator extends ResourceCalculatorProcessTree { void setCGroupFilePaths() throws YarnException { if (cGroupsHandler == null) { throw new YarnException("CGroups handler is not initialized"); } File cpuDir = new File( cGroupsHandler.getControllerPath( CGroupsHandler.CGroupController.CPUACCT), getCGroupRelativePath(CGroupsHandler.CGroupController.CPUACCT)); File memDir = new File( cGroupsHandler.getControllerPath( CGroupsHandler.CGroupController.MEMORY), getCGroupRelativePath(CGroupsHandler.CGroupController.MEMORY)); cpuStat = new File(cpuDir, CPU_STAT); memStat = new File(memDir, MEM_STAT); memswStat = new File(memDir, MEMSW_STAT); } CGroupsResourceCalculator();  CGroupsResourceCalculator(String pid); @VisibleForTesting  CGroupsResourceCalculator(String pid, String procfsDir,
                            CGroupsHandler cGroupsHandler,
                            Clock clock,
                            long jiffyLengthMs0); @Override void initialize(); @Override float getCpuUsagePercent(); @Override long getCumulativeCpuTime(); @Override long getRssMemorySize(int olderThanAge); @Override long getVirtualMemorySize(int olderThanAge); @Override void updateProcessTree(); @Override String getProcessTreeDump(); @Override boolean checkPidPgrpidForMatch(); static boolean isAvailable();  }
@Test(expected = YarnException.class) public void testPidNotFound() throws Exception { CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( "1234", ".", cGroupsHandler, clock, 10); calculator.setCGroupFilePaths(); Assert.assertEquals("Expected exception", null, calculator); }
@Test(expected = YarnException.class) public void testNoMemoryCGgroupMount() throws Exception { File procfs = new File(basePath + "/1234"); Assert.assertTrue("Setup error", procfs.mkdirs()); try { FileUtils.writeStringToFile( new File(procfs, CGroupsResourceCalculator.CGROUP), "7:devices:/yarn/container_1\n" + "6:cpuacct,cpu:/yarn/container_1\n" + "5:pids:/yarn/container_1\n", StandardCharsets.UTF_8); CGroupsResourceCalculator calculator = new CGroupsResourceCalculator( "1234", basePath, cGroupsHandler, clock, 10); calculator.setCGroupFilePaths(); Assert.assertEquals("Expected exception", null, calculator); } finally { FileUtils.deleteDirectory(new File(basePath)); } }