示例#1
0
        public virtual void TestPutMetrics2()
        {
            GraphiteSink       sink = new GraphiteSink();
            IList <MetricsTag> tags = new AList <MetricsTag>();

            tags.AddItem(new MetricsTag(MsInfo.Context, "all"));
            tags.AddItem(new MetricsTag(MsInfo.Hostname, null));
            ICollection <AbstractMetric> metrics = new HashSet <AbstractMetric>();

            metrics.AddItem(MakeMetric("foo1", 1));
            metrics.AddItem(MakeMetric("foo2", 2));
            MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long)10000, tags, metrics
                                                         );
            ArgumentCaptor <string> argument = ArgumentCaptor.ForClass <string>();

            GraphiteSink.Graphite mockGraphite = MakeGraphite();
            Whitebox.SetInternalState(sink, "graphite", mockGraphite);
            sink.PutMetrics(record);
            try
            {
                Org.Mockito.Mockito.Verify(mockGraphite).Write(argument.Capture());
            }
            catch (IOException e)
            {
                Runtime.PrintStackTrace(e);
            }
            string result = argument.GetValue();

            Assert.Equal(true, result.Equals("null.all.Context.Context=all.foo1 1 10\n"
                                             + "null.all.Context.Context=all.foo2 2 10\n") || result.Equals("null.all.Context.Context=all.foo2 2 10\n"
                                                                                                            + "null.all.Context.Context=all.foo1 1 10\n"));
        }
示例#2
0
        public virtual void TestStorageReportHasStorageTypeAndState()
        {
            // Make sure we are not testing with the default type, that would not
            // be a very good test.
            NUnit.Framework.Assert.AreNotSame(storageType, StorageType.Default);
            NameNode nn = cluster.GetNameNode();
            DataNode dn = cluster.GetDataNodes()[0];
            // Insert a spy object for the NN RPC.
            DatanodeProtocolClientSideTranslatorPB nnSpy = DataNodeTestUtils.SpyOnBposToNN(dn
                                                                                           , nn);

            // Trigger a heartbeat so there is an interaction with the spy
            // object.
            DataNodeTestUtils.TriggerHeartbeat(dn);
            // Verify that the callback passed in the expected parameters.
            ArgumentCaptor <StorageReport[]> captor = ArgumentCaptor.ForClass <StorageReport[]>
                                                          ();

            Org.Mockito.Mockito.Verify(nnSpy).SendHeartbeat(Matchers.Any <DatanodeRegistration
                                                                          >(), captor.Capture(), Matchers.AnyLong(), Matchers.AnyLong(), Matchers.AnyInt()
                                                            , Matchers.AnyInt(), Matchers.AnyInt(), Org.Mockito.Mockito.Any <VolumeFailureSummary
                                                                                                                             >());
            StorageReport[] reports = captor.GetValue();
            foreach (StorageReport report in reports)
            {
                Assert.AssertThat(report.GetStorage().GetStorageType(), IS.Is(storageType));
                Assert.AssertThat(report.GetStorage().GetState(), IS.Is(DatanodeStorage.State.Normal
                                                                        ));
            }
        }
示例#3
0
        public static float GetFloatGauge(string name, MetricsRecordBuilder rb)
        {
            ArgumentCaptor <float> captor = ArgumentCaptor.ForClass <float>();

            Org.Mockito.Mockito.Verify(rb, Org.Mockito.Mockito.AtLeast(0)).AddGauge(EqName(Interns.Info
                                                                                               (name, string.Empty)), captor.Capture());
            CheckCaptured(captor, name);
            return(captor.GetValue());
        }
示例#4
0
        public static long GetLongCounter(string name, MetricsRecordBuilder rb)
        {
            ArgumentCaptor <long> captor = ArgumentCaptor.ForClass <long>();

            Org.Mockito.Mockito.Verify(rb, Org.Mockito.Mockito.AtLeast(0)).AddCounter(EqName(
                                                                                          Interns.Info(name, string.Empty)), captor.Capture());
            CheckCaptured(captor, name);
            return(captor.GetValue());
        }
示例#5
0
        /// <exception cref="System.Exception"/>
        private ReceivedDeletedBlockInfo[] WaitForBlockReceived(ExtendedBlock fakeBlock,
                                                                DatanodeProtocolClientSideTranslatorPB mockNN)
        {
            string fakeBlockPoolId = fakeBlock.GetBlockPoolId();
            ArgumentCaptor <StorageReceivedDeletedBlocks[]> captor = ArgumentCaptor.ForClass <StorageReceivedDeletedBlocks
                                                                                              []>();

            GenericTestUtils.WaitFor(new _Supplier_457(mockNN, fakeBlockPoolId, captor), 100,
                                     10000);
            return(captor.GetValue()[0].GetBlocks());
        }
示例#6
0
		private void VerifyFailedStatus(MRAppMasterTest appMaster, string expectedJobState
			)
		{
			ArgumentCaptor<JobHistoryEvent> captor = ArgumentCaptor.ForClass<JobHistoryEvent>
				();
			// handle two events: AMStartedEvent and JobUnsuccessfulCompletionEvent
			Org.Mockito.Mockito.Verify(appMaster.spyHistoryService, Org.Mockito.Mockito.Times
				(2)).HandleEvent(captor.Capture());
			HistoryEvent @event = captor.GetValue().GetHistoryEvent();
			NUnit.Framework.Assert.IsTrue(@event is JobUnsuccessfulCompletionEvent);
			NUnit.Framework.Assert.AreEqual(((JobUnsuccessfulCompletionEvent)@event).GetStatus
				(), expectedJobState);
		}
        public virtual void TestRecovery()
        {
            FilePath[] localLogDirs       = GetLocalLogDirFiles(this.GetType().FullName, 2);
            string     localLogDirsString = localLogDirs[0].GetAbsolutePath() + "," + localLogDirs
                                            [1].GetAbsolutePath();

            conf.Set(YarnConfiguration.NmLogDirs, localLogDirsString);
            conf.SetBoolean(YarnConfiguration.LogAggregationEnabled, false);
            conf.SetLong(YarnConfiguration.NmLogRetainSeconds, YarnConfiguration.DefaultNmLogRetainSeconds
                         );
            dirsHandler.Init(conf);
            NMStateStoreService stateStore = new NMMemoryStateStoreService();

            stateStore.Init(conf);
            stateStore.Start();
            TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor logHandler =
                new TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor(this,
                                                                                          dispatcher, mockDelService, dirsHandler, stateStore);
            logHandler.Init(conf);
            logHandler.Start();
            logHandler.Handle(new LogHandlerAppStartedEvent(appId, user, null, ContainerLogsRetentionPolicy
                                                            .AllContainers, null));
            logHandler.Handle(new LogHandlerContainerFinishedEvent(container11, 0));
            logHandler.Handle(new LogHandlerAppFinishedEvent(appId));
            // simulate a restart and verify deletion is rescheduled
            logHandler.Close();
            logHandler = new TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor
                             (this, dispatcher, mockDelService, dirsHandler, stateStore);
            logHandler.Init(conf);
            logHandler.Start();
            ArgumentCaptor <Runnable> schedArg = ArgumentCaptor.ForClass <Runnable>();

            Org.Mockito.Mockito.Verify(logHandler.mockSched).Schedule(schedArg.Capture(), Matchers.AnyLong
                                                                          (), Matchers.Eq(TimeUnit.Milliseconds));
            // execute the runnable and verify another restart has nothing scheduled
            schedArg.GetValue().Run();
            logHandler.Close();
            logHandler = new TestNonAggregatingLogHandler.NonAggregatingLogHandlerWithMockExecutor
                             (this, dispatcher, mockDelService, dirsHandler, stateStore);
            logHandler.Init(conf);
            logHandler.Start();
            Org.Mockito.Mockito.Verify(logHandler.mockSched, Org.Mockito.Mockito.Never()).Schedule
                (Matchers.Any <Runnable>(), Matchers.AnyLong(), Matchers.Any <TimeUnit>());
            logHandler.Close();
        }
        public virtual void TestFilter()
        {
            FilterConfig config = MockConfig("myuser");

            StaticUserWebFilter.StaticUserFilter suf = new StaticUserWebFilter.StaticUserFilter
                                                           ();
            suf.Init(config);
            ArgumentCaptor <HttpServletRequestWrapper> wrapperArg = ArgumentCaptor.ForClass <HttpServletRequestWrapper
                                                                                             >();
            FilterChain chain = Org.Mockito.Mockito.Mock <FilterChain>();

            suf.DoFilter(Org.Mockito.Mockito.Mock <HttpServletRequest>(), Org.Mockito.Mockito.Mock
                         <ServletResponse>(), chain);
            Org.Mockito.Mockito.Verify(chain).DoFilter(wrapperArg.Capture(), Org.Mockito.Mockito
                                                       .AnyObject <ServletResponse>());
            HttpServletRequestWrapper wrapper = wrapperArg.GetValue();

            Assert.Equal("myuser", wrapper.GetUserPrincipal().GetName());
            Assert.Equal("myuser", wrapper.GetRemoteUser());
            suf.Destroy();
        }
        public virtual void TestRsrcUnused()
        {
            DeletionService      delService = Org.Mockito.Mockito.Mock <DeletionService>();
            long                 TargetMb   = 10 << 20;
            ResourceRetentionSet rss        = new ResourceRetentionSet(delService, TargetMb);
            // 3MB files @{10, 15}
            LocalResourcesTracker pubTracker = CreateMockTracker(null, 3 * 1024 * 1024, 2, 10
                                                                 , 5);
            // 1MB files @{3, 6, 9, 12}
            LocalResourcesTracker trackerA = CreateMockTracker("A", 1 * 1024 * 1024, 4, 3, 3);
            // 4MB file @{1}
            LocalResourcesTracker trackerB = CreateMockTracker("B", 4 * 1024 * 1024, 1, 10, 5
                                                               );
            // 2MB files @{7, 9, 11}
            LocalResourcesTracker trackerC = CreateMockTracker("C", 2 * 1024 * 1024, 3, 7, 2);

            // Total cache: 20MB; verify removed at least 10MB
            rss.AddResources(pubTracker);
            rss.AddResources(trackerA);
            rss.AddResources(trackerB);
            rss.AddResources(trackerC);
            long deleted = 0L;
            ArgumentCaptor <LocalizedResource> captor = ArgumentCaptor.ForClass <LocalizedResource
                                                                                 >();

            Org.Mockito.Mockito.Verify(pubTracker, Org.Mockito.Mockito.AtMost(2)).Remove(captor
                                                                                         .Capture(), IsA <DeletionService>());
            Org.Mockito.Mockito.Verify(trackerA, Org.Mockito.Mockito.AtMost(4)).Remove(captor
                                                                                       .Capture(), IsA <DeletionService>());
            Org.Mockito.Mockito.Verify(trackerB, Org.Mockito.Mockito.AtMost(1)).Remove(captor
                                                                                       .Capture(), IsA <DeletionService>());
            Org.Mockito.Mockito.Verify(trackerC, Org.Mockito.Mockito.AtMost(3)).Remove(captor
                                                                                       .Capture(), IsA <DeletionService>());
            foreach (LocalizedResource rem in captor.GetAllValues())
            {
                deleted += rem.GetSize();
            }
            NUnit.Framework.Assert.IsTrue(deleted >= 10 * 1024 * 1024);
            NUnit.Framework.Assert.IsTrue(deleted < 15 * 1024 * 1024);
        }
        /// <summary>
        /// Test that if splitThreshold is zero, then we always get a separate
        /// call per storage.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestAlwaysSplit()
        {
            StartUpCluster(0);
            NameNode nn = cluster.GetNameNode();
            DataNode dn = cluster.GetDataNodes()[0];

            // Create a file with a few blocks.
            CreateFile(GenericTestUtils.GetMethodName(), BlocksInFile);
            // Insert a spy object for the NN RPC.
            DatanodeProtocolClientSideTranslatorPB nnSpy = DataNodeTestUtils.SpyOnBposToNN(dn
                                                                                           , nn);

            // Trigger a block report so there is an interaction with the spy
            // object.
            DataNodeTestUtils.TriggerBlockReport(dn);
            ArgumentCaptor <StorageBlockReport[]> captor = ArgumentCaptor.ForClass <StorageBlockReport
                                                                                    []>();

            Org.Mockito.Mockito.Verify(nnSpy, Org.Mockito.Mockito.Times(cluster.GetStoragesPerDatanode
                                                                            ())).BlockReport(Matchers.Any <DatanodeRegistration>(), Matchers.AnyString(), captor
                                                                                             .Capture(), Org.Mockito.Mockito.AnyObject <BlockReportContext>());
            VerifyCapturedArguments(captor, 1, BlocksInFile);
        }
示例#11
0
        public virtual void TestGetRootQueues()
        {
            ApplicationClientProtocol applicationsManager = Org.Mockito.Mockito.Mock <ApplicationClientProtocol
                                                                                      >();
            GetQueueInfoResponse response  = Org.Mockito.Mockito.Mock <GetQueueInfoResponse>();
            QueueInfo            queueInfo = Org.Mockito.Mockito.Mock <QueueInfo>();

            Org.Mockito.Mockito.When(response.GetQueueInfo()).ThenReturn(queueInfo);
            try
            {
                Org.Mockito.Mockito.When(applicationsManager.GetQueueInfo(Org.Mockito.Mockito.Any
                                                                          <GetQueueInfoRequest>())).ThenReturn(response);
            }
            catch (YarnException e)
            {
                throw new IOException(e);
            }
            ResourceMgrDelegate delegate_ = new _ResourceMgrDelegate_69(applicationsManager,
                                                                        new YarnConfiguration());

            delegate_.GetRootQueues();
            ArgumentCaptor <GetQueueInfoRequest> argument = ArgumentCaptor.ForClass <GetQueueInfoRequest
                                                                                     >();

            try
            {
                Org.Mockito.Mockito.Verify(applicationsManager).GetQueueInfo(argument.Capture());
            }
            catch (YarnException e)
            {
                throw new IOException(e);
            }
            NUnit.Framework.Assert.IsTrue("Children of root queue not requested", argument.GetValue
                                              ().GetIncludeChildQueues());
            NUnit.Framework.Assert.IsTrue("Request wasn't to recurse through children", argument
                                          .GetValue().GetRecursive());
        }
        /// <exception cref="System.IO.IOException"/>
        private void RunTest(TestNNStorageRetentionManager.TestCaseDescription tc)
        {
            NNStorageRetentionManager.StoragePurger mockPurger = Org.Mockito.Mockito.Mock <NNStorageRetentionManager.StoragePurger
                                                                                           >();
            ArgumentCaptor <FSImageStorageInspector.FSImageFile> imagesPurgedCaptor = ArgumentCaptor
                                                                                      .ForClass <FSImageStorageInspector.FSImageFile>();
            ArgumentCaptor <FileJournalManager.EditLogFile> logsPurgedCaptor = ArgumentCaptor.
                                                                               ForClass <FileJournalManager.EditLogFile>();

            // Ask the manager to purge files we don't need any more
            new NNStorageRetentionManager(conf, tc.MockStorage(), tc.MockEditLog(mockPurger),
                                          mockPurger).PurgeOldStorage(NNStorage.NameNodeFile.Image);
            // Verify that it asked the purger to remove the correct files
            Org.Mockito.Mockito.Verify(mockPurger, Org.Mockito.Mockito.AtLeast(0)).PurgeImage
                (imagesPurgedCaptor.Capture());
            Org.Mockito.Mockito.Verify(mockPurger, Org.Mockito.Mockito.AtLeast(0)).PurgeLog(logsPurgedCaptor
                                                                                            .Capture());
            // Check images
            ICollection <string> purgedPaths = Sets.NewLinkedHashSet();

            foreach (FSImageStorageInspector.FSImageFile purged in imagesPurgedCaptor.GetAllValues
                         ())
            {
                purgedPaths.AddItem(FileToPath(purged.GetFile()));
            }
            NUnit.Framework.Assert.AreEqual(Joiner.On(",").Join(FilesToPaths(tc.expectedPurgedImages
                                                                             )), Joiner.On(",").Join(purgedPaths));
            // Check images
            purgedPaths.Clear();
            foreach (FileJournalManager.EditLogFile purged_1 in logsPurgedCaptor.GetAllValues
                         ())
            {
                purgedPaths.AddItem(FileToPath(purged_1.GetFile()));
            }
            NUnit.Framework.Assert.AreEqual(Joiner.On(",").Join(FilesToPaths(tc.expectedPurgedLogs
                                                                             )), Joiner.On(",").Join(purgedPaths));
        }
