public virtual void Setup() { // setup a context / conf csConf = new CapacitySchedulerConfiguration(); YarnConfiguration conf = new YarnConfiguration(); csContext = Org.Mockito.Mockito.Mock <CapacitySchedulerContext>(); Org.Mockito.Mockito.When(csContext.GetConfiguration()).ThenReturn(csConf); Org.Mockito.Mockito.When(csContext.GetConf()).ThenReturn(conf); Org.Mockito.Mockito.When(csContext.GetMinimumResourceCapability()).ThenReturn(Resources .CreateResource(Gb, 1)); Org.Mockito.Mockito.When(csContext.GetMaximumResourceCapability()).ThenReturn(Resources .CreateResource(16 * Gb, 32)); Org.Mockito.Mockito.When(csContext.GetClusterResource()).ThenReturn(Resources.CreateResource (100 * 16 * Gb, 100 * 32)); Org.Mockito.Mockito.When(csContext.GetResourceCalculator()).ThenReturn(resourceCalculator ); RMContext mockRMContext = TestUtils.GetMockRMContext(); Org.Mockito.Mockito.When(csContext.GetRMContext()).ThenReturn(mockRMContext); // create a queue PlanQueue pq = new PlanQueue(csContext, "root", null, null); reservationQueue = new ReservationQueue(csContext, "a", pq); }
public virtual void TestMoveAppToPlanQueue() { CapacityScheduler scheduler = (CapacityScheduler)rm.GetResourceScheduler(); // submit an app RMApp app = rm.SubmitApp(Gb, "test-move-1", "user_0", null, "b1"); ApplicationAttemptId appAttemptId = rm.GetApplicationReport(app.GetApplicationId( )).GetCurrentApplicationAttemptId(); // check preconditions IList <ApplicationAttemptId> appsInB1 = scheduler.GetAppsInQueue("b1"); NUnit.Framework.Assert.AreEqual(1, appsInB1.Count); IList <ApplicationAttemptId> appsInB = scheduler.GetAppsInQueue("b"); NUnit.Framework.Assert.AreEqual(1, appsInB.Count); NUnit.Framework.Assert.IsTrue(appsInB.Contains(appAttemptId)); IList <ApplicationAttemptId> appsInA = scheduler.GetAppsInQueue("a"); NUnit.Framework.Assert.IsTrue(appsInA.IsEmpty()); string queue = scheduler.GetApplicationAttempt(appsInB1[0]).GetQueue().GetQueueName (); NUnit.Framework.Assert.IsTrue(queue.Equals("b1")); IList <ApplicationAttemptId> appsInRoot = scheduler.GetAppsInQueue("root"); NUnit.Framework.Assert.IsTrue(appsInRoot.Contains(appAttemptId)); NUnit.Framework.Assert.AreEqual(1, appsInRoot.Count); // create the default reservation queue string defQName = "a" + ReservationConstants.DefaultQueueSuffix; ReservationQueue defQ = new ReservationQueue(scheduler, defQName, (PlanQueue)scheduler .GetQueue("a")); scheduler.AddQueue(defQ); defQ.SetEntitlement(new QueueEntitlement(1f, 1f)); IList <ApplicationAttemptId> appsInDefQ = scheduler.GetAppsInQueue(defQName); NUnit.Framework.Assert.IsTrue(appsInDefQ.IsEmpty()); // now move the app to plan queue scheduler.MoveApplication(app.GetApplicationId(), "a"); // check postconditions appsInDefQ = scheduler.GetAppsInQueue(defQName); NUnit.Framework.Assert.AreEqual(1, appsInDefQ.Count); queue = scheduler.GetApplicationAttempt(appsInDefQ[0]).GetQueue().GetQueueName(); NUnit.Framework.Assert.IsTrue(queue.Equals(defQName)); appsInA = scheduler.GetAppsInQueue("a"); NUnit.Framework.Assert.IsTrue(appsInA.Contains(appAttemptId)); NUnit.Framework.Assert.AreEqual(1, appsInA.Count); appsInRoot = scheduler.GetAppsInQueue("root"); NUnit.Framework.Assert.IsTrue(appsInRoot.Contains(appAttemptId)); NUnit.Framework.Assert.AreEqual(1, appsInRoot.Count); appsInB1 = scheduler.GetAppsInQueue("b1"); NUnit.Framework.Assert.IsTrue(appsInB1.IsEmpty()); appsInB = scheduler.GetAppsInQueue("b"); NUnit.Framework.Assert.IsTrue(appsInB.IsEmpty()); rm.Stop(); }
public virtual void TestAddQueueFailCases() { CapacityScheduler cs = (CapacityScheduler)rm.GetResourceScheduler(); try { // Test invalid addition (adding non-zero size queue) ReservationQueue a1 = new ReservationQueue(cs, "a1", (PlanQueue)cs.GetQueue("a")); a1.SetEntitlement(new QueueEntitlement(A1Capacity / 100, 1f)); cs.AddQueue(a1); NUnit.Framework.Assert.Fail(); } catch (Exception) { } // expected // Test add one reservation dynamically and manually modify capacity ReservationQueue a1_1 = new ReservationQueue(cs, "a1", (PlanQueue)cs.GetQueue("a" )); cs.AddQueue(a1_1); a1_1.SetEntitlement(new QueueEntitlement(A1Capacity / 100, 1f)); // Test add another reservation queue and use setEntitlement to modify // capacity ReservationQueue a2 = new ReservationQueue(cs, "a2", (PlanQueue)cs.GetQueue("a")); cs.AddQueue(a2); try { // Test invalid entitlement (sum of queues exceed 100%) cs.SetEntitlement("a2", new QueueEntitlement(A2Capacity / 100 + 0.1f, 1.0f)); NUnit.Framework.Assert.Fail(); } catch (Exception) { } // expected cs.SetEntitlement("a2", new QueueEntitlement(A2Capacity / 100, 1.0f)); // Verify all allocations match tcs.CheckQueueCapacities(cs, ACapacity, BCapacity); cs.Stop(); }
public virtual void TestRemoveQueue() { CapacityScheduler cs = (CapacityScheduler)rm.GetResourceScheduler(); // Test add one reservation dynamically and manually modify capacity ReservationQueue a1 = new ReservationQueue(cs, "a1", (PlanQueue)cs.GetQueue("a")); cs.AddQueue(a1); a1.SetEntitlement(new QueueEntitlement(A1Capacity / 100, 1f)); // submit an app RMApp app = rm.SubmitApp(Gb, "test-move-1", "user_0", null, "a1"); // check preconditions IList <ApplicationAttemptId> appsInA1 = cs.GetAppsInQueue("a1"); NUnit.Framework.Assert.AreEqual(1, appsInA1.Count); try { cs.RemoveQueue("a1"); NUnit.Framework.Assert.Fail(); } catch (SchedulerDynamicEditException) { } // expected a1 contains applications // clear queue by killling all apps cs.KillAllAppsInQueue("a1"); // wait for events of move to propagate rm.WaitForState(app.GetApplicationId(), RMAppState.Killed); try { cs.RemoveQueue("a1"); NUnit.Framework.Assert.Fail(); } catch (SchedulerDynamicEditException) { } // expected a1 is not zero capacity // set capacity to zero cs.SetEntitlement("a1", new QueueEntitlement(0f, 0f)); cs.RemoveQueue("a1"); NUnit.Framework.Assert.IsTrue(cs.GetQueue("a1") == null); rm.Stop(); }
public virtual void TestRefreshQueuesWithReservations() { CapacityScheduler cs = (CapacityScheduler)rm.GetResourceScheduler(); // Test add one reservation dynamically and manually modify capacity ReservationQueue a1 = new ReservationQueue(cs, "a1", (PlanQueue)cs.GetQueue("a")); cs.AddQueue(a1); a1.SetEntitlement(new QueueEntitlement(A1Capacity / 100, 1f)); // Test add another reservation queue and use setEntitlement to modify // capacity ReservationQueue a2 = new ReservationQueue(cs, "a2", (PlanQueue)cs.GetQueue("a")); cs.AddQueue(a2); cs.SetEntitlement("a2", new QueueEntitlement(A2Capacity / 100, 1.0f)); // Verify all allocations match tcs.CheckQueueCapacities(cs, ACapacity, BCapacity); // Reinitialize and verify all dynamic queued survived CapacitySchedulerConfiguration conf = cs.GetConfiguration(); conf.SetCapacity(A, 80f); conf.SetCapacity(B, 20f); cs.Reinitialize(conf, rm.GetRMContext()); tcs.CheckQueueCapacities(cs, 80f, 20f); }