Пример #1
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAMRMClientAsyncShutDownWithWaitFor()
        {
            Configuration conf = new Configuration();

            TestAMRMClientAsync.TestCallbackHandler callbackHandler = new TestAMRMClientAsync.TestCallbackHandler
                                                                          (this);
            AMRMClient <AMRMClient.ContainerRequest> client = Org.Mockito.Mockito.Mock <AMRMClientImpl
                                                                                        >();

            Org.Mockito.Mockito.When(client.Allocate(Matchers.AnyFloat())).ThenThrow(new ApplicationAttemptNotFoundException
                                                                                         ("app not found, shut down"));
            AMRMClientAsync <AMRMClient.ContainerRequest> asyncClient = AMRMClientAsync.CreateAMRMClientAsync
                                                                            (client, 10, callbackHandler);

            asyncClient.Init(conf);
            asyncClient.Start();
            Supplier <bool> checker = new _Supplier_246(callbackHandler);

            asyncClient.RegisterApplicationMaster("localhost", 1234, null);
            asyncClient.WaitFor(checker);
            asyncClient.Stop();
            // stopping should have joined all threads and completed all callbacks
            NUnit.Framework.Assert.IsTrue(callbackHandler.callbackCount == 0);
            Org.Mockito.Mockito.Verify(client, Org.Mockito.Mockito.Times(1)).Allocate(Matchers.AnyFloat
                                                                                          ());
            asyncClient.Stop();
        }
Пример #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAMRMClientAsyncShutDown()
        {
            Configuration conf = new Configuration();

            TestAMRMClientAsync.TestCallbackHandler callbackHandler = new TestAMRMClientAsync.TestCallbackHandler
                                                                          (this);
            AMRMClient <AMRMClient.ContainerRequest> client = Org.Mockito.Mockito.Mock <AMRMClientImpl
                                                                                        >();

            CreateAllocateResponse(new AList <ContainerStatus>(), new AList <Container>(), null
                                   );
            Org.Mockito.Mockito.When(client.Allocate(Matchers.AnyFloat())).ThenThrow(new ApplicationAttemptNotFoundException
                                                                                         ("app not found, shut down"));
            AMRMClientAsync <AMRMClient.ContainerRequest> asyncClient = AMRMClientAsync.CreateAMRMClientAsync
                                                                            (client, 10, callbackHandler);

            asyncClient.Init(conf);
            asyncClient.Start();
            asyncClient.RegisterApplicationMaster("localhost", 1234, null);
            Sharpen.Thread.Sleep(50);
            Org.Mockito.Mockito.Verify(client, Org.Mockito.Mockito.Times(1)).Allocate(Matchers.AnyFloat
                                                                                          ());
            asyncClient.Stop();
        }
Пример #3
0
        /// <exception cref="System.Exception"/>
        private void RunHeartBeatThrowOutException(Exception ex)
        {
            Configuration conf = new Configuration();

            TestAMRMClientAsync.TestCallbackHandler callbackHandler = new TestAMRMClientAsync.TestCallbackHandler
                                                                          (this);
            AMRMClient <AMRMClient.ContainerRequest> client = Org.Mockito.Mockito.Mock <AMRMClientImpl
                                                                                        >();

            Org.Mockito.Mockito.When(client.Allocate(Matchers.AnyFloat())).ThenThrow(ex);
            AMRMClientAsync <AMRMClient.ContainerRequest> asyncClient = AMRMClientAsync.CreateAMRMClientAsync
                                                                            (client, 20, callbackHandler);

            asyncClient.Init(conf);
            asyncClient.Start();
            lock (callbackHandler.notifier)
            {
                asyncClient.RegisterApplicationMaster("localhost", 1234, null);
                while (callbackHandler.savedException == null)
                {
                    try
                    {
                        Sharpen.Runtime.Wait(callbackHandler.notifier);
                    }
                    catch (Exception e)
                    {
                        Sharpen.Runtime.PrintStackTrace(e);
                    }
                }
            }
            NUnit.Framework.Assert.IsTrue(callbackHandler.savedException.Message.Contains(ex.
                                                                                          Message));
            asyncClient.Stop();
            // stopping should have joined all threads and completed all callbacks
            NUnit.Framework.Assert.IsTrue(callbackHandler.callbackCount == 0);
        }
