public void TestAggregatingMetricsSucceeds() { var component = new ComponentData("TestName", "com.newrelic.test"); var metric1 = new MetricData("Test/Metric", "units", 2); var metric2 = new MetricData("Test/Metric", "units", 3); var metric3 = new MetricData("Test/Metric", "units", 4); var metric4 = new MetricData("Test/Metric", "otherunits", 5); Assert.AreEqual(0, TestSerializationHelper.GetMetricsMapFromComponent(component).Count, "Should be zero metrics"); component.AddMetric(metric1); component.AddMetric(metric2); component.AddMetric(metric3); component.AddMetric(metric4); var serializedComponent = component.Serialize(DateTime.Now.Subtract(TimeSpan.FromSeconds(60))); var metrics = TestSerializationHelper.GetMetricsMapFromComponent(component); Assert.AreEqual(2, metrics.Count, "Should be two metrics"); Assert.AreEqual(9, TestSerializationHelper.GetValueFromMetricMap(metrics, metric1.FullName, MetricValues.Value)); Assert.AreEqual(3, TestSerializationHelper.GetValueFromMetricMap(metrics, metric1.FullName, MetricValues.Count)); Assert.AreEqual(2, TestSerializationHelper.GetValueFromMetricMap(metrics, metric1.FullName, MetricValues.MinValue)); Assert.AreEqual(4, TestSerializationHelper.GetValueFromMetricMap(metrics, metric1.FullName, MetricValues.MaxValue)); Assert.AreEqual(29, TestSerializationHelper.GetValueFromMetricMap(metrics, metric1.FullName, MetricValues.SumOfSquares)); Assert.AreEqual(5, TestSerializationHelper.GetValueFromMetricMap(metrics, metric4.FullName, MetricValues.Value)); Assert.AreEqual(1, TestSerializationHelper.GetValueFromMetricMap(metrics, metric4.FullName, MetricValues.Count)); Assert.AreEqual(5, TestSerializationHelper.GetValueFromMetricMap(metrics, metric4.FullName, MetricValues.MinValue)); Assert.AreEqual(5, TestSerializationHelper.GetValueFromMetricMap(metrics, metric4.FullName, MetricValues.MaxValue)); Assert.AreEqual(25, TestSerializationHelper.GetValueFromMetricMap(metrics, metric4.FullName, MetricValues.SumOfSquares)); }
public void TestMultipleComponentsSucceeds() { var requestData = new RequestData(); Assert.AreEqual(0, TestSerializationHelper.GetComponentsListFromRequestData(requestData).Count); requestData.AddMetric("com.newrelic.test", "TestComponent1", "Test/Metric", "unit", 2); requestData.AddMetric("com.newrelic.test", "TestComponent2", "Test/Metric", "unit", 3); requestData.AddMetric("com.newrelic.test", "TestComponent3", "Test/Metric", "unit", 4); var componentsList = TestSerializationHelper.GetComponentsListFromRequestData(requestData); Assert.AreEqual(3, componentsList.Count); var component1 = TestSerializationHelper.GetComponentMapFromComponentsList(componentsList, "TestComponent1"); var component2 = TestSerializationHelper.GetComponentMapFromComponentsList(componentsList, "TestComponent2"); var component3 = TestSerializationHelper.GetComponentMapFromComponentsList(componentsList, "TestComponent3"); var metrics1 = TestSerializationHelper.GetMetricsMapFromComponentMap(component1); var metrics2 = TestSerializationHelper.GetMetricsMapFromComponentMap(component2); var metrics3 = TestSerializationHelper.GetMetricsMapFromComponentMap(component3); Assert.AreEqual(1, metrics1.Count); Assert.AreEqual(1, metrics2.Count); Assert.AreEqual(1, metrics3.Count); }
public void TestResetComponentsSucceeds() { var requestData = new RequestData(); requestData.AddMetric("com.newrelic.test", "TestComponent1", "Test/Metric", "unit", 2); requestData.AddMetric("com.newrelic.test", "TestComponent2", "Test/Metric", "unit", 3); requestData.AddMetric("com.newrelic.test", "TestComponent3", "Test/Metric", "unit", 4); var beforeResetList = TestSerializationHelper.GetComponentsListFromRequestData(requestData); Assert.AreEqual(3, beforeResetList.Count); requestData.Reset(); var firstAfterResetList = TestSerializationHelper.GetComponentsListFromRequestData(requestData); Assert.AreEqual(0, firstAfterResetList.Count); requestData.AddMetric("com.newrelic.test", "TestComponent1", "Test/Metric", "unit", 2); requestData.AddMetric("com.newrelic.test", "TestComponent2", "Test/Metric", "unit", 3); requestData.AddMetric("com.newrelic.test", "TestComponent3", "Test/Metric", "unit", 4); var secondAfterResetList = TestSerializationHelper.GetComponentsListFromRequestData(requestData); Assert.AreEqual(3, secondAfterResetList.Count); }
private void AssertMetricValues(IDictionary <string, object> metrics, string metricName, float value, int count, float min, float max, float sumOfSquares) { Assert.AreEqual(value, TestSerializationHelper.GetValueFromMetricMap(metrics, metricName, MetricValues.Value)); Assert.AreEqual(count, TestSerializationHelper.GetValueFromMetricMap(metrics, metricName, MetricValues.Count)); Assert.AreEqual(min, TestSerializationHelper.GetValueFromMetricMap(metrics, metricName, MetricValues.MinValue)); Assert.AreEqual(max, TestSerializationHelper.GetValueFromMetricMap(metrics, metricName, MetricValues.MaxValue)); Assert.AreEqual(sumOfSquares, TestSerializationHelper.GetValueFromMetricMap(metrics, metricName, MetricValues.SumOfSquares)); }
public void TestDifferentGuidDoesntAggregate() { var requestData = new RequestData(); requestData.AddMetric("com.newrelic.test", "TestComponent", "Test/Metric", "unit", 2); requestData.AddMetric("com.newrelic.anothertest", "TestComponent", "Test/Metric", "unit", 2); var componentsList = TestSerializationHelper.GetComponentsListFromRequestData(requestData); Assert.AreEqual(2, componentsList.Count); }
public void TestAddSingleMetricSucceeds() { var component = new ComponentData("TestName", "com.newrelic.test"); var metric = new MetricData("Test/Metric", "units", 3); Assert.AreEqual("TestName", component.Name); Assert.AreEqual("com.newrelic.test", component.Guid); Assert.AreEqual(0, TestSerializationHelper.GetMetricsMapFromComponent(component).Count, "Should be zero metrics"); component.AddMetric(metric); var serializedComponent = component.Serialize(DateTime.Now.Subtract(TimeSpan.FromSeconds(60))); var metrics = TestSerializationHelper.GetMetricsMapFromComponent(component); Assert.AreEqual(1, metrics.Count, "Should be one metric"); Assert.IsTrue(metrics.Keys.Any(key => key == metric.FullName), "Metric name should be a valid key"); Assert.AreEqual(3, TestSerializationHelper.GetValueFromMetricMap(metrics, metric.FullName, MetricValues.Value)); }
public void TestAggregateMetricsSucceeds() { var requestData = new RequestData(); Assert.AreEqual(0, TestSerializationHelper.GetComponentsListFromRequestData(requestData).Count); requestData.AddMetric("com.newrelic.test", "TestComponent", "Test/Metric", "unit", 2); requestData.AddMetric("com.newrelic.test", "TestComponent", "Test/Metric", "unit", 3); requestData.AddMetric("com.newrelic.test", "TestComponent", "Test/Metric", "unit", 4); var componentsList = TestSerializationHelper.GetComponentsListFromRequestData(requestData); Assert.AreEqual(1, componentsList.Count); var component = TestSerializationHelper.GetComponentMapFromComponentsList(componentsList, "TestComponent"); var metrics = TestSerializationHelper.GetMetricsMapFromComponentMap(component); Assert.AreEqual(1, metrics.Count); AssertMetricValues(metrics, "Component/Test/Metric[unit]", 9, 3, 2, 4, 29); }
public void TestAddMultipleMetricsSucceeds() { var component = new ComponentData("TestName", "com.newrelic.test"); var metric1 = new MetricData("Test/Metric1", "units", 2); var metric2 = new MetricData("Test/Metric2", "units", 3); var metric3 = new MetricData("Test/Metric3", "units", 4); Assert.AreEqual(0, TestSerializationHelper.GetMetricsMapFromComponent(component).Count, "Should be zero metrics"); component.AddMetric(metric1); component.AddMetric(metric2); component.AddMetric(metric3); var serializedComponent = component.Serialize(DateTime.Now.Subtract(TimeSpan.FromSeconds(60))); var metrics = TestSerializationHelper.GetMetricsMapFromComponent(component); Assert.AreEqual(3, metrics.Count, "Should be three metrics"); Assert.AreEqual(2, TestSerializationHelper.GetValueFromMetricMap(metrics, metric1.FullName, MetricValues.Value)); Assert.AreEqual(3, TestSerializationHelper.GetValueFromMetricMap(metrics, metric2.FullName, MetricValues.Value)); Assert.AreEqual(4, TestSerializationHelper.GetValueFromMetricMap(metrics, metric3.FullName, MetricValues.Value)); }