示例#13
0
        public virtual void TestFailureAndPutMetrics()
        {
            GraphiteSink       sink = new GraphiteSink();
            IList <MetricsTag> tags = new AList <MetricsTag>();

            tags.AddItem(new MetricsTag(MsInfo.Context, "all"));
            tags.AddItem(new MetricsTag(MsInfo.Hostname, "host"));
            ICollection <AbstractMetric> metrics = new HashSet <AbstractMetric>();

            metrics.AddItem(MakeMetric("foo1", 1.25));
            metrics.AddItem(MakeMetric("foo2", 2.25));
            MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long)10000, tags, metrics
                                                         );

            GraphiteSink.Graphite mockGraphite = MakeGraphite();
            Whitebox.SetInternalState(sink, "graphite", mockGraphite);
            // throw exception when first try
            Org.Mockito.Mockito.DoThrow(new IOException("IO exception")).When(mockGraphite).Write
                (Matchers.AnyString());
            sink.PutMetrics(record);
            Org.Mockito.Mockito.Verify(mockGraphite).Write(Matchers.AnyString());
            Org.Mockito.Mockito.Verify(mockGraphite).Close();
            // reset mock and try again
            Org.Mockito.Mockito.Reset(mockGraphite);
            Org.Mockito.Mockito.When(mockGraphite.IsConnected()).ThenReturn(false);
            ArgumentCaptor <string> argument = ArgumentCaptor.ForClass <string>();

            sink.PutMetrics(record);
            Org.Mockito.Mockito.Verify(mockGraphite).Write(argument.Capture());
            string result = argument.GetValue();

            Assert.Equal(true, result.Equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"
                                             + "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") || result.Equals
                             ("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"
                             ));
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestContainerCleaned()
        {
            Log.Info("STARTING testContainerCleaned");
            CyclicBarrier startLaunchBarrier    = new CyclicBarrier(2);
            CyclicBarrier completeLaunchBarrier = new CyclicBarrier(2);
            AppContext    mockContext           = Org.Mockito.Mockito.Mock <AppContext>();
            EventHandler  mockEventHandler      = Org.Mockito.Mockito.Mock <EventHandler>();

            Org.Mockito.Mockito.When(mockContext.GetEventHandler()).ThenReturn(mockEventHandler
                                                                               );
            TestContainerLauncherImpl.ContainerManagementProtocolClient mockCM = new TestContainerLauncherImpl.ContainerManagerForTest
                                                                                     (startLaunchBarrier, completeLaunchBarrier);
            TestContainerLauncherImpl.ContainerLauncherImplUnderTest ut = new TestContainerLauncherImpl.ContainerLauncherImplUnderTest
                                                                              (mockContext, mockCM);
            Configuration conf = new Configuration();

            ut.Init(conf);
            ut.Start();
            try
            {
                ContainerId             contId        = MakeContainerId(0l, 0, 0, 1);
                TaskAttemptId           taskAttemptId = MakeTaskAttemptId(0l, 0, 0, TaskType.Map, 0);
                string                  cmAddress     = "127.0.0.1:8000";
                StartContainersResponse startResp     = recordFactory.NewRecordInstance <StartContainersResponse
                                                                                         >();
                startResp.SetAllServicesMetaData(serviceResponse);
                Log.Info("inserting launch event");
                ContainerRemoteLaunchEvent mockLaunchEvent = Org.Mockito.Mockito.Mock <ContainerRemoteLaunchEvent
                                                                                       >();
                Org.Mockito.Mockito.When(mockLaunchEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                               .ContainerRemoteLaunch);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockLaunchEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                        );
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                              );
                Org.Mockito.Mockito.When(mockLaunchEvent.GetContainerToken()).ThenReturn(CreateNewContainerToken
                                                                                             (contId, cmAddress));
                ut.Handle(mockLaunchEvent);
                startLaunchBarrier.Await();
                Log.Info("inserting cleanup event");
                ContainerLauncherEvent mockCleanupEvent = Org.Mockito.Mockito.Mock <ContainerLauncherEvent
                                                                                    >();
                Org.Mockito.Mockito.When(mockCleanupEvent.GetType()).ThenReturn(ContainerLauncher.EventType
                                                                                .ContainerRemoteCleanup);
                Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerID()).ThenReturn(contId);
                Org.Mockito.Mockito.When(mockCleanupEvent.GetTaskAttemptID()).ThenReturn(taskAttemptId
                                                                                         );
                Org.Mockito.Mockito.When(mockCleanupEvent.GetContainerMgrAddress()).ThenReturn(cmAddress
                                                                                               );
                ut.Handle(mockCleanupEvent);
                completeLaunchBarrier.Await();
                ut.WaitForPoolToIdle();
                ArgumentCaptor <Org.Apache.Hadoop.Yarn.Event.Event> arg = ArgumentCaptor.ForClass <
                    Org.Apache.Hadoop.Yarn.Event.Event>();
                Org.Mockito.Mockito.Verify(mockEventHandler, Org.Mockito.Mockito.AtLeast(2)).Handle
                    (arg.Capture());
                bool containerCleaned = false;
                for (int i = 0; i < arg.GetAllValues().Count; i++)
                {
                    Log.Info(arg.GetAllValues()[i].ToString());
                    Org.Apache.Hadoop.Yarn.Event.Event currentEvent = arg.GetAllValues()[i];
                    if (currentEvent.GetType() == TaskAttemptEventType.TaContainerCleaned)
                    {
                        containerCleaned = true;
                    }
                }
                System.Diagnostics.Debug.Assert((containerCleaned));
            }
            finally
            {
                ut.Stop();
            }
        }
示例#15
0
        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()
                                            );
        }