public virtual RMContext MockRMContext(int n, long time) { IList <RMApp> apps = NewRMApps(n, time, RMAppState.Finished); ConcurrentMap <ApplicationId, RMApp> map = Maps.NewConcurrentMap(); foreach (RMApp app in apps) { map[app.GetApplicationId()] = app; } Dispatcher rmDispatcher = new AsyncDispatcher(); ContainerAllocationExpirer containerAllocationExpirer = new ContainerAllocationExpirer (rmDispatcher); AMLivelinessMonitor amLivelinessMonitor = new AMLivelinessMonitor(rmDispatcher); AMLivelinessMonitor amFinishingMonitor = new AMLivelinessMonitor(rmDispatcher); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); RMContext context = new _RMContextImpl_121(map, rmDispatcher, containerAllocationExpirer , amLivelinessMonitor, amFinishingMonitor, null, null, null, null, null); ((RMContextImpl)context).SetStateStore(Org.Mockito.Mockito.Mock <RMStateStore>()); metricsPublisher = Org.Mockito.Mockito.Mock <SystemMetricsPublisher>(); context.SetSystemMetricsPublisher(metricsPublisher); context.SetRMApplicationHistoryWriter(writer); return(context); }
/// <summary> /// Get a mock /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.RMContext"/> /// for use in test cases. /// </summary> /// <returns> /// a mock /// <see cref="Org.Apache.Hadoop.Yarn.Server.Resourcemanager.RMContext"/> /// for use in test cases /// </returns> public static RMContext GetMockRMContext() { // Null dispatcher Dispatcher nullDispatcher = new _Dispatcher_73(); // No op ContainerAllocationExpirer cae = new ContainerAllocationExpirer(nullDispatcher); Configuration conf = new Configuration(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); RMContextImpl rmContext = new RMContextImpl(nullDispatcher, cae, null, null, null , new AMRMTokenSecretManager(conf, null), new RMContainerTokenSecretManager(conf ), new NMTokenSecretManagerInRM(conf), new ClientToAMTokenSecretManagerInRM()); RMNodeLabelsManager nlm = Org.Mockito.Mockito.Mock <RMNodeLabelsManager>(); Org.Mockito.Mockito.When(nlm.GetQueueResource(Matchers.Any <string>(), Matchers.Any <Set>(), Matchers.Any <Resource>())).ThenAnswer(new _Answer_105()); Org.Mockito.Mockito.When(nlm.GetResourceByLabel(Matchers.Any <string>(), Matchers.Any <Resource>())).ThenAnswer(new _Answer_114()); rmContext.SetNodeLabelManager(nlm); rmContext.SetSystemMetricsPublisher(Org.Mockito.Mockito.Mock <SystemMetricsPublisher >()); rmContext.SetRMApplicationHistoryWriter(Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >()); return(rmContext); }
/// <exception cref="System.Exception"/> public virtual void TestAppAttemptMetrics() { AsyncDispatcher dispatcher = new InlineDispatcher(); FifoScheduler scheduler = new FifoScheduler(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); RMContext rmContext = new RMContextImpl(dispatcher, null, null, null, null, null, null, null, null, scheduler); ((RMContextImpl)rmContext).SetSystemMetricsPublisher(Org.Mockito.Mockito.Mock <SystemMetricsPublisher >()); Configuration conf = new Configuration(); scheduler.SetRMContext(rmContext); scheduler.Init(conf); scheduler.Start(); scheduler.Reinitialize(conf, rmContext); QueueMetrics metrics = scheduler.GetRootQueueMetrics(); int beforeAppsSubmitted = metrics.GetAppsSubmitted(); ApplicationId appId = BuilderUtils.NewApplicationId(200, 1); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 1 ); SchedulerEvent appEvent = new AppAddedSchedulerEvent(appId, "queue", "user"); scheduler.Handle(appEvent); SchedulerEvent attemptEvent = new AppAttemptAddedSchedulerEvent(appAttemptId, false ); scheduler.Handle(attemptEvent); appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 2); SchedulerEvent attemptEvent2 = new AppAttemptAddedSchedulerEvent(appAttemptId, false ); scheduler.Handle(attemptEvent2); int afterAppsSubmitted = metrics.GetAppsSubmitted(); NUnit.Framework.Assert.AreEqual(1, afterAppsSubmitted - beforeAppsSubmitted); scheduler.Stop(); }
public virtual void SetRMApplicationHistoryWriter(RMApplicationHistoryWriter rmApplicationHistoryWriter ) { this.rmApplicationHistoryWriter = rmApplicationHistoryWriter; }
public virtual void TestReleaseWhileRunning() { DrainDispatcher drainDispatcher = new DrainDispatcher(); EventHandler <RMAppAttemptEvent> appAttemptEventHandler = Org.Mockito.Mockito.Mock <EventHandler>(); EventHandler generic = Org.Mockito.Mockito.Mock <EventHandler>(); drainDispatcher.Register(typeof(RMAppAttemptEventType), appAttemptEventHandler); drainDispatcher.Register(typeof(RMNodeEventType), generic); drainDispatcher.Init(new YarnConfiguration()); drainDispatcher.Start(); NodeId nodeId = BuilderUtils.NewNodeId("host", 3425); ApplicationId appId = BuilderUtils.NewApplicationId(1, 1); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 1 ); ContainerId containerId = BuilderUtils.NewContainerId(appAttemptId, 1); ContainerAllocationExpirer expirer = Org.Mockito.Mockito.Mock <ContainerAllocationExpirer >(); Resource resource = BuilderUtils.NewResource(512, 1); Priority priority = BuilderUtils.NewPriority(5); Container container = BuilderUtils.NewContainer(containerId, nodeId, "host:3465", resource, priority, null); ConcurrentMap <ApplicationId, RMApp> rmApps = Org.Mockito.Mockito.Spy(new ConcurrentHashMap <ApplicationId, RMApp>()); RMApp rmApp = Org.Mockito.Mockito.Mock <RMApp>(); Org.Mockito.Mockito.When(rmApp.GetRMAppAttempt((ApplicationAttemptId)Matchers.Any ())).ThenReturn(null); Org.Mockito.Mockito.DoReturn(rmApp).When(rmApps)[(ApplicationId)Matchers.Any()]; RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); SystemMetricsPublisher publisher = Org.Mockito.Mockito.Mock <SystemMetricsPublisher >(); RMContext rmContext = Org.Mockito.Mockito.Mock <RMContext>(); Org.Mockito.Mockito.When(rmContext.GetDispatcher()).ThenReturn(drainDispatcher); Org.Mockito.Mockito.When(rmContext.GetContainerAllocationExpirer()).ThenReturn(expirer ); Org.Mockito.Mockito.When(rmContext.GetRMApplicationHistoryWriter()).ThenReturn(writer ); Org.Mockito.Mockito.When(rmContext.GetRMApps()).ThenReturn(rmApps); Org.Mockito.Mockito.When(rmContext.GetSystemMetricsPublisher()).ThenReturn(publisher ); Org.Mockito.Mockito.When(rmContext.GetYarnConfiguration()).ThenReturn(new YarnConfiguration ()); RMContainer rmContainer = new RMContainerImpl(container, appAttemptId, nodeId, "user" , rmContext); NUnit.Framework.Assert.AreEqual(RMContainerState.New, rmContainer.GetState()); NUnit.Framework.Assert.AreEqual(resource, rmContainer.GetAllocatedResource()); NUnit.Framework.Assert.AreEqual(nodeId, rmContainer.GetAllocatedNode()); NUnit.Framework.Assert.AreEqual(priority, rmContainer.GetAllocatedPriority()); Org.Mockito.Mockito.Verify(writer).ContainerStarted(Matchers.Any <RMContainer>()); Org.Mockito.Mockito.Verify(publisher).ContainerCreated(Matchers.Any <RMContainer>( ), Matchers.AnyLong()); rmContainer.Handle(new RMContainerEvent(containerId, RMContainerEventType.Start)); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Allocated, rmContainer.GetState( )); rmContainer.Handle(new RMContainerEvent(containerId, RMContainerEventType.Acquired )); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Acquired, rmContainer.GetState() ); rmContainer.Handle(new RMContainerEvent(containerId, RMContainerEventType.Launched )); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Running, rmContainer.GetState()); NUnit.Framework.Assert.AreEqual("http://host:3465/node/containerlogs/container_1_0001_01_000001/user" , rmContainer.GetLogURL()); // In RUNNING state. Verify RELEASED and associated actions. Org.Mockito.Mockito.Reset(appAttemptEventHandler); ContainerStatus containerStatus = SchedulerUtils.CreateAbnormalContainerStatus(containerId , SchedulerUtils.ReleasedContainer); rmContainer.Handle(new RMContainerFinishedEvent(containerId, containerStatus, RMContainerEventType .Released)); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Released, rmContainer.GetState() ); NUnit.Framework.Assert.AreEqual(SchedulerUtils.ReleasedContainer, rmContainer.GetDiagnosticsInfo ()); NUnit.Framework.Assert.AreEqual(ContainerExitStatus.Aborted, rmContainer.GetContainerExitStatus ()); NUnit.Framework.Assert.AreEqual(ContainerState.Complete, rmContainer.GetContainerState ()); Org.Mockito.Mockito.Verify(writer).ContainerFinished(Matchers.Any <RMContainer>()); Org.Mockito.Mockito.Verify(publisher).ContainerFinished(Matchers.Any <RMContainer> (), Matchers.AnyLong()); ArgumentCaptor <RMAppAttemptContainerFinishedEvent> captor = ArgumentCaptor.ForClass <RMAppAttemptContainerFinishedEvent>(); Org.Mockito.Mockito.Verify(appAttemptEventHandler).Handle(captor.Capture()); RMAppAttemptContainerFinishedEvent cfEvent = captor.GetValue(); NUnit.Framework.Assert.AreEqual(appAttemptId, cfEvent.GetApplicationAttemptId()); NUnit.Framework.Assert.AreEqual(containerStatus, cfEvent.GetContainerStatus()); NUnit.Framework.Assert.AreEqual(RMAppAttemptEventType.ContainerFinished, cfEvent. GetType()); // In RELEASED state. A FINIHSED event may come in. rmContainer.Handle(new RMContainerFinishedEvent(containerId, SchedulerUtils.CreateAbnormalContainerStatus (containerId, "FinishedContainer"), RMContainerEventType.Finished)); NUnit.Framework.Assert.AreEqual(RMContainerState.Released, rmContainer.GetState() ); }
public virtual void TestExpireWhileRunning() { DrainDispatcher drainDispatcher = new DrainDispatcher(); EventHandler <RMAppAttemptEvent> appAttemptEventHandler = Org.Mockito.Mockito.Mock <EventHandler>(); EventHandler generic = Org.Mockito.Mockito.Mock <EventHandler>(); drainDispatcher.Register(typeof(RMAppAttemptEventType), appAttemptEventHandler); drainDispatcher.Register(typeof(RMNodeEventType), generic); drainDispatcher.Init(new YarnConfiguration()); drainDispatcher.Start(); NodeId nodeId = BuilderUtils.NewNodeId("host", 3425); ApplicationId appId = BuilderUtils.NewApplicationId(1, 1); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(appId, 1 ); ContainerId containerId = BuilderUtils.NewContainerId(appAttemptId, 1); ContainerAllocationExpirer expirer = Org.Mockito.Mockito.Mock <ContainerAllocationExpirer >(); Resource resource = BuilderUtils.NewResource(512, 1); Priority priority = BuilderUtils.NewPriority(5); Container container = BuilderUtils.NewContainer(containerId, nodeId, "host:3465", resource, priority, null); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); SystemMetricsPublisher publisher = Org.Mockito.Mockito.Mock <SystemMetricsPublisher >(); RMContext rmContext = Org.Mockito.Mockito.Mock <RMContext>(); Org.Mockito.Mockito.When(rmContext.GetDispatcher()).ThenReturn(drainDispatcher); Org.Mockito.Mockito.When(rmContext.GetContainerAllocationExpirer()).ThenReturn(expirer ); Org.Mockito.Mockito.When(rmContext.GetRMApplicationHistoryWriter()).ThenReturn(writer ); Org.Mockito.Mockito.When(rmContext.GetSystemMetricsPublisher()).ThenReturn(publisher ); Org.Mockito.Mockito.When(rmContext.GetYarnConfiguration()).ThenReturn(new YarnConfiguration ()); RMContainer rmContainer = new RMContainerImpl(container, appAttemptId, nodeId, "user" , rmContext); NUnit.Framework.Assert.AreEqual(RMContainerState.New, rmContainer.GetState()); NUnit.Framework.Assert.AreEqual(resource, rmContainer.GetAllocatedResource()); NUnit.Framework.Assert.AreEqual(nodeId, rmContainer.GetAllocatedNode()); NUnit.Framework.Assert.AreEqual(priority, rmContainer.GetAllocatedPriority()); Org.Mockito.Mockito.Verify(writer).ContainerStarted(Matchers.Any <RMContainer>()); Org.Mockito.Mockito.Verify(publisher).ContainerCreated(Matchers.Any <RMContainer>( ), Matchers.AnyLong()); rmContainer.Handle(new RMContainerEvent(containerId, RMContainerEventType.Start)); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Allocated, rmContainer.GetState( )); rmContainer.Handle(new RMContainerEvent(containerId, RMContainerEventType.Acquired )); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Acquired, rmContainer.GetState() ); rmContainer.Handle(new RMContainerEvent(containerId, RMContainerEventType.Launched )); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Running, rmContainer.GetState()); NUnit.Framework.Assert.AreEqual("http://host:3465/node/containerlogs/container_1_0001_01_000001/user" , rmContainer.GetLogURL()); // In RUNNING state. Verify EXPIRE and associated actions. Org.Mockito.Mockito.Reset(appAttemptEventHandler); ContainerStatus containerStatus = SchedulerUtils.CreateAbnormalContainerStatus(containerId , SchedulerUtils.ExpiredContainer); rmContainer.Handle(new RMContainerFinishedEvent(containerId, containerStatus, RMContainerEventType .Expire)); drainDispatcher.Await(); NUnit.Framework.Assert.AreEqual(RMContainerState.Running, rmContainer.GetState()); Org.Mockito.Mockito.Verify(writer, Org.Mockito.Mockito.Never()).ContainerFinished (Matchers.Any <RMContainer>()); Org.Mockito.Mockito.Verify(publisher, Org.Mockito.Mockito.Never()).ContainerFinished (Matchers.Any <RMContainer>(), Matchers.AnyLong()); }
/// <exception cref="System.Exception"/> public virtual void TestUpdateResourceOnNode() { AsyncDispatcher dispatcher = new InlineDispatcher(); Configuration conf = new Configuration(); RMContainerTokenSecretManager containerTokenSecretManager = new RMContainerTokenSecretManager (conf); containerTokenSecretManager.RollMasterKey(); NMTokenSecretManagerInRM nmTokenSecretManager = new NMTokenSecretManagerInRM(conf ); nmTokenSecretManager.RollMasterKey(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); FifoScheduler scheduler = new _FifoScheduler_275(this); RMContext rmContext = new RMContextImpl(dispatcher, null, null, null, null, null, containerTokenSecretManager, nmTokenSecretManager, null, scheduler); rmContext.SetSystemMetricsPublisher(Org.Mockito.Mockito.Mock <SystemMetricsPublisher >()); rmContext.SetRMApplicationHistoryWriter(Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >()); ((RMContextImpl)rmContext).SetYarnConfiguration(new YarnConfiguration()); scheduler.SetRMContext(rmContext); scheduler.Init(conf); scheduler.Start(); scheduler.Reinitialize(new Configuration(), rmContext); RMNode node0 = MockNodes.NewNodeInfo(1, Resources.CreateResource(2048, 4), 1, "127.0.0.1" ); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0); scheduler.Handle(nodeEvent1); MethodInfo method = Sharpen.Runtime.GetDeclaredMethod(scheduler.GetType(), "getNodes" ); IDictionary <NodeId, FiCaSchedulerNode> schedulerNodes = (IDictionary <NodeId, FiCaSchedulerNode >)method.Invoke(scheduler); NUnit.Framework.Assert.AreEqual(schedulerNodes.Values.Count, 1); Org.Apache.Hadoop.Yarn.Api.Records.Resource newResource = Resources.CreateResource (1024, 4); NodeResourceUpdateSchedulerEvent node0ResourceUpdate = new NodeResourceUpdateSchedulerEvent (node0, ResourceOption.NewInstance(newResource, RMNode.OverCommitTimeoutMillisDefault )); scheduler.Handle(node0ResourceUpdate); // SchedulerNode's total resource and available resource are changed. NUnit.Framework.Assert.AreEqual(schedulerNodes[node0.GetNodeID()].GetTotalResource ().GetMemory(), 1024); NUnit.Framework.Assert.AreEqual(schedulerNodes[node0.GetNodeID()].GetAvailableResource ().GetMemory(), 1024); QueueInfo queueInfo = scheduler.GetQueueInfo(null, false, false); NUnit.Framework.Assert.AreEqual(0.0f, queueInfo.GetCurrentCapacity(), 0.0f); int _appId = 1; int _appAttemptId = 1; ApplicationAttemptId appAttemptId = CreateAppAttemptId(_appId, _appAttemptId); CreateMockRMApp(appAttemptId, rmContext); AppAddedSchedulerEvent appEvent = new AppAddedSchedulerEvent(appAttemptId.GetApplicationId (), "queue1", "user1"); scheduler.Handle(appEvent); AppAttemptAddedSchedulerEvent attemptEvent = new AppAttemptAddedSchedulerEvent(appAttemptId , false); scheduler.Handle(attemptEvent); int memory = 1024; int priority = 1; IList <ResourceRequest> ask = new AList <ResourceRequest>(); ResourceRequest nodeLocal = CreateResourceRequest(memory, node0.GetHostName(), priority , 1); ResourceRequest rackLocal = CreateResourceRequest(memory, node0.GetRackName(), priority , 1); ResourceRequest any = CreateResourceRequest(memory, ResourceRequest.Any, priority , 1); ask.AddItem(nodeLocal); ask.AddItem(rackLocal); ask.AddItem(any); scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null); // Before the node update event, there are one local request NUnit.Framework.Assert.AreEqual(1, nodeLocal.GetNumContainers()); NodeUpdateSchedulerEvent node0Update = new NodeUpdateSchedulerEvent(node0); // Now schedule. scheduler.Handle(node0Update); // After the node update event, check no local request NUnit.Framework.Assert.AreEqual(0, nodeLocal.GetNumContainers()); // Also check that one container was scheduled SchedulerAppReport info = scheduler.GetSchedulerAppInfo(appAttemptId); NUnit.Framework.Assert.AreEqual(1, info.GetLiveContainers().Count); // And check the default Queue now is full. queueInfo = scheduler.GetQueueInfo(null, false, false); NUnit.Framework.Assert.AreEqual(1.0f, queueInfo.GetCurrentCapacity(), 0.0f); }
/// <exception cref="System.Exception"/> public virtual void TestNodeLocalAssignment() { AsyncDispatcher dispatcher = new InlineDispatcher(); Configuration conf = new Configuration(); RMContainerTokenSecretManager containerTokenSecretManager = new RMContainerTokenSecretManager (conf); containerTokenSecretManager.RollMasterKey(); NMTokenSecretManagerInRM nmTokenSecretManager = new NMTokenSecretManagerInRM(conf ); nmTokenSecretManager.RollMasterKey(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); FifoScheduler scheduler = new FifoScheduler(); RMContext rmContext = new RMContextImpl(dispatcher, null, null, null, null, null, containerTokenSecretManager, nmTokenSecretManager, null, scheduler); rmContext.SetSystemMetricsPublisher(Org.Mockito.Mockito.Mock <SystemMetricsPublisher >()); rmContext.SetRMApplicationHistoryWriter(Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >()); ((RMContextImpl)rmContext).SetYarnConfiguration(new YarnConfiguration()); scheduler.SetRMContext(rmContext); scheduler.Init(conf); scheduler.Start(); scheduler.Reinitialize(new Configuration(), rmContext); RMNode node0 = MockNodes.NewNodeInfo(1, Resources.CreateResource(1024 * 64), 1, "127.0.0.1" ); NodeAddedSchedulerEvent nodeEvent1 = new NodeAddedSchedulerEvent(node0); scheduler.Handle(nodeEvent1); int _appId = 1; int _appAttemptId = 1; ApplicationAttemptId appAttemptId = CreateAppAttemptId(_appId, _appAttemptId); CreateMockRMApp(appAttemptId, rmContext); AppAddedSchedulerEvent appEvent = new AppAddedSchedulerEvent(appAttemptId.GetApplicationId (), "queue1", "user1"); scheduler.Handle(appEvent); AppAttemptAddedSchedulerEvent attemptEvent = new AppAttemptAddedSchedulerEvent(appAttemptId , false); scheduler.Handle(attemptEvent); int memory = 64; int nConts = 3; int priority = 20; IList <ResourceRequest> ask = new AList <ResourceRequest>(); ResourceRequest nodeLocal = CreateResourceRequest(memory, node0.GetHostName(), priority , nConts); ResourceRequest rackLocal = CreateResourceRequest(memory, node0.GetRackName(), priority , nConts); ResourceRequest any = CreateResourceRequest(memory, ResourceRequest.Any, priority , nConts); ask.AddItem(nodeLocal); ask.AddItem(rackLocal); ask.AddItem(any); scheduler.Allocate(appAttemptId, ask, new AList <ContainerId>(), null, null); NodeUpdateSchedulerEvent node0Update = new NodeUpdateSchedulerEvent(node0); // Before the node update event, there are 3 local requests outstanding NUnit.Framework.Assert.AreEqual(3, nodeLocal.GetNumContainers()); scheduler.Handle(node0Update); // After the node update event, check that there are no more local requests // outstanding NUnit.Framework.Assert.AreEqual(0, nodeLocal.GetNumContainers()); //Also check that the containers were scheduled SchedulerAppReport info = scheduler.GetSchedulerAppInfo(appAttemptId); NUnit.Framework.Assert.AreEqual(3, info.GetLiveContainers().Count); scheduler.Stop(); }
public virtual void TestSortedQueues() { // Setup queue configs SetupSortedQueues(csConf); IDictionary <string, CSQueue> queues = new Dictionary <string, CSQueue>(); CSQueue root = CapacityScheduler.ParseQueue(csContext, csConf, null, CapacitySchedulerConfiguration .Root, queues, queues, TestUtils.spyHook); // Setup some nodes int memoryPerNode = 10; int coresPerNode = 16; int numNodes = 1; FiCaSchedulerNode node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, memoryPerNode * Gb); Org.Mockito.Mockito.DoNothing().When(node_0).ReleaseContainer(Matchers.Any <Container >()); Org.Apache.Hadoop.Yarn.Api.Records.Resource clusterResource = Resources.CreateResource (numNodes * (memoryPerNode * Gb), numNodes * coresPerNode); Org.Mockito.Mockito.When(csContext.GetNumClusterNodes()).ThenReturn(numNodes); // Start testing CSQueue a = queues[A]; CSQueue b = queues[B]; CSQueue c = queues[C]; CSQueue d = queues[D]; string user_0 = "user_0"; // Stub an App and its containerCompleted FiCaSchedulerApp app_0 = GetMockApplication(0, user_0); Org.Mockito.Mockito.DoReturn(true).When(app_0).ContainerCompleted(Matchers.Any <RMContainer >(), Matchers.Any <ContainerStatus>(), Matchers.Any <RMContainerEventType>()); Priority priority = TestUtils.CreateMockPriority(1); ContainerAllocationExpirer expirer = Org.Mockito.Mockito.Mock <ContainerAllocationExpirer >(); DrainDispatcher drainDispatcher = new DrainDispatcher(); RMApplicationHistoryWriter writer = Org.Mockito.Mockito.Mock <RMApplicationHistoryWriter >(); SystemMetricsPublisher publisher = Org.Mockito.Mockito.Mock <SystemMetricsPublisher >(); RMContext rmContext = Org.Mockito.Mockito.Mock <RMContext>(); Org.Mockito.Mockito.When(rmContext.GetContainerAllocationExpirer()).ThenReturn(expirer ); Org.Mockito.Mockito.When(rmContext.GetDispatcher()).ThenReturn(drainDispatcher); Org.Mockito.Mockito.When(rmContext.GetRMApplicationHistoryWriter()).ThenReturn(writer ); Org.Mockito.Mockito.When(rmContext.GetSystemMetricsPublisher()).ThenReturn(publisher ); Org.Mockito.Mockito.When(rmContext.GetYarnConfiguration()).ThenReturn(new YarnConfiguration ()); ApplicationAttemptId appAttemptId = BuilderUtils.NewApplicationAttemptId(app_0.GetApplicationId (), 1); ContainerId containerId = BuilderUtils.NewContainerId(appAttemptId, 1); Container container = TestUtils.GetMockContainer(containerId, node_0.GetNodeID(), Resources.CreateResource(1 * Gb), priority); RMContainer rmContainer = new RMContainerImpl(container, appAttemptId, node_0.GetNodeID (), "user", rmContext); // Assign {1,2,3,4} 1GB containers respectively to queues StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); for (int i = 0; i < 2; i++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } for (int i_1 = 0; i_1 < 3; i_1++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 1 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } for (int i_2 = 0; i_2 < 4; i_2++) { StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 4 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 3 x 1GB containers from D for (int i_3 = 0; i_3 < 3; i_3++) { d.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); } VerifyQueueMetrics(a, 1 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 1 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 2 x 1GB Containers to A for (int i_4 = 0; i_4 < 2; i_4++) { StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); } VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 1GB Container from A a.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 2 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 1GB container to B StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 3 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); //Release 1GB container resources from B b.CompletedContainer(clusterResource, app_0, node_0, rmContainer, null, RMContainerEventType .Kill, null, true); VerifyQueueMetrics(a, 2 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); //reset manually resources on node node_0 = TestUtils.GetMockNode("host_0", DefaultRack, 0, (memoryPerNode - 2 - 2 - 3 - 1) * Gb); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Assign 1GB container to A StubQueueAllocation(a, clusterResource, node_0, 1 * Gb); StubQueueAllocation(b, clusterResource, node_0, 0 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 0 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 1 * Gb, clusterResource); Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); // Now do the real test, where B and D request a 1GB container // D should should get the next container if the order is correct StubQueueAllocation(a, clusterResource, node_0, 0 * Gb); StubQueueAllocation(b, clusterResource, node_0, 1 * Gb); StubQueueAllocation(c, clusterResource, node_0, 0 * Gb); StubQueueAllocation(d, clusterResource, node_0, 1 * Gb); root.AssignContainers(clusterResource, node_0, new ResourceLimits(clusterResource )); InOrder allocationOrder = Org.Mockito.Mockito.InOrder(d, b); allocationOrder.Verify(d).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), Matchers.Any <ResourceLimits>()); allocationOrder.Verify(b).AssignContainers(Matchers.Eq(clusterResource), Matchers.Any <FiCaSchedulerNode>(), Matchers.Any <ResourceLimits>()); VerifyQueueMetrics(a, 3 * Gb, clusterResource); VerifyQueueMetrics(b, 2 * Gb, clusterResource); VerifyQueueMetrics(c, 3 * Gb, clusterResource); VerifyQueueMetrics(d, 2 * Gb, clusterResource); //D got the container Log.Info("status child-queues: " + ((ParentQueue)root).GetChildQueuesToPrint()); }