/// <exception cref="System.Exception"/> public virtual void TestOutOfOrder() { CyclicBarrier barrierA = new CyclicBarrier(2); CyclicBarrier barrierB = new CyclicBarrier(2); CyclicBarrier barrierC = new CyclicBarrier(2); asyncClient = new TestNMClientAsync.MockNMClientAsync2(this, barrierA, barrierB, barrierC); asyncClient.Init(new Configuration()); asyncClient.Start(); Container container = MockContainer(1); ContainerLaunchContext clc = recordFactory.NewRecordInstance <ContainerLaunchContext >(); // start container from another thread Sharpen.Thread t = new _Thread_434(this, container, clc); t.Start(); barrierA.Await(); asyncClient.StopContainerAsync(container.GetId(), container.GetNodeId()); barrierC.Await(); NUnit.Framework.Assert.IsFalse("Starting and stopping should be out of order", (( TestNMClientAsync.TestCallbackHandler2)asyncClient.GetCallbackHandler()).exceptionOccurred .Get()); }
/// <exception cref="System.Exception"/> public virtual void TestNMClientAsync() { Configuration conf = new Configuration(); conf.SetInt(YarnConfiguration.NmClientAsyncThreadPoolMaxSize, 10); // Threads to run are more than the max size of the thread pool int expectedSuccess = 40; int expectedFailure = 40; asyncClient = new TestNMClientAsync.MockNMClientAsync1(this, expectedSuccess, expectedFailure ); asyncClient.Init(conf); NUnit.Framework.Assert.AreEqual("The max thread pool size is not correctly set", 10, asyncClient.maxThreadPoolSize); asyncClient.Start(); for (int i = 0; i < expectedSuccess + expectedFailure; ++i) { if (i == expectedSuccess) { while (!((TestNMClientAsync.TestCallbackHandler1)asyncClient.GetCallbackHandler() ).IsAllSuccessCallsExecuted()) { Sharpen.Thread.Sleep(10); } asyncClient.SetClient(MockNMClient(1)); } Container container = MockContainer(i); ContainerLaunchContext clc = recordFactory.NewRecordInstance <ContainerLaunchContext >(); asyncClient.StartContainerAsync(container, clc); } while (!((TestNMClientAsync.TestCallbackHandler1)asyncClient.GetCallbackHandler() ).IsStartAndQueryFailureCallsExecuted()) { Sharpen.Thread.Sleep(10); } asyncClient.SetClient(MockNMClient(2)); ((TestNMClientAsync.TestCallbackHandler1)asyncClient.GetCallbackHandler()).path = false; for (int i_1 = 0; i_1 < expectedFailure; ++i_1) { Container container = MockContainer(expectedSuccess + expectedFailure + i_1); ContainerLaunchContext clc = recordFactory.NewRecordInstance <ContainerLaunchContext >(); asyncClient.StartContainerAsync(container, clc); } while (!((TestNMClientAsync.TestCallbackHandler1)asyncClient.GetCallbackHandler() ).IsStopFailureCallsExecuted()) { Sharpen.Thread.Sleep(10); } foreach (string errorMsg in ((TestNMClientAsync.TestCallbackHandler1)asyncClient. GetCallbackHandler()).errorMsgs) { System.Console.Out.WriteLine(errorMsg); } NUnit.Framework.Assert.AreEqual("Error occurs in CallbackHandler", 0, ((TestNMClientAsync.TestCallbackHandler1 )asyncClient.GetCallbackHandler()).errorMsgs.Count); foreach (string errorMsg_1 in ((TestNMClientAsync.MockNMClientAsync1)asyncClient) .errorMsgs) { System.Console.Out.WriteLine(errorMsg_1); } NUnit.Framework.Assert.AreEqual("Error occurs in ContainerEventProcessor", 0, ((TestNMClientAsync.MockNMClientAsync1 )asyncClient).errorMsgs.Count); // When the callback functions are all executed, the event processor threads // may still not terminate and the containers may still not removed. while (asyncClient.containers.Count > 0) { Sharpen.Thread.Sleep(10); } asyncClient.Stop(); NUnit.Framework.Assert.IsFalse("The thread of Container Management Event Dispatcher is still alive" , asyncClient.eventDispatcherThread.IsAlive()); NUnit.Framework.Assert.IsTrue("The thread pool is not shut down", asyncClient.threadPool .IsShutdown()); }