Example #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);
                    }
                }
            }
        }
        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);
        }
Example #3
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());
        }