Пример #4
0
 public _Supplier_246(TestAMRMClientAsync.TestCallbackHandler callbackHandler)
 {
     this.callbackHandler = callbackHandler;
 }
Пример #5
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAMRMClientAsync()
        {
            Configuration           conf           = new Configuration();
            AtomicBoolean           heartbeatBlock = new AtomicBoolean(true);
            IList <ContainerStatus> completed1     = Arrays.AsList(ContainerStatus.NewInstance(NewContainerId
                                                                                                   (0, 0, 0, 0), ContainerState.Complete, string.Empty, 0));
            IList <Container> allocated1 = Arrays.AsList(Container.NewInstance(null, null, null
                                                                               , null, null, null));
            AllocateResponse response1 = CreateAllocateResponse(new AList <ContainerStatus>(),
                                                                allocated1, null);
            AllocateResponse response2 = CreateAllocateResponse(completed1, new AList <Container
                                                                                       >(), null);
            AllocateResponse emptyResponse = CreateAllocateResponse(new AList <ContainerStatus
                                                                               >(), new AList <Container>(), null);

            TestAMRMClientAsync.TestCallbackHandler callbackHandler = new TestAMRMClientAsync.TestCallbackHandler
                                                                          (this);
            AMRMClient <AMRMClient.ContainerRequest> client = Org.Mockito.Mockito.Mock <AMRMClientImpl
                                                                                        >();
            AtomicInteger secondHeartbeatSync = new AtomicInteger(0);

            Org.Mockito.Mockito.When(client.Allocate(Matchers.AnyFloat())).ThenReturn(response1
                                                                                      ).ThenAnswer(new _Answer_89(secondHeartbeatSync, heartbeatBlock, response2)).ThenReturn
                (emptyResponse);
            Org.Mockito.Mockito.When(client.RegisterApplicationMaster(Matchers.AnyString(), Matchers.AnyInt
                                                                          (), Matchers.AnyString())).ThenReturn(null);
            Org.Mockito.Mockito.When(client.GetAvailableResources()).ThenAnswer(new _Answer_105
                                                                                    (client));
            // take client lock to simulate behavior of real impl
            AMRMClientAsync <AMRMClient.ContainerRequest> asyncClient = AMRMClientAsync.CreateAMRMClientAsync
                                                                            (client, 20, callbackHandler);

            asyncClient.Init(conf);
            asyncClient.Start();
            asyncClient.RegisterApplicationMaster("localhost", 1234, null);
            // while the CallbackHandler will still only be processing the first response,
            // heartbeater thread should still be sending heartbeats.
            // To test this, wait for the second heartbeat to be received.
            while (secondHeartbeatSync.Get() < 1)
            {
                Sharpen.Thread.Sleep(10);
            }
            // heartbeat will be blocked. make sure we can call client methods at this
            // time. Checks that heartbeat is not holding onto client lock
            System.Diagnostics.Debug.Assert((secondHeartbeatSync.Get() < 2));
            asyncClient.GetAvailableResources();
            // method returned. now unblock heartbeat
            System.Diagnostics.Debug.Assert((secondHeartbeatSync.Get() < 2));
            lock (heartbeatBlock)
            {
                heartbeatBlock.Set(false);
                Sharpen.Runtime.NotifyAll(heartbeatBlock);
            }
            // allocated containers should come before completed containers
            NUnit.Framework.Assert.AreEqual(null, callbackHandler.TakeCompletedContainers());
            // wait for the allocated containers from the first heartbeat's response
            while (callbackHandler.TakeAllocatedContainers() == null)
            {
                NUnit.Framework.Assert.AreEqual(null, callbackHandler.TakeCompletedContainers());
                Sharpen.Thread.Sleep(10);
            }
            // wait for the completed containers from the second heartbeat's response
            while (callbackHandler.TakeCompletedContainers() == null)
            {
                Sharpen.Thread.Sleep(10);
            }
            asyncClient.Stop();
            NUnit.Framework.Assert.AreEqual(null, callbackHandler.TakeAllocatedContainers());
            NUnit.Framework.Assert.AreEqual(null, callbackHandler.TakeCompletedContainers());
        }