public void MetricsAreEqualIfDimensionsSetToNothingImplicitlyAndExplicitlyAsEmptySet() { using (var manager = new MetricManagerV1()) { MetricV1 metric = manager.CreateMetric("My metric", new Dictionary <string, string>()); MetricV1 other = manager.CreateMetric("My metric"); Assert.IsTrue(metric.Equals(other)); } }
public void MetricsAreEqualForTheSameMetricNameWithoutDimensions() { using (var manager = new MetricManagerV1()) { MetricV1 metric = manager.CreateMetric("My metric"); MetricV1 other = manager.CreateMetric("My metric"); Assert.IsTrue(metric.Equals(other)); } }
public void MetricNameIsAccentSensitive() { using (var manager = new MetricManagerV1()) { MetricV1 metric = manager.CreateMetric("My metric"); MetricV1 other = manager.CreateMetric("My métric"); Assert.IsFalse(metric.Equals(other)); } }
public void CanCreateMetricWithASetOfDimensions() { // Arrange var sentTelemetry = new List <ITelemetry>(); var client = this.InitializeTelemetryClient(sentTelemetry); var dimensions = new Dictionary <string, string> { { "Dim1", "Value1" }, { "Dim2", "Value2" } }; using (MetricManagerV1 manager = new MetricManagerV1(client)) { // Act MetricV1 metric = manager.CreateMetric("Test Metric", dimensions); metric.Track(42); } // Assert var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single(); Assert.AreEqual("Test Metric", aggregatedMetric.Name); Assert.AreEqual(1, aggregatedMetric.Count); Assert.AreEqual(42, aggregatedMetric.Sum); // note: interval duration property is auto-generated Assert.AreEqual(3, aggregatedMetric.Properties.Count); Assert.AreEqual("Value1", aggregatedMetric.Properties["Dim1"]); Assert.AreEqual("Value2", aggregatedMetric.Properties["Dim2"]); }
public void CanCreateMetricExplicitlySettingDimensionsToNull() { // Arrange var sentTelemetry = new List <ITelemetry>(); var client = this.InitializeTelemetryClient(sentTelemetry); using (MetricManagerV1 manager = new MetricManagerV1(client)) { // Act MetricV1 metric = manager.CreateMetric("Test Metric", null); metric.Track(42); } // Assert var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single(); Assert.AreEqual("Test Metric", aggregatedMetric.Name); Assert.AreEqual(1, aggregatedMetric.Count); Assert.AreEqual(42, aggregatedMetric.Sum); // note: interval duration property is auto-generated Assert.AreEqual(1, aggregatedMetric.Properties.Count); }
public void AggregatedMetricTelemetryIntervalDurationPropertyIsPositiveInteger() { // Arrange var sentTelemetry = new List <ITelemetry>(); var client = this.InitializeTelemetryClient(sentTelemetry); using (MetricManagerV1 manager = new MetricManagerV1(client)) { MetricV1 metric = manager.CreateMetric("Test Metric"); // Act metric.Track(42); } // Assert var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single(); Assert.AreEqual("Test Metric", aggregatedMetric.Name); Assert.AreEqual(1, aggregatedMetric.Count); Assert.AreEqual(1, aggregatedMetric.Properties.Count); Assert.IsTrue(aggregatedMetric.Properties.ContainsKey("_MS.AggregationIntervalMs")); Assert.IsTrue(long.Parse(aggregatedMetric.Properties["_MS.AggregationIntervalMs"]) > 0); }
public void MetricAggregatorCalculatesSumCorrectly() { // Arrange double[] testValues = { 4.45, 8, 29.21, 78.43, 0 }; var sentTelemetry = new List <ITelemetry>(); var sentSamples = new List <MetricSample>(); var client = this.InitializeTelemetryClient(sentTelemetry, sentSamples); using (MetricManagerV1 manager = new MetricManagerV1(client)) { MetricV1 metric = manager.CreateMetric("Test Metric"); // Act for (int i = 0; i < testValues.Length; i++) { metric.Track(testValues[i]); } } // Assert double sentSampleSum = sentTelemetry.Sum( (telemetry) => { var metric = telemetry as MetricTelemetry; return(metric == null ? 0 : metric.Sum); }); Assert.AreEqual(testValues.Sum(), sentSampleSum); }
public void MetricInvokesMetricProcessorsForEachValueTracked() { // Arrange var sentTelemetry = new List <ITelemetry>(); var sentSamples = new List <MetricSample>(); var client = this.InitializeTelemetryClient(sentTelemetry, sentSamples); var dimensions = new Dictionary <string, string> { { "Dim1", "Value1" }, { "Dim2", "Value2" } }; using (MetricManagerV1 manager = new MetricManagerV1(client)) { MetricV1 metric = manager.CreateMetric("Test Metric", dimensions); // Act metric.Track(42); } // Assert var sample = (MetricSample)sentSamples.Single(); Assert.AreEqual("Test Metric", sample.Name); Assert.AreEqual(42, sample.Value); Assert.AreEqual("Value1", sample.Dimensions["Dim1"]); Assert.AreEqual("Value2", sample.Dimensions["Dim2"]); }
public void MetricEqualsItself() { using (var manager = new MetricManagerV1()) { MetricV1 metric = manager.CreateMetric("My metric"); Assert.IsTrue(metric.Equals(metric)); } }
public void EqualMetricsAreCombinedIntoSignleAggregatedStatsStructure() { // Arrange var sentTelemetry = new List <ITelemetry>(); var client = this.InitializeTelemetryClient(sentTelemetry); MetricV1 metric1 = null; MetricV1 metric2 = null; using (MetricManagerV1 manager = new MetricManagerV1(client)) { // note: on first go aggregators may be different because manager may // snapshot after first got created but before the second for (int i = 0; i < 2; i++) { metric1 = manager.CreateMetric("Test Metric"); metric2 = manager.CreateMetric("Test Metric"); // Act metric1.Track(10); metric2.Track(5); manager.Flush(); if (sentTelemetry.Count == 1) { break; } else { sentTelemetry.Clear(); } } } // Assert Assert.AreEqual(1, sentTelemetry.Count); var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single(); Assert.AreEqual(2, aggregatedMetric.Count); Assert.AreEqual(15, aggregatedMetric.Sum); }
public void DimensionValuesAreAccentSensitive() { using (var manager = new MetricManagerV1()) { var dimensionSet1 = new Dictionary <string, string>() { { "Dim1", "Value1" } }; var dimensionSet2 = new Dictionary <string, string>() { { "Dim1", "Válue1" } }; MetricV1 metric = manager.CreateMetric("My metric", dimensionSet1); MetricV1 other = manager.CreateMetric("My metric", dimensionSet2); Assert.IsFalse(metric.Equals(other)); } }
public void MetricNotEqualsOtherObject() { using (var manager = new MetricManagerV1()) { MetricV1 metric = manager.CreateMetric("My metric"); var other = new object(); Assert.IsFalse(metric.Equals(other)); } }
public void MetricNeverEqualsNull() { using (var manager = new MetricManagerV1()) { MetricV1 metric = manager.CreateMetric("My metric"); object other = null; Assert.IsFalse(metric.Equals(other)); } }
public void DimensionsAreOrderInsensitive() { using (var manager = new MetricManagerV1()) { var dimensionSet1 = new Dictionary <string, string>() { { "Dim1", "Value1" }, { "Dim2", "Value2" }, }; var dimensionSet2 = new Dictionary <string, string>() { { "Dim2", "Value2" }, { "Dim1", "Value1" }, }; MetricV1 metric = manager.CreateMetric("My metric", dimensionSet1); MetricV1 other = manager.CreateMetric("My metric", dimensionSet2); Assert.IsTrue(metric.Equals(other)); } }
public void MetricAggregatorCalculatesStandardDeviationCorrectly() { // Arrange double[] testValues = { 1, 2, 3, 4, 5 }; var sentTelemetry = new List <ITelemetry>(); var sentSamples = new List <MetricSample>(); var client = this.InitializeTelemetryClient(sentTelemetry, sentSamples); using (MetricManagerV1 manager = new MetricManagerV1(client)) { MetricV1 metric = manager.CreateMetric("Test Metric"); // Act for (int i = 0; i < testValues.Length; i++) { metric.Track(testValues[i]); } } // Assert double sumOfSquares = sentTelemetry.Sum( (telemetry) => { var metric = telemetry as MetricTelemetry; return (metric == null ? 0 : Math.Pow(metric.StandardDeviation.Value, 2) * metric.Count.Value + Math.Pow(metric.Sum, 2) / metric.Count.Value); }); int count = sentTelemetry.Sum( (telemetry) => { var metric = telemetry as MetricTelemetry; return(metric == null ? 0 : metric.Count.Value); }); double sum = sentTelemetry.Sum( (telemetry) => { var metric = telemetry as MetricTelemetry; return(metric == null ? 0 : metric.Sum); }); double stddev = Math.Sqrt(sumOfSquares / count - Math.Pow(sum / count, 2)); Assert.AreEqual(testValues.StdDev(), stddev); }
public void DisposingManagerCreatesAggregatedMetricTelemetry() { // Arrange var sentTelemetry = new List <ITelemetry>(); var client = this.InitializeTelemetryClient(sentTelemetry); using (MetricManagerV1 manager = new MetricManagerV1(client)) { MetricV1 metric = manager.CreateMetric("Test Metric"); metric.Track(42); // Act manager.Dispose(); // Assert Assert.AreEqual(1, sentTelemetry.Count); var aggregatedMetric = (MetricTelemetry)sentTelemetry.Single(); Assert.IsNotNull(aggregatedMetric); } }