예제 #1
0
        /// <summary>HADOOP-11932</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestHangOnSinkRead()
        {
            new ConfigBuilder().Add("*.period", 8).Add("test.sink.test.class", typeof(TestMetricsSystemImpl.TestSink
                                                                                      ).FullName).Save(TestMetricsConfig.GetTestFilename("hadoop-metrics2-test"));
            MetricsSystemImpl ms = new MetricsSystemImpl("Test");

            ms.Start();
            try
            {
                CountDownLatch collectingLatch = new CountDownLatch(1);
                MetricsSink    sink            = new TestMetricsSystemImpl.TestClosableSink(collectingLatch);
                ms.RegisterSink("closeableSink", "The sink will be used to test closeability", sink
                                );
                // trigger metric collection first time
                ms.OnTimerEvent();
                // Make sure that sink is collecting metrics
                Assert.True(collectingLatch.Await(1, TimeUnit.Seconds));
            }
            finally
            {
                ms.Stop();
            }
        }
예제 #2
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);
                    }
                }
            }
        }
예제 #3
0
        public virtual void TestQSize()
        {
            new ConfigBuilder().Add("*.period", 8).Add("test.sink.test.class", typeof(TestMetricsSystemImpl.TestSink
                                                                                      ).FullName).Save(TestMetricsConfig.GetTestFilename("hadoop-metrics2-test"));
            MetricsSystemImpl ms                     = new MetricsSystemImpl("Test");
            CountDownLatch    proceedSignal          = new CountDownLatch(1);
            CountDownLatch    reachedPutMetricSignal = new CountDownLatch(1);

            ms.Start();
            try
            {
                MetricsSink slowSink = Org.Mockito.Mockito.Mock <MetricsSink>();
                MetricsSink dataSink = Org.Mockito.Mockito.Mock <MetricsSink>();
                ms.RegisterSink("slowSink", "The sink that will wait on putMetric", slowSink);
                ms.RegisterSink("dataSink", "The sink I'll use to get info about slowSink", dataSink
                                );
                Org.Mockito.Mockito.DoAnswer(new _Answer_457(reachedPutMetricSignal, proceedSignal
                                                             )).When(slowSink).PutMetrics(Any <MetricsRecord>());
                // trigger metric collection first time
                ms.OnTimerEvent();
                Assert.True(reachedPutMetricSignal.Await(1, TimeUnit.Seconds));
                // Now that the slow sink is still processing the first metric,
                // its queue length should be 1 for the second collection.
                ms.OnTimerEvent();
                Org.Mockito.Mockito.Verify(dataSink, Org.Mockito.Mockito.Timeout(500).Times(2)).PutMetrics
                    (r1.Capture());
                IList <MetricsRecord> mr = r1.GetAllValues();
                Number qSize             = Iterables.Find(mr[1].Metrics(), new _Predicate_475()).Value();
                Assert.Equal(1, qSize);
            }
            finally
            {
                proceedSignal.CountDown();
                ms.Stop();
            }
        }
예제 #4
0
        public virtual void TestHangingSink()
        {
            new ConfigBuilder().Add("*.period", 8).Add("test.sink.test.class", typeof(TestMetricsSystemImpl.TestSink
                                                                                      ).FullName).Add("test.sink.hanging.retry.delay", "1").Add("test.sink.hanging.retry.backoff"
                                                                                                                                                , "1.01").Add("test.sink.hanging.retry.count", "0").Save(TestMetricsConfig.GetTestFilename
                                                                                                                                                                                                             ("hadoop-metrics2-test"));
            MetricsSystemImpl ms = new MetricsSystemImpl("Test");

            ms.Start();
            TestMetricsSystemImpl.TestSource s = ms.Register("s3", "s3 desc", new TestMetricsSystemImpl.TestSource
                                                                 ("s3rec"));
            s.c1.Incr();
            TestMetricsSystemImpl.HangingSink hanging = new TestMetricsSystemImpl.HangingSink
                                                            ();
            ms.RegisterSink("hanging", "Hang the sink!", hanging);
            ms.PublishMetricsNow();
            Assert.Equal(1L, ms.droppedPubAll.Value());
            NUnit.Framework.Assert.IsFalse(hanging.GetInterrupted());
            ms.Stop();
            ms.Shutdown();
            Assert.True(hanging.GetInterrupted());
            Assert.True("The sink didn't get called after its first hang "
                        + "for subsequent records.", hanging.GetGotCalledSecondTime());
        }
예제 #5
0
        public virtual void TestMultiThreadedPublish()
        {
            int numThreads = 10;

            new ConfigBuilder().Add("*.period", 80).Add("test.sink.collector." + MetricsConfig
                                                        .QueueCapacityKey, numThreads).Save(TestMetricsConfig.GetTestFilename("hadoop-metrics2-test"
                                                                                                                              ));
            MetricsSystemImpl ms = new MetricsSystemImpl("Test");

            ms.Start();
            TestMetricsSystemImpl.CollectingSink sink = new TestMetricsSystemImpl.CollectingSink
                                                            (numThreads);
            ms.RegisterSink("collector", "Collector of values from all threads.", sink);
            TestMetricsSystemImpl.TestSource[] sources = new TestMetricsSystemImpl.TestSource
                                                         [numThreads];
            Thread[]      threads  = new Thread[numThreads];
            string[]      results  = new string[numThreads];
            CyclicBarrier barrier1 = new CyclicBarrier(numThreads);
            CyclicBarrier barrier2 = new CyclicBarrier(numThreads);

            for (int i = 0; i < numThreads; i++)
            {
                sources[i] = ms.Register("threadSource" + i, "A source of my threaded goodness.",
                                         new TestMetricsSystemImpl.TestSource("threadSourceRec" + i));
                threads[i] = new Thread(new _Runnable_194(results, sink, barrier1, sources
                                                          , ms, barrier2), string.Empty + i);
            }
            // Wait for all the threads to come here so we can hammer
            // the system at the same time
            // Since some other thread may have snatched my metric,
            // I need to wait for the threads to finish before checking.
            foreach (Thread t in threads)
            {
                t.Start();
            }
            foreach (Thread t_1 in threads)
            {
                t_1.Join();
            }
            Assert.Equal(0L, ms.droppedPubAll.Value());
            Assert.True(StringUtils.Join("\n", Arrays.AsList(results)), Iterables
                        .All(Arrays.AsList(results), new _Predicate_240()));
            ms.Stop();
            ms.Shutdown();
        }
예제 #6
0
        public virtual void TestGangliaMetrics2()
        {
            ConfigBuilder cb = new ConfigBuilder().Add("default.period", 10).Add("test.sink.gsink30.context"
                                                                                 , "test").Add("test.sink.gsink31.context", "test").Save(TestMetricsConfig.GetTestFilename
                                                                                                                                             ("hadoop-metrics2-test"));
            // filter out only "test"
            // filter out only "test"
            MetricsSystemImpl ms = new MetricsSystemImpl("Test");

            ms.Start();
            TestGangliaMetrics.TestSource s1 = ms.Register("s1", "s1 desc", new TestGangliaMetrics.TestSource
                                                               ("s1rec"));
            s1.c1.Incr();
            s1.xxx.Incr();
            s1.g1.Set(2);
            s1.yyy.Incr(2);
            s1.s1.Add(0);
            int expectedCountFromGanglia30 = expectedMetrics.Length;
            int expectedCountFromGanglia31 = 2 * expectedMetrics.Length;
            // Setup test for GangliaSink30
            AbstractGangliaSink gsink30 = new GangliaSink30();

            gsink30.Init(cb.Subset("test"));
            TestGangliaMetrics.MockDatagramSocket mockds30 = new TestGangliaMetrics.MockDatagramSocket
                                                                 (this);
            GangliaMetricsTestHelper.SetDatagramSocket(gsink30, mockds30);
            // Setup test for GangliaSink31
            AbstractGangliaSink gsink31 = new GangliaSink31();

            gsink31.Init(cb.Subset("test"));
            TestGangliaMetrics.MockDatagramSocket mockds31 = new TestGangliaMetrics.MockDatagramSocket
                                                                 (this);
            GangliaMetricsTestHelper.SetDatagramSocket(gsink31, mockds31);
            // register the sinks
            ms.Register("gsink30", "gsink30 desc", gsink30);
            ms.Register("gsink31", "gsink31 desc", gsink31);
            ms.PublishMetricsNow();
            // publish the metrics
            ms.Stop();
            // check GanfliaSink30 data
            CheckMetrics(mockds30.GetCapturedSend(), expectedCountFromGanglia30);
            // check GanfliaSink31 data
            CheckMetrics(mockds31.GetCapturedSend(), expectedCountFromGanglia31);
        }