コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }