public void TryFlushMaxUniqueStatsBeforeFlush() { var handler = new Mock <IBufferBuilderHandler>(); var parameters = MetricAggregatorParametersFactory.Create( handler.Object, TimeSpan.FromMinutes(1), maxUniqueStatsBeforeFlush: 3); var aggregator = new AggregatorFlusher <StatsMetric>(parameters, MetricType.Count); Add(aggregator, "key1", new StatsMetric { }); Add(aggregator, "key2", new StatsMetric { }); Flush(aggregator); handler.Verify(h => h.Handle(It.IsAny <byte[]>(), It.IsAny <int>()), Times.Never()); Add(aggregator, "key3", new StatsMetric { }); Flush(aggregator); handler.Verify(h => h.Handle(It.IsAny <byte[]>(), It.IsAny <int>()), Times.Once()); Add(aggregator, "key4", new StatsMetric { }); Flush(aggregator); handler.Verify(h => h.Handle(It.IsAny <byte[]>(), It.IsAny <int>()), Times.Once()); Flush(aggregator, force: true); handler.Verify(h => h.Handle(It.IsAny <byte[]>(), It.IsAny <int>()), Times.Exactly(2)); }
public void OnNewValue() { var handler = new BufferBuilderHandlerMock(); var aggregator = new GaugeAggregator(MetricAggregatorParametersFactory.Create(handler.Object)); AddStatsMetric(aggregator, "s1", 1); AddStatsMetric(aggregator, "s1", 2); AddStatsMetric(aggregator, "s2", 3); aggregator.TryFlush(force: true); Assert.AreEqual("s1:2|g|@0,s2:3|g|@0", handler.Value); }
public void Pool() { var handler = new BufferBuilderHandlerMock(); var parameters = MetricAggregatorParametersFactory.Create(handler.Object, TimeSpan.FromMinutes(1), 1); var aggregator = new SetAggregator(parameters, null); // Check StatsMetricSet instance go back to the pool for (int i = 0; i < 10; ++i) { AddStatsMetric(aggregator, "s1", i.ToString()); Assert.AreEqual($"s1:{i}|s|@0", handler.Value); } }
public void OnNewValue() { var handler = new BufferBuilderHandlerMock(); var aggregator = new SetAggregator(MetricAggregatorParametersFactory.Create(handler.Object), null); AddStatsMetric(aggregator, "s1", "1"); AddStatsMetric(aggregator, "s1", "2"); AddStatsMetric(aggregator, "s1", "2"); AddStatsMetric(aggregator, "s1", "2"); AddStatsMetric(aggregator, "s2", "3"); aggregator.TryFlush(force: true); Assert.AreEqual("s1:1|s|@0,s1:2|s|@0,s2:3|s|@0", handler.Value); AddStatsMetric(aggregator, "s1", "4"); aggregator.TryFlush(force: true); Assert.AreEqual("s1:4|s|@0", handler.Value); }
public void TryFlushFlushInterval() { var handler = new Mock <IBufferBuilderHandler>(); var parameters = MetricAggregatorParametersFactory.Create( handler.Object, TimeSpan.FromMilliseconds(500), maxUniqueStatsBeforeFlush: 100); var aggregator = new AggregatorFlusher <StatsMetric>(parameters, MetricType.Count); Add(aggregator, "key", new StatsMetric { }); Flush(aggregator); handler.Verify(h => h.Handle(It.IsAny <byte[]>(), It.IsAny <int>()), Times.Never()); Thread.Sleep(TimeSpan.FromSeconds(1)); Flush(aggregator); handler.Verify(h => h.Handle(It.IsAny <byte[]>(), It.IsAny <int>()), Times.Once()); }