コード例 #1
0
        public void Clean_WithNoReportsRegistered_RemovesAllEvents()
        {
            ResetCleaner();

            const string context  = "";
            var          registry = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(context, registry);
            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var metric = new EventMetric();

            registry.Event(MetricName, () => { return(metric); }, MetricTags.None);

            metric.Record();
            metric.Record();
            metric.Record();
            var registryCounts = GetRegistryEventDetailCounts(MetricNameType);

            registryCounts[context].Should().Be(3);

            timer.OnTimerCallback();

            registryCounts = GetRegistryEventDetailCounts(MetricNameType);
            registryCounts[context].Should().Be(0);
        }
コード例 #2
0
        public void Clean_WithAllReportsFilteringOutEvents_RemovesAllEvents()
        {
            ResetCleaner();

            const string context  = "";
            var          registry = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(context, registry);
            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric       = new EventMetric();

            registry.Event(MetricName, () => { return(metric); }, MetricTags.None);
            metric.Record();
            metric.Record();
            metric.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, new List <EventValueSource>());
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, new List <EventValueSource>());

            GetReportsReportedEventDetailCount(reportIndex1, MetricNameType).Should().Be(0);
            GetReportsReportedEventDetailCount(reportIndex2, MetricNameType).Should().Be(0);
            var registryCounts = GetRegistryEventDetailCounts(MetricNameType);

            registryCounts[context].Should().Be(3);

            timer.OnTimerCallback();

            registryCounts = GetRegistryEventDetailCounts(MetricNameType);
            registryCounts[context].Should().Be(0);
        }
コード例 #3
0
        public void Clean_IgnoresReportsThatHaveNotReportedAnyEvents()
        {
            ResetCleaner();

            const string context  = "";
            var          registry = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(context, registry);
            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric       = new EventMetric();

            registry.Event(MetricName, () => { return(metric); }, MetricTags.None);

            metric.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry.DataProvider.Events);

            GetReportsReportedEventDetailCount(reportIndex1, metricNameTypeTags).Should().Be(1);
            GetReportsReportedEventDetailCount(reportIndex2, metricNameTypeTags).Should().Be(0);

            timer.OnTimerCallback();

            var registryCounts = GetRegistryEventDetailCounts(MetricNameType);

            registryCounts[context].Should().Be(0);
        }
コード例 #4
0
        public void Clean_WithMultipleRegistriesInSeparateContexts_RemovesEvents()
        {
            ResetCleaner();

            const string ctx1      = "ctx1";
            var          registry1 = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(ctx1, registry1);

            const string ctx2      = "ctx2";
            var          registry2 = new DefaultMetricsRegistry();

            EventMetricsCleaner.ContextRegistries.Add(ctx2, registry2);

            var timer = new MockTimer();

            EventMetricsCleaner.EnableTestTimer(timer);

            var reportIndex1 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric1      = new EventMetric();

            registry1.Event("test1", () => { return(metric1); }, MetricTags.None);
            metric1.Record();
            metric1.Record();
            metric1.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex1, registry1.DataProvider.Events);

            var reportIndex2 = EventMetricsCleaner.RegisterReport(new TimeSpan(0, 0, 0, 60));
            var metric2      = new EventMetric();

            registry2.Event("test2", () => { return(metric2); }, MetricTags.None);
            metric2.Record();
            metric2.Record();
            EventMetricsCleaner.UpdateTotalReportedEvents(reportIndex2, registry2.DataProvider.Events);

            var registryCounts = GetRegistryEventDetailCounts("test1.event");

            registryCounts[ctx1].Should().Be(3);
            registryCounts[ctx2].Should().Be(0);
            registryCounts = GetRegistryEventDetailCounts("test2.event");
            registryCounts[ctx1].Should().Be(0);
            registryCounts[ctx2].Should().Be(2);

            timer.OnTimerCallback();

            registryCounts = GetRegistryEventDetailCounts("test1.event");
            registryCounts[ctx1].Should().Be(0);
            registryCounts[ctx2].Should().Be(0);
            registryCounts = GetRegistryEventDetailCounts("test2.event");
            registryCounts[ctx1].Should().Be(0);
            registryCounts[ctx2].Should().Be(0);
        }