public virtual void TestDelayScheduling() { FSLeafQueue queue = Org.Mockito.Mockito.Mock <FSLeafQueue>(); Priority prio = Org.Mockito.Mockito.Mock <Priority>(); Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1); double nodeLocalityThreshold = .5; double rackLocalityThreshold = .6; ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); RMContext rmContext = resourceManager.GetRMContext(); FSAppAttempt schedulerApp = new FSAppAttempt(scheduler, applicationAttemptId, "user1" , queue, null, rmContext); // Default level should be node-local NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); // First five scheduling opportunities should remain node local for (int i = 0; i < 5; i++) { schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); } // After five it should switch to rack local schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); // Manually set back to node local schedulerApp.ResetAllowedLocalityLevel(prio, NodeType.NodeLocal); schedulerApp.ResetSchedulingOpportunities(prio); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); // Now escalate again to rack-local, then to off-switch for (int i_1 = 0; i_1 < 5; i_1++) { schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.NodeLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); } schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); for (int i_2 = 0; i_2 < 6; i_2++) { schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.RackLocal, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); } schedulerApp.AddSchedulingOpportunity(prio); NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevel (prio, 10, nodeLocalityThreshold, rackLocalityThreshold)); }
public virtual void TestLocalityLevelWithoutDelays() { FSLeafQueue queue = Org.Mockito.Mockito.Mock <FSLeafQueue>(); Priority prio = Org.Mockito.Mockito.Mock <Priority>(); Org.Mockito.Mockito.When(prio.GetPriority()).ThenReturn(1); RMContext rmContext = resourceManager.GetRMContext(); ApplicationAttemptId applicationAttemptId = CreateAppAttemptId(1, 1); FSAppAttempt schedulerApp = new FSAppAttempt(scheduler, applicationAttemptId, "user1" , queue, null, rmContext); NUnit.Framework.Assert.AreEqual(NodeType.OffSwitch, schedulerApp.GetAllowedLocalityLevel (prio, 10, -1.0, -1.0)); }