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(); }
// Test even if AM container is allocated with containerId not equal to 1, the // following allocate requests from AM should be able to retrieve the // corresponding NM Token. /// <exception cref="System.Exception"/> public virtual void TestNMTokenSentForNormalContainer() { conf.Set(YarnConfiguration.RmScheduler, typeof(CapacityScheduler).GetCanonicalName ()); MockRM rm = new MockRM(conf); rm.Start(); MockNM nm1 = rm.RegisterNode("h1:1234", 5120); RMApp app = rm.SubmitApp(2000); RMAppAttempt attempt = app.GetCurrentAppAttempt(); // Call getNewContainerId to increase container Id so that the AM container // Id doesn't equal to one. CapacityScheduler cs = (CapacityScheduler)rm.GetResourceScheduler(); cs.GetApplicationAttempt(attempt.GetAppAttemptId()).GetNewContainerId(); // kick the scheduling nm1.NodeHeartbeat(true); MockAM am = MockRM.LaunchAM(app, rm, nm1); // am container Id not equal to 1. NUnit.Framework.Assert.IsTrue(attempt.GetMasterContainer().GetId().GetContainerId () != 1); // NMSecretManager doesn't record the node on which the am is allocated. NUnit.Framework.Assert.IsFalse(rm.GetRMContext().GetNMTokenSecretManager().IsApplicationAttemptNMTokenPresent (attempt.GetAppAttemptId(), nm1.GetNodeId())); am.RegisterAppAttempt(); rm.WaitForState(app.GetApplicationId(), RMAppState.Running); int NumContainers = 1; IList <Container> containers = new AList <Container>(); // nmTokens keeps track of all the nmTokens issued in the allocate call. IList <NMToken> expectedNMTokens = new AList <NMToken>(); // am1 allocate 1 container on nm1. while (true) { AllocateResponse response = am.Allocate("127.0.0.1", 2000, NumContainers, new AList <ContainerId>()); nm1.NodeHeartbeat(true); Sharpen.Collections.AddAll(containers, response.GetAllocatedContainers()); Sharpen.Collections.AddAll(expectedNMTokens, response.GetNMTokens()); if (containers.Count == NumContainers) { break; } Sharpen.Thread.Sleep(200); System.Console.Out.WriteLine("Waiting for container to be allocated."); } NodeId nodeId = expectedNMTokens[0].GetNodeId(); // NMToken is sent for the allocated container. NUnit.Framework.Assert.AreEqual(nm1.GetNodeId(), nodeId); }