Beispiel #1
0
        public virtual void TestInitFirstVerifyStopInvokedImmediately()
        {
            DefaultMetricsSystem.Shutdown();
            new ConfigBuilder().Add("*.period", 8).Add("test.sink.test.class", typeof(TestMetricsSystemImpl.TestSink
                                                                                      ).FullName).Add("test.*.source.filter.exclude", "s0").Add("test.source.s1.metric.filter.exclude"
                                                                                                                                                , "X*").Add("test.sink.sink1.metric.filter.exclude", "Y*").Add("test.sink.sink2.metric.filter.exclude"
                                                                                                                                                                                                               , "Y*").Save(TestMetricsConfig.GetTestFilename("hadoop-metrics2-test"));
            //.add("test.sink.plugin.urls", getPluginUrlsAsString())
            MetricsSystemImpl ms = new MetricsSystemImpl("Test");

            ms.Start();
            ms.Register("s0", "s0 desc", new TestMetricsSystemImpl.TestSource("s0rec"));
            TestMetricsSystemImpl.TestSource s1 = ms.Register("s1", "s1 desc", new TestMetricsSystemImpl.TestSource
                                                                  ("s1rec"));
            s1.c1.Incr();
            s1.xxx.Incr();
            s1.g1.Set(2);
            s1.yyy.Incr(2);
            s1.s1.Add(0);
            MetricsSink sink1 = Org.Mockito.Mockito.Mock <MetricsSink>();
            MetricsSink sink2 = Org.Mockito.Mockito.Mock <MetricsSink>();

            ms.RegisterSink("sink1", "sink1 desc", sink1);
            ms.RegisterSink("sink2", "sink2 desc", sink2);
            ms.PublishMetricsNow();
            // publish the metrics
            ms.Stop();
            ms.Shutdown();
            //When we call stop, at most two sources will be consumed by each sink thread.
            Org.Mockito.Mockito.Verify(sink1, Org.Mockito.Mockito.AtMost(2)).PutMetrics(r1.Capture
                                                                                            ());
            IList <MetricsRecord> mr1 = r1.GetAllValues();

            Org.Mockito.Mockito.Verify(sink2, Org.Mockito.Mockito.AtMost(2)).PutMetrics(r2.Capture
                                                                                            ());
            IList <MetricsRecord> mr2 = r2.GetAllValues();

            if (mr1.Count != 0 && mr2.Count != 0)
            {
                CheckMetricsRecords(mr1);
                MoreAsserts.AssertEquals("output", mr1, mr2);
            }
            else
            {
                if (mr1.Count != 0)
                {
                    CheckMetricsRecords(mr1);
                }
                else
                {
                    if (mr2.Count != 0)
                    {
                        CheckMetricsRecords(mr2);
                    }
                }
            }
        }
Beispiel #2
0
 public virtual void TestTransitionToActive()
 {
     Org.Mockito.Mockito.DoReturn(StandbyReadyResult).When(mockProtocol).GetServiceStatus
         ();
     NUnit.Framework.Assert.AreEqual(0, RunTool("-transitionToActive", "nn1"));
     Org.Mockito.Mockito.Verify(mockProtocol).TransitionToActive(reqInfoCaptor.Capture
                                                                     ());
     NUnit.Framework.Assert.AreEqual(HAServiceProtocol.RequestSource.RequestByUser, reqInfoCaptor
                                     .GetValue().GetSource());
 }
Beispiel #3
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"));
        }
Beispiel #4
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
                                                                        ));
            }
        }
        public async Task NewBrandCommandHandler_Works()
        {
            var repository = new Mock <IRepository>();

            var brand = new Brand {
                Id = 1, Name = "a", ImageUri = "uri"
            };

            var captor = new ArgumentCaptor <Brand>();

            repository.Setup(x => x.InsertAsync(captor.Capture()))
            .ReturnsAsync(brand);

            var handler = new NewBrandCommandHandler(repository.Object);

            var result = await handler
                         .Handle(new NewBrandCommand(brand.Name, brand.ImageUri), It.IsAny <CancellationToken>())
                         .ConfigureAwait(false);

            result.Should().BeOfType <BrandDto>();
            result.Id.Should().Equals(brand.Id);
            result.ImageUri.Should().Equals(brand.ImageUri);
            result.Name.Should().Equals(brand.Name);

            captor.Value.Name.Should().Be(brand.Name);
            captor.Value.ImageUri.Should().Be(brand.ImageUri);

            repository.Verify(x => x.InsertAsync(captor.Value), Times.Once);
            repository.VerifyNoOtherCalls();
        }
        public async Task NewRecordCommandHandler_Verify_Dependencies()
        {
            var repository = new Mock <IRepository>();

            var record = GetRecord();

            var flavors = new string[] { "a", "b", "c" };

            var flavorPredicateCaptor = new ExpressionCaptor <Flavor, bool>();

            repository.Setup(x => x.ListAsync(flavorPredicateCaptor.Capture()))
            .ReturnsAsync(new List <Flavor> {
                new Flavor {
                    Id = 1, Name = "a",
                }
            });

            var recordCaptor = new ArgumentCaptor <Record>();

            repository.Setup(x => x.InsertAsync(recordCaptor.Capture()))
            .ReturnsAsync(record);

            var flavorCaptor = new ArgumentCaptor <List <Flavor> >();

            repository.Setup(x => x.InsertRangeAsync(flavorCaptor.Capture()))
            .ReturnsAsync(
                new List <Flavor> {
                new Flavor {
                    Id = 2, Name = "b",
                },
                new Flavor {
                    Id = 3, Name = "c",
                }
            });

            var recordFlavorCaptor = new ArgumentCaptor <List <RecordFlavor> >();

            repository.Setup(x => x.InsertRangeAsync(recordFlavorCaptor.Capture()));

            var handler = new NewRecordCommandHandler(repository.Object);

            var result = await handler
                         .Handle(new NewRecordCommand(record.CoffeeId, record.DoseIn, record.DoseOut, record.Time, flavors, record.Rating),
                                 It.IsAny <CancellationToken>())
                         .ConfigureAwait(false);

            repository.Verify(x => x.InsertAsync(recordCaptor.Value), Times.Once);
            repository.Verify(x => x.InsertRangeAsync(flavorCaptor.Value), Times.Once);
            repository.Verify(x => x.InsertRangeAsync(recordFlavorCaptor.Value), Times.Once);
            repository.Verify(x => x.ListAsync(flavorPredicateCaptor.Value), Times.Once);
            repository.VerifyNoOtherCalls();
        }
Beispiel #7
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();
        }
Beispiel #9
0
        public virtual void TestCommon()
        {
            MetricsVisitor         visitor  = Org.Mockito.Mockito.Mock <MetricsVisitor>();
            MetricsRegistry        registry = new MetricsRegistry("test");
            IList <AbstractMetric> metrics  = ((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl
                                                                           )((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl
                                                                                                                                    )((MetricsRecordBuilderImpl)MetricsLists.Builder("test").AddCounter(Interns.Info
                                                                                                                                                                                                            ("c1", "int counter"), 1)).AddCounter(Interns.Info("c2", "long counter"), 2L)).AddGauge
                                                                                                            (Interns.Info("g1", "int gauge"), 5)).AddGauge(Interns.Info("g2", "long gauge"),
                                                                                                                                                           6L)).AddGauge(Interns.Info("g3", "float gauge"), 7f)).AddGauge(Interns.Info("g4"
                                                                                                                                                                                                                                       , "double gauge"), 8d)).Metrics();

            foreach (AbstractMetric metric in metrics)
            {
                metric.Visit(visitor);
            }
            Org.Mockito.Mockito.Verify(visitor).Counter(c1.Capture(), Eq(1));
            Assert.Equal("c1 name", "c1", c1.GetValue().Name());
            Assert.Equal("c1 description", "int counter", c1.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Counter(c2.Capture(), Eq(2L));
            Assert.Equal("c2 name", "c2", c2.GetValue().Name());
            Assert.Equal("c2 description", "long counter", c2.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g1.Capture(), Eq(5));
            Assert.Equal("g1 name", "g1", g1.GetValue().Name());
            Assert.Equal("g1 description", "int gauge", g1.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g2.Capture(), Eq(6L));
            Assert.Equal("g2 name", "g2", g2.GetValue().Name());
            Assert.Equal("g2 description", "long gauge", g2.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g3.Capture(), Eq(7f));
            Assert.Equal("g3 name", "g3", g3.GetValue().Name());
            Assert.Equal("g3 description", "float gauge", g3.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g4.Capture(), Eq(8d));
            Assert.Equal("g4 name", "g4", g4.GetValue().Name());
            Assert.Equal("g4 description", "double gauge", g4.GetValue().Description
                             ());
        }
        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 void NowPlayingPlayFromIndex()
        {
            const string message       = @" 
                {
                    ""context"": ""nowplayinglistplay"",
                    ""data"": 2
                } 
            ";
            var          socketMessage = new SocketMessage(JObject.Parse(message));
            var          messageEvent  = new MessageEvent(
                socketMessage.Context,
                socketMessage.Data,
                string.Empty,
                "5");

            _request.Execute(messageEvent);
            _apiAdapter.Verify(adapter => adapter.PlayIndex(2));
            var captor = new ArgumentCaptor <PluginResponseAvailableEvent>();

            _hub.Verify(hub => hub.Publish(captor.Capture()));
            Assert.AreEqual("nowplayinglistplay", captor.Value.Message.Context);
        }
Beispiel #12
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));
        }
        public async Task NewCoffeeCommandHandler_Works()
        {
            var repository = new Mock <IRepository>();

            var coffee = new Coffee
            {
                Id         = 1,
                BrandId    = 1,
                CoffeeType = Core.Enums.CoffeeType.Robusto,
                Country    = "a",
            };

            var captor = new ArgumentCaptor <Coffee>();

            repository.Setup(x => x.InsertAsync(captor.Capture()))
            .ReturnsAsync(coffee);

            var handler = new NewCoffeeCommandHandler(repository.Object);

            var result = await handler
                         .Handle(new NewCoffeeCommand(coffee.BrandId, coffee.CoffeeType.ToString(), coffee.Country),
                                 It.IsAny <CancellationToken>())
                         .ConfigureAwait(false);

            result.Should().BeOfType <CoffeeDto>();
            result.Id.Should().Equals(coffee.Id);
            result.CoffeeType.Should().Equals(coffee.CoffeeType);
            result.Country.Should().Equals(coffee.Country);

            captor.Value.BrandId.Should().Be(coffee.BrandId);
            captor.Value.CoffeeType.Should().Be(coffee.CoffeeType);
            captor.Value.Country.Should().Be(coffee.Country);

            repository.Verify(x => x.InsertAsync(captor.Value), Times.Once);
            repository.VerifyNoOtherCalls();
        }
Beispiel #15
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"
                             ));
        }
        /// <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);
        }
Beispiel #17
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()
                                            );
        }
        public async Task NewRecordCommandHandler_Verify_Expressions()
        {
            var repository = new Mock <IRepository>();

            var record = GetRecord();

            var flavors = new string[] { "a", "b", "c" };

            var flavorPredicateCaptor = new ExpressionCaptor <Flavor, bool>();

            repository.Setup(x => x.ListAsync(flavorPredicateCaptor.Capture()))
            .ReturnsAsync(new List <Flavor> {
                new Flavor {
                    Id = 1, Name = "a",
                }
            });

            var recordCaptor = new ArgumentCaptor <Record>();

            repository.Setup(x => x.InsertAsync(recordCaptor.Capture()))
            .ReturnsAsync(record);

            var insertFlavorCaptor = new ArgumentCaptor <List <Flavor> >();

            repository.Setup(x => x.InsertRangeAsync(insertFlavorCaptor.Capture()))
            .ReturnsAsync(
                new List <Flavor> {
                new Flavor {
                    Id = 2, Name = "b",
                },
                new Flavor {
                    Id = 3, Name = "c",
                }
            });

            var recordFlavorCaptor = new ArgumentCaptor <List <RecordFlavor> >();

            repository.Setup(x => x.InsertRangeAsync(recordFlavorCaptor.Capture()));

            var handler = new NewRecordCommandHandler(repository.Object);

            var result = await handler
                         .Handle(new NewRecordCommand(record.CoffeeId, record.DoseIn, record.DoseOut, record.Time, flavors, record.Rating),
                                 It.IsAny <CancellationToken>())
                         .ConfigureAwait(false);

            var existingFlavors = new List <Flavor> {
                new Flavor {
                    Name = "a"
                }, new Flavor {
                    Name = "d"
                }, new Flavor {
                    Name = "e"
                },
            };
            var queriedFlavors = existingFlavors.Where(flavorPredicateCaptor.Compile());

            queriedFlavors.Select(x => x.Name).Should().Equal("a");

            recordCaptor.Value.CoffeeId.Should().Be(record.CoffeeId);
            recordCaptor.Value.DoseIn.Should().Be(record.DoseIn);
            recordCaptor.Value.DoseOut.Should().Be(record.DoseOut);
            recordCaptor.Value.Time.Should().Be(record.Time);

            insertFlavorCaptor.Value.Select(x => x.Name).Should().Equal("b", "c");
            recordFlavorCaptor
            .Value
            .Select(x => (x.FlavorId, x.RecordId))
            .Should().Equal(
                new List <(long, long)>
            {
                (1, 1),
                (2, 1),
                (3, 1)
            });
Beispiel #19
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());
        }
Beispiel #20
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());
        }
        /// <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();
            }
        }
        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);
        }