Пример #1
0
        public virtual void TestRegisterDupError()
        {
            MetricsSystem ms = new MetricsSystemImpl("test");

            TestMetricsSystemImpl.TestSource ts = new TestMetricsSystemImpl.TestSource("ts");
            ms.Register(ts);
            ms.Register(ts);
        }
Пример #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 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);
        }
Пример #4
0
        public virtual void TestRegisterDups()
        {
            MetricsSystem ms = new MetricsSystemImpl();

            TestMetricsSystemImpl.TestSource ts1 = new TestMetricsSystemImpl.TestSource("ts1"
                                                                                        );
            TestMetricsSystemImpl.TestSource ts2 = new TestMetricsSystemImpl.TestSource("ts2"
                                                                                        );
            ms.Register("ts1", string.Empty, ts1);
            MetricsSource s1 = ms.GetSource("ts1");

            NUnit.Framework.Assert.IsNotNull(s1);
            // should work when metrics system is not started
            ms.Register("ts1", string.Empty, ts2);
            MetricsSource s2 = ms.GetSource("ts1");

            NUnit.Framework.Assert.IsNotNull(s2);
            NUnit.Framework.Assert.AreNotSame(s1, s2);
            ms.Shutdown();
        }
Пример #5
0
        public virtual void TestRegisterSourceWithoutName()
        {
            MetricsSystem ms = new MetricsSystemImpl();

            TestMetricsSystemImpl.TestSource  ts  = new TestMetricsSystemImpl.TestSource("ts");
            TestMetricsSystemImpl.TestSource2 ts2 = new TestMetricsSystemImpl.TestSource2("ts2"
                                                                                          );
            ms.Register(ts);
            ms.Register(ts2);
            ms.Init("TestMetricsSystem");
            // if metrics source is registered without name,
            // the class name will be used as the name
            MetricsSourceAdapter sa = ((MetricsSystemImpl)ms).GetSourceAdapter("TestSource");

            NUnit.Framework.Assert.IsNotNull(sa);
            MetricsSourceAdapter sa2 = ((MetricsSystemImpl)ms).GetSourceAdapter("TestSource2"
                                                                                );

            NUnit.Framework.Assert.IsNotNull(sa2);
            ms.Shutdown();
        }
Пример #6
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();
        }
Пример #7
0
        public virtual void TestStartStopStart()
        {
            DefaultMetricsSystem.Shutdown();
            // Clear pre-existing source names.
            MetricsSystemImpl ms = new MetricsSystemImpl("test");

            TestMetricsSystemImpl.TestSource ts = new TestMetricsSystemImpl.TestSource("ts");
            ms.Start();
            ms.Register("ts", string.Empty, ts);
            MetricsSourceAdapter sa = ms.GetSourceAdapter("ts");

            NUnit.Framework.Assert.IsNotNull(sa);
            NUnit.Framework.Assert.IsNotNull(sa.GetMBeanName());
            ms.Stop();
            ms.Shutdown();
            ms.Start();
            sa = ms.GetSourceAdapter("ts");
            NUnit.Framework.Assert.IsNotNull(sa);
            NUnit.Framework.Assert.IsNotNull(sa.GetMBeanName());
            ms.Stop();
            ms.Shutdown();
        }
Пример #8
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());
        }