Пример #1
0
 public void MeasureFunctionCorrectlyMeasuresValues()
 {
     TimespanMetricType metric = new TimespanMetricType(
         category: "telemetry",
         disabled: false,
         lifetime: Lifetime.Application,
         name: "timespan_metric",
         sendInPings: new string[] { "store1" },
         timeUnit: TimeUnit.Millisecond
         );
Пример #2
0
        public void TestGetValueThrows()
        {
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Application,
                name: "timespan_metric",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Millisecond
                );

            Assert.Throws <NullReferenceException>(() => metric.TestGetValue());
        }
Пример #3
0
        public void TestSetRawNanos()
        {
            ulong timespanNanos = 6 * 1000000000L;

            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Ping,
                name: "explicit_timespan",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Second
                );

            metric.SetRawNanos(timespanNanos);
            Assert.Equal <ulong>(6, metric.TestGetValue());
        }
Пример #4
0
        public void APISavesToSecondaryPings()
        {
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Application,
                name: "timespan_metric",
                sendInPings: new string[] { "store1", "store2" },
                timeUnit: TimeUnit.Millisecond
                );

            metric.Start();
            metric.Stop();

            // Check that data was properly recorded in the second ping.
            Assert.True(metric.TestHasValue("store2"));
            Assert.True(metric.TestGetValue("store2") >= 0);
        }
Пример #5
0
        public void APIMustCorrectlyCancel()
        {
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Application,
                name: "timespan_metric",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Millisecond
                );

            // Record a timespan.
            metric.Start();
            metric.Cancel();
            metric.Stop();

            // Check that data was not recorded.
            Assert.False(metric.TestHasValue(), "The API should not record an error if the metric is cancelled");
            Assert.Equal(1, metric.TestGetNumRecordedErrors(ErrorType.InvalidState));
        }
Пример #6
0
        public void SetRawNanosDoesNotOverwriteValue()
        {
            ulong timespanNanos       = 6 * 1000000000L;
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Ping,
                name: "explicit_timespan_1",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Second
                );

            metric.Start();
            metric.Stop();
            ulong value = metric.TestGetValue();

            metric.SetRawNanos(timespanNanos);

            Assert.Equal <ulong>(value, metric.TestGetValue());
        }
Пример #7
0
        public void DisabledTimespansMustNotRecordData()
        {
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: true,
                lifetime: Lifetime.Application,
                name: "timespan_metric",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Millisecond
                );

            // Record a timespan.
            metric.Start();
            metric.Stop();

            // Let's also call cancel() to make sure it's a no-op.
            metric.Cancel();

            // Check that data was not recorded.
            Assert.False(metric.TestHasValue(), "The API should not record a counter if metric is disabled");
        }
Пример #8
0
        public void SetRawNanosDoesNothingWhenTimerIsRunning()
        {
            ulong timespanNanos = 1000000000L;

            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Ping,
                name: "explicit_timespan",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Second
                );

            metric.Start();
            metric.SetRawNanos(timespanNanos);
            metric.Stop();

            // If setRawNanos worked, (which it's not supposed to in this case), it would
            // have recorded 1000000000 ns == 1s.  Make sure it's not that.
            Assert.NotEqual <ulong>(1, metric.TestGetValue());
        }
Пример #9
0
        public void ValueUnchangedIfStoppedTwice()
        {
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Application,
                name: "timespan_metric",
                sendInPings: new string[] { "store1" },
                timeUnit: TimeUnit.Millisecond
                );

            // Record a timespan.
            metric.Start();
            metric.Stop();
            Assert.True(metric.TestHasValue());
            ulong value = metric.TestGetValue();

            metric.Stop();

            Assert.Equal(value, metric.TestGetValue());
        }
Пример #10
0
        public void RecordsAnErrorIfStartedTwice()
        {
            TimespanMetricType metric = new TimespanMetricType(
                category: "telemetry",
                disabled: false,
                lifetime: Lifetime.Application,
                name: "timespan_metric",
                sendInPings: new string[] { "store1", "store2" },
                timeUnit: TimeUnit.Millisecond
                );

            // Record a timespan.
            metric.Start();
            metric.Start();
            metric.Stop();

            // Check that data was properly recorded in the second ping.
            Assert.True(metric.TestHasValue("store2"));
            Assert.True(metric.TestGetValue("store2") >= 0);
            Assert.Equal(1, metric.TestGetNumRecordedErrors(ErrorType.InvalidState));
        }