public void TestAggregateWithMultipleComponentsSucceeds()
        {
            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", "TestComponent1", "Test/Metric", "unit", 2);

            requestData.AddMetric("com.newrelic.test", "TestComponent2", "Test/Metric", "unit", 3);
            requestData.AddMetric("com.newrelic.test", "TestComponent2", "Test/Metric", "unit", 3);

            requestData.AddMetric("com.newrelic.test", "TestComponent3", "Test/Metric", "unit", 4);
            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);

            AssertMetricValues(metrics2, "Component/Test/Metric[unit]", 6, 2, 3, 3, 18);
        }
示例#2
0
        /// <summary>
        /// This class is responsible for maintaining metrics that have been reported as well as sending them to the New Relic 
        /// service. Any Components that share a Request reference will have their data sent to the service in one request.
        /// </summary>
        /// <param name="licenseKey">The New Relic license key.</param>
        /// <param name="config">The configuration that should be used.</param>
        public Context(string licenseKey, INewRelicConfig config = null)
        {
            this._newRelicConfig = config ?? NewRelicConfig.Instance;

            this._licenseKey = licenseKey;
            this._requestData = new RequestData();

            s_log.Debug("Using service URL: {0}", this.ServiceUri);
            s_log.Debug("Using license key: {0}", this.LicenseKey);
        }
        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);
        }
 internal static List<object> GetComponentsListFromRequestData(RequestData requestData)
 {
     return (List<object>)requestData.Serialize()["components"];
 }
        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);
        }
        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 TestAggregationLimitIsRespected()
        {
            var requestData = new RequestData();
            requestData.SetAggregationLimit(DateTime.Now.AddMinutes(-20));

            Assert.IsTrue(requestData.IsPastAggregationLimit(), "Aggregation limit is not being respected");
        }
示例#8
0
 public MockContext()
 {
     this.RequestData = new RequestData();
 }