public virtual void TestcheckAndDeleteCgroup() { CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler(); handler.SetConf(new YarnConfiguration()); handler.InitConfig(); FileUtils.DeleteQuietly(cgroupDir); // Test 0 // tasks file not present, should return false NUnit.Framework.Assert.IsFalse(handler.CheckAndDeleteCgroup(cgroupDir)); FilePath tfile = new FilePath(cgroupDir.GetAbsolutePath(), "tasks"); FileOutputStream fos = FileUtils.OpenOutputStream(tfile); FilePath fspy = Org.Mockito.Mockito.Spy(cgroupDir); // Test 1, tasks file is empty // tasks file has no data, should return true Org.Mockito.Mockito.Stub(fspy.Delete()).ToReturn(true); NUnit.Framework.Assert.IsTrue(handler.CheckAndDeleteCgroup(fspy)); // Test 2, tasks file has data fos.Write(Sharpen.Runtime.GetBytesForString("1234")); fos.Close(); // tasks has data, would not be able to delete, should return false NUnit.Framework.Assert.IsFalse(handler.CheckAndDeleteCgroup(fspy)); FileUtils.DeleteQuietly(cgroupDir); }
public virtual void TestDeleteCgroup() { TestCgroupsLCEResourcesHandler.MockClock clock = new TestCgroupsLCEResourcesHandler.MockClock (); clock.time = Runtime.CurrentTimeMillis(); CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler(); handler.SetConf(new YarnConfiguration()); handler.InitConfig(); handler.clock = clock; FileUtils.DeleteQuietly(cgroupDir); // Create a non-empty tasks file FilePath tfile = new FilePath(cgroupDir.GetAbsolutePath(), "tasks"); FileOutputStream fos = FileUtils.OpenOutputStream(tfile); fos.Write(Sharpen.Runtime.GetBytesForString("1234")); fos.Close(); CountDownLatch latch = new CountDownLatch(1); new _Thread_112(latch, clock).Start(); //NOP latch.Await(); NUnit.Framework.Assert.IsFalse(handler.DeleteCgroup(cgroupDir.GetAbsolutePath())); FileUtils.DeleteQuietly(cgroupDir); }
public virtual void TestGetOverallLimits() { int expectedQuota = 1000 * 1000; CgroupsLCEResourcesHandler handler = new CgroupsLCEResourcesHandler(); int[] ret = handler.GetOverallLimits(2); NUnit.Framework.Assert.AreEqual(expectedQuota / 2, ret[0]); NUnit.Framework.Assert.AreEqual(expectedQuota, ret[1]); ret = handler.GetOverallLimits(2000); NUnit.Framework.Assert.AreEqual(expectedQuota, ret[0]); NUnit.Framework.Assert.AreEqual(-1, ret[1]); int[] @params = new int[] { 0, -1 }; foreach (int cores in @params) { try { handler.GetOverallLimits(cores); NUnit.Framework.Assert.Fail("Function call should throw error."); } catch (ArgumentException) { } } // expected // test minimums ret = handler.GetOverallLimits(1000 * 1000); NUnit.Framework.Assert.AreEqual(1000 * 1000, ret[0]); NUnit.Framework.Assert.AreEqual(-1, ret[1]); }