예제 #1
0
        public void ExceptionInAttach_Throws()
        {
            var source    = new FailureMetricSource(throwOnAttach: true);
            var collector = new MetricsCollector(
                new MetricsCollectorOptions
            {
                Endpoints        = new[] { new MetricEndpoint("Local", new LocalMetricHandler()), },
                Sources          = new[] { source },
                RetryInterval    = TimeSpan.Zero,
                SnapshotInterval = TimeSpan.FromMilliseconds(20),
            }
                );

            Assert.Throws <Exception>(() => collector.Start());
        }
예제 #2
0
        public async Task MetricSourcesAreAttachedAndDetached()
        {
            var metricSource = new TestMetricSource();
            var collector    = new MetricsCollector(
                new MetricsCollectorOptions
            {
                Endpoints = new []
                {
                    new MetricEndpoint("Local", new LocalMetricHandler()),
                },
                Sources          = new[] { metricSource },
                RetryInterval    = TimeSpan.Zero,
                SnapshotInterval = TimeSpan.FromMilliseconds(20),
            }
                );

            collector.Start();

            try
            {
                // make sure initialization happened
                await Task.WhenAny(metricSource.AttachTask, Task.Delay(1000));

                Assert.True(metricSource.AttachTask.IsCompleted, "Metric source was not attached");

                // make sure we got snapshotted
                await Task.WhenAny(metricSource.SnapshotTask, Task.Delay(30000));

                Assert.True(metricSource.SnapshotTask.IsCompleted, "Metric source was not snapshotted");
            }
            finally
            {
                collector.Stop();

                // make sure we got detached
                await Task.WhenAny(metricSource.DetachTask, Task.Delay(1000));

                Assert.True(metricSource.DetachTask.IsCompleted, "Metric source was not detached");
            }
        }