CgroupsLCEResourcesHandler implements LCEResourcesHandler { @VisibleForTesting int[] getOverallLimits(float yarnProcessors) { int[] ret = new int[2]; if (yarnProcessors < 0.01f) { throw new IllegalArgumentException("Number of processors can't be <= 0."); } int quotaUS = MAX_QUOTA_US; int periodUS = (int) (MAX_QUOTA_US / yarnProcessors); if (yarnProcessors < 1.0f) { periodUS = MAX_QUOTA_US; quotaUS = (int) (periodUS * yarnProcessors); if (quotaUS < MIN_PERIOD_US) { LOG .warn("The quota calculated for the cgroup was too low. The minimum value is " + MIN_PERIOD_US + ", calculated value is " + quotaUS + ". Setting quota to minimum value."); quotaUS = MIN_PERIOD_US; } } if (periodUS < MIN_PERIOD_US) { LOG .warn("The period calculated for the cgroup was too low. The minimum value is " + MIN_PERIOD_US + ", calculated value is " + periodUS + ". Using all available CPU."); periodUS = MAX_QUOTA_US; quotaUS = -1; } ret[0] = periodUS; ret[1] = quotaUS; return ret; } 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 testGetOverallLimits() { int expectedQuota = 1000 * 1000; CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler(); int[] ret = handler.getOverallLimits(2); Assert.assertEquals(expectedQuota / 2, ret[0]); Assert.assertEquals(expectedQuota, ret[1]); ret = handler.getOverallLimits(2000); Assert.assertEquals(expectedQuota, ret[0]); Assert.assertEquals(-1, ret[1]); int[] params = {0, -1}; for (int cores : params) { try { handler.getOverallLimits(cores); Assert.fail("Function call should throw error."); } catch (IllegalArgumentException ie) { } } ret = handler.getOverallLimits(1000 * 1000); Assert.assertEquals(1000 * 1000, ret[0]); Assert.assertEquals(-1, ret[1]); }
@Test public void testGetOverallLimits() { int expectedQuota = 1000 * 1000; CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler(); int[] ret = handler.getOverallLimits(2); Assert.assertEquals(expectedQuota / 2, ret[0]); Assert.assertEquals(expectedQuota, ret[1]); ret = handler.getOverallLimits(2000); Assert.assertEquals(expectedQuota, ret[0]); Assert.assertEquals(-1, ret[1]); int[] params = { 0, -1 }; for (int cores : params) { try { handler.getOverallLimits(cores); Assert.fail("Function call should throw error."); } catch (IllegalArgumentException ie) { } } ret = handler.getOverallLimits(1000 * 1000); Assert.assertEquals(1000 * 1000, ret[0]); Assert.assertEquals(-1, ret[1]); }