CgroupsLCEResourcesHandler implements LCEResourcesHandler { @VisibleForTesting boolean deleteCgroup(String cgroupPath) { boolean deleted = false; LOG.debug("deleteCgroup: {}", cgroupPath); long start = clock.getTime(); do { try { deleted = checkAndDeleteCgroup(new File(cgroupPath)); if (!deleted) { Thread.sleep(deleteCgroupDelay); } } catch (InterruptedException ex) { } } while (!deleted && (clock.getTime() - start) < deleteCgroupTimeout); if (!deleted) { LOG.warn("Unable to delete cgroup at: " + cgroupPath + ", tried to delete for " + deleteCgroupTimeout + "ms"); } return deleted; } CgroupsLCEResourcesHandler(); @Override void setConf(Configuration conf); @Override Configuration getConf(); void init(LinuxContainerExecutor lce); void preExecute(ContainerId containerId, Resource containerResource); void postExecute(ContainerId containerId); String getResourcesOption(ContainerId containerId);  }
@Test public void testDeleteCgroup() throws Exception { final ControlledClock clock = new ControlledClock(); CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler(); handler.setConf(new YarnConfiguration()); handler.initConfig(); handler.clock = clock; FileUtils.deleteQuietly(cgroupDir); File tfile = new File(cgroupDir.getAbsolutePath(), "tasks"); FileOutputStream fos = FileUtils.openOutputStream(tfile); fos.write("1234".getBytes()); fos.close(); final CountDownLatch latch = new CountDownLatch(1); new Thread() { @Override public void run() { latch.countDown(); try { Thread.sleep(200); } catch (InterruptedException ex) { } clock.tickMsec(YarnConfiguration. DEFAULT_NM_LINUX_CONTAINER_CGROUPS_DELETE_TIMEOUT); } }.start(); latch.await(); Assert.assertFalse(handler.deleteCgroup(cgroupDir.getAbsolutePath())); FileUtils.deleteQuietly(cgroupDir); }