/// <exception cref="System.Exception"/>
        public virtual void TestSchedulingDelay()
        {
            // Add one node
            string host  = "127.0.0.1";
            RMNode node1 = MockNodes.NewNodeInfo(1, Resources.CreateResource(4096, 4), 1, host
                                                 );
            NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node1);

            scheduler.Handle(nodeEvent1);
            NodeUpdateSchedulerEvent nodeUpdateEvent = new NodeUpdateSchedulerEvent(node1);

            scheduler.Handle(nodeUpdateEvent);
            // Create one application and submit one each of node-local, rack-local
            // and ANY requests
            ApplicationAttemptId appAttemptId = CreateAppAttemptId(this.AppId++, this.AttemptId
                                                                   ++);

            CreateMockRMApp(appAttemptId);
            scheduler.AddApplication(appAttemptId.GetApplicationId(), "queue11", "user11", false
                                     );
            scheduler.AddApplicationAttempt(appAttemptId, false, false);
            IList <ResourceRequest> ask = new AList <ResourceRequest>();

            ask.AddItem(CreateResourceRequest(1024, 1, ResourceRequest.Any, 1, 1, true));
            scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null);
            FSAppAttempt app = scheduler.GetSchedulerApp(appAttemptId);

            // Advance time and let continuous scheduling kick in
            mockClock.Tick(1);
            while (1024 != app.GetCurrentConsumption().GetMemory())
            {
                Sharpen.Thread.Sleep(100);
            }
            NUnit.Framework.Assert.AreEqual(1024, app.GetCurrentConsumption().GetMemory());
        }
        public virtual void TestRemoveEnablingOrderedByStartTime()
        {
            FSLeafQueue leaf1 = queueManager.GetLeafQueue("root.queue1.subqueue1.leaf1", true
                                                          );
            FSLeafQueue leaf2 = queueManager.GetLeafQueue("root.queue1.subqueue2.leaf2", true
                                                          );

            queueMaxApps["root.queue1"] = 2;
            FSAppAttempt app1 = AddApp(leaf1, "user");

            AddApp(leaf2, "user");
            AddApp(leaf2, "user");
            clock.Tick(20);
            AddApp(leaf1, "user");
            NUnit.Framework.Assert.AreEqual(1, leaf1.GetNumRunnableApps());
            NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumRunnableApps());
            NUnit.Framework.Assert.AreEqual(1, leaf1.GetNumNonRunnableApps());
            NUnit.Framework.Assert.AreEqual(1, leaf2.GetNumNonRunnableApps());
            RemoveApp(app1);
            NUnit.Framework.Assert.AreEqual(0, leaf1.GetNumRunnableApps());
            NUnit.Framework.Assert.AreEqual(2, leaf2.GetNumRunnableApps());
            NUnit.Framework.Assert.AreEqual(0, leaf2.GetNumNonRunnableApps());
        }
        public virtual void TestPreemptionWithFreeResources()
        {
            PrintWriter @out = new PrintWriter(new FileWriter(AllocFile));

            @out.WriteLine("<?xml version=\"1.0\"?>");
            @out.WriteLine("<allocations>");
            @out.WriteLine("<queue name=\"default\">");
            @out.WriteLine("<maxResources>0mb,0vcores</maxResources>");
            @out.WriteLine("</queue>");
            @out.WriteLine("<queue name=\"queueA\">");
            @out.WriteLine("<weight>1</weight>");
            @out.WriteLine("<minResources>1024mb,0vcores</minResources>");
            @out.WriteLine("</queue>");
            @out.WriteLine("<queue name=\"queueB\">");
            @out.WriteLine("<weight>1</weight>");
            @out.WriteLine("<minResources>1024mb,0vcores</minResources>");
            @out.WriteLine("</queue>");
            @out.Write("<defaultMinSharePreemptionTimeout>5</defaultMinSharePreemptionTimeout>"
                       );
            @out.Write("<fairSharePreemptionTimeout>10</fairSharePreemptionTimeout>");
            @out.WriteLine("</allocations>");
            @out.Close();
            StartResourceManager(0f);
            // Create node with 4GB memory and 4 vcores
            RegisterNodeAndSubmitApp(4 * 1024, 4, 2, 1024);
            // Verify submitting another request triggers preemption
            CreateSchedulingRequest(1024, "queueB", "user1", 1, 1);
            scheduler.Update();
            clock.Tick(6);
            ((TestFairSchedulerPreemption.StubbedFairScheduler)scheduler).ResetLastPreemptResources
                ();
            scheduler.PreemptTasksIfNecessary();
            NUnit.Framework.Assert.AreEqual("preemptResources() should have been called", 1024
                                            , ((TestFairSchedulerPreemption.StubbedFairScheduler)scheduler).lastPreemptMemory
                                            );
            resourceManager.Stop();
            StartResourceManager(0.8f);
            // Create node with 4GB memory and 4 vcores
            RegisterNodeAndSubmitApp(4 * 1024, 4, 3, 1024);
            // Verify submitting another request doesn't trigger preemption
            CreateSchedulingRequest(1024, "queueB", "user1", 1, 1);
            scheduler.Update();
            clock.Tick(6);
            ((TestFairSchedulerPreemption.StubbedFairScheduler)scheduler).ResetLastPreemptResources
                ();
            scheduler.PreemptTasksIfNecessary();
            NUnit.Framework.Assert.AreEqual("preemptResources() should not have been called",
                                            -1, ((TestFairSchedulerPreemption.StubbedFairScheduler)scheduler).lastPreemptMemory
                                            );
            resourceManager.Stop();
            StartResourceManager(0.7f);
            // Create node with 4GB memory and 4 vcores
            RegisterNodeAndSubmitApp(4 * 1024, 4, 3, 1024);
            // Verify submitting another request triggers preemption
            CreateSchedulingRequest(1024, "queueB", "user1", 1, 1);
            scheduler.Update();
            clock.Tick(6);
            ((TestFairSchedulerPreemption.StubbedFairScheduler)scheduler).ResetLastPreemptResources
                ();
            scheduler.PreemptTasksIfNecessary();
            NUnit.Framework.Assert.AreEqual("preemptResources() should have been called", 1024
                                            , ((TestFairSchedulerPreemption.StubbedFairScheduler)scheduler).lastPreemptMemory
                                            );
        }