Ejemplo n.º 1
0
        public virtual void TestContainerMonitorMemFlags()
        {
            ContainersMonitor cm = null;
            long expPmem         = 8192 * 1024 * 1024l;
            long expVmem         = (long)(expPmem * 2.1f);

            cm = new ContainersMonitorImpl(Org.Mockito.Mockito.Mock <ContainerExecutor>(), Org.Mockito.Mockito.Mock
                                           <AsyncDispatcher>(), Org.Mockito.Mockito.Mock <Context>());
            cm.Init(GetConfForCM(false, false, 8192, 2.1f));
            NUnit.Framework.Assert.AreEqual(expPmem, cm.GetPmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(expVmem, cm.GetVmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(false, cm.IsPmemCheckEnabled());
            NUnit.Framework.Assert.AreEqual(false, cm.IsVmemCheckEnabled());
            cm = new ContainersMonitorImpl(Org.Mockito.Mockito.Mock <ContainerExecutor>(), Org.Mockito.Mockito.Mock
                                           <AsyncDispatcher>(), Org.Mockito.Mockito.Mock <Context>());
            cm.Init(GetConfForCM(true, false, 8192, 2.1f));
            NUnit.Framework.Assert.AreEqual(expPmem, cm.GetPmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(expVmem, cm.GetVmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(true, cm.IsPmemCheckEnabled());
            NUnit.Framework.Assert.AreEqual(false, cm.IsVmemCheckEnabled());
            cm = new ContainersMonitorImpl(Org.Mockito.Mockito.Mock <ContainerExecutor>(), Org.Mockito.Mockito.Mock
                                           <AsyncDispatcher>(), Org.Mockito.Mockito.Mock <Context>());
            cm.Init(GetConfForCM(true, true, 8192, 2.1f));
            NUnit.Framework.Assert.AreEqual(expPmem, cm.GetPmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(expVmem, cm.GetVmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(true, cm.IsPmemCheckEnabled());
            NUnit.Framework.Assert.AreEqual(true, cm.IsVmemCheckEnabled());
            cm = new ContainersMonitorImpl(Org.Mockito.Mockito.Mock <ContainerExecutor>(), Org.Mockito.Mockito.Mock
                                           <AsyncDispatcher>(), Org.Mockito.Mockito.Mock <Context>());
            cm.Init(GetConfForCM(false, true, 8192, 2.1f));
            NUnit.Framework.Assert.AreEqual(expPmem, cm.GetPmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(expVmem, cm.GetVmemAllocatedForContainers());
            NUnit.Framework.Assert.AreEqual(false, cm.IsPmemCheckEnabled());
            NUnit.Framework.Assert.AreEqual(true, cm.IsVmemCheckEnabled());
        }
Ejemplo n.º 2
0
 public MonitoringThread(ContainersMonitorImpl _enclosing)
     : base("Container Monitor")
 {
     this._enclosing = _enclosing;
 }
Ejemplo n.º 3
0
        public virtual void TestProcessTreeLimits()
        {
            // set up a dummy proc file system
            FilePath procfsRootDir = new FilePath(localDir, "proc");

            string[] pids = new string[] { "100", "200", "300", "400", "500", "600", "700" };
            try
            {
                TestProcfsBasedProcessTree.SetupProcfsRootDir(procfsRootDir);
                // create pid dirs.
                TestProcfsBasedProcessTree.SetupPidDirs(procfsRootDir, pids);
                // create process infos.
                TestProcfsBasedProcessTree.ProcessStatInfo[] procs = new TestProcfsBasedProcessTree.ProcessStatInfo
                                                                     [7];
                // assume pids 100, 500 are in 1 tree
                // 200,300,400 are in another
                // 600,700 are in a third
                procs[0] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "100", "proc1"
                                                                                         , "1", "100", "100", "100000" });
                procs[1] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "200", "proc2"
                                                                                         , "1", "200", "200", "200000" });
                procs[2] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "300", "proc3"
                                                                                         , "200", "200", "200", "300000" });
                procs[3] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "400", "proc4"
                                                                                         , "200", "200", "200", "400000" });
                procs[4] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "500", "proc5"
                                                                                         , "100", "100", "100", "1500000" });
                procs[5] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "600", "proc6"
                                                                                         , "1", "600", "600", "100000" });
                procs[6] = new TestProcfsBasedProcessTree.ProcessStatInfo(new string[] { "700", "proc7"
                                                                                         , "600", "600", "600", "100000" });
                // write stat files.
                TestProcfsBasedProcessTree.WriteStatFiles(procfsRootDir, pids, procs, null);
                // vmem limit
                long limit = 700000;
                ContainersMonitorImpl test = new ContainersMonitorImpl(null, null, null);
                // create process trees
                // tree rooted at 100 is over limit immediately, as it is
                // twice over the mem limit.
                ProcfsBasedProcessTree pTree = new ProcfsBasedProcessTree("100", procfsRootDir.GetAbsolutePath
                                                                              ());
                pTree.UpdateProcessTree();
                NUnit.Framework.Assert.IsTrue("tree rooted at 100 should be over limit " + "after first iteration."
                                              , test.IsProcessTreeOverLimit(pTree, "dummyId", limit));
                // the tree rooted at 200 is initially below limit.
                pTree = new ProcfsBasedProcessTree("200", procfsRootDir.GetAbsolutePath());
                pTree.UpdateProcessTree();
                NUnit.Framework.Assert.IsFalse("tree rooted at 200 shouldn't be over limit " + "after one iteration."
                                               , test.IsProcessTreeOverLimit(pTree, "dummyId", limit));
                // second iteration - now the tree has been over limit twice,
                // hence it should be declared over limit.
                pTree.UpdateProcessTree();
                NUnit.Framework.Assert.IsTrue("tree rooted at 200 should be over limit after 2 iterations"
                                              , test.IsProcessTreeOverLimit(pTree, "dummyId", limit));
                // the tree rooted at 600 is never over limit.
                pTree = new ProcfsBasedProcessTree("600", procfsRootDir.GetAbsolutePath());
                pTree.UpdateProcessTree();
                NUnit.Framework.Assert.IsFalse("tree rooted at 600 should never be over limit.",
                                               test.IsProcessTreeOverLimit(pTree, "dummyId", limit));
                // another iteration does not make any difference.
                pTree.UpdateProcessTree();
                NUnit.Framework.Assert.IsFalse("tree rooted at 600 should never be over limit.",
                                               test.IsProcessTreeOverLimit(pTree, "dummyId", limit));
            }
            finally
            {
                FileUtil.FullyDelete(procfsRootDir);
            }
        }