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(); } }
/// <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(); } }