public IEnumerator MetricsSubmission_ShouldTry3TimesOn502BeforeDroppingEvents_DataWasntSendToBacktrace()
        {
            const int expectedNumberOfEventsAfterFailure = 2;
            var       requestHandler = new BacktraceHttpClientMock()
            {
                StatusCode = 502
            };
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            backtraceMetrics.Send();
            for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++)
            {
                yield return(new WaitForSeconds(1));

                // immidiately run next update
                var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1;
                backtraceMetrics.Tick(time);
            }

            yield return(new WaitForSeconds(1));

            Assert.AreEqual(BacktraceMetrics.MaxNumberOfAttempts * 2, requestHandler.NumberOfRequests);
            Assert.AreEqual(backtraceMetrics.Count(), expectedNumberOfEventsAfterFailure);
        }
        public IEnumerator MetricsSubmission_ShouldTry3TimesOn503AndDropSummedEventsOnMaximumNumberOfEvents_DataWasDeleted()
        {
            const int expectedNumberOfEventsAfterFailure = 1; // unique events and we have enough place for session event so also session event
            var       requestHandler = new BacktraceHttpClientMock()
            {
                StatusCode = 503
            };
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.OverrideHttpClient(requestHandler);
            for (int i = 0; i < backtraceMetrics.MaximumSummedEvents; i++)
            {
                backtraceMetrics.AddSummedEvent(MetricsEventName);
            }
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);

            backtraceMetrics.Send();
            for (int i = 0; i < BacktraceMetrics.MaxNumberOfAttempts; i++)
            {
                yield return(new WaitForSeconds(1));

                // immidiately run next update
                var time = BacktraceMetrics.MaxTimeBetweenRequests + (BacktraceMetrics.MaxTimeBetweenRequests * i) + i + 1;
                backtraceMetrics.Tick(time);
            }

            yield return(new WaitForSeconds(1));

            Assert.AreEqual(expectedNumberOfEventsAfterFailure, backtraceMetrics.Count());
            Assert.AreEqual(BacktraceMetrics.MaxNumberOfAttempts * 2, requestHandler.NumberOfRequests);
        }
Exemplo n.º 3
0
        public void BacktraceMetricsUniqueEvents_ShoulOverrideDefaultSubmissionUrl_SendEventToValidUrl()
        {
            var expectedSubmissionUrl = $"{_defaultSubmissionUrl}/unique-events/unit-test/submit?token={_token}&universe={_universeName}";
            var jsonString            = string.Empty;
            var submissionUrl         = string.Empty;
            var requestHandler        = new BacktraceHttpClientMock()
            {
                OnInvoke = (string url, BacktraceJObject json) =>
                {
                    jsonString    = json.ToJson();
                    submissionUrl = url;
                }
            };
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl)
            {
                UniqueEventsSubmissionUrl = expectedSubmissionUrl
            };

            backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            backtraceMetrics.Send();

            Assert.IsNotEmpty(jsonString);
            Assert.AreEqual(expectedSubmissionUrl, submissionUrl);
            Assert.IsEmpty(backtraceMetrics.SummedEvents);
        }
Exemplo n.º 4
0
        public void BacktraceMetricsUniqueEvents_ShouldntAddNullableUniqueEvent_UniqueEventsAreEmpty()
        {
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.AddUniqueEvent(null);

            Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 0);
        }
Exemplo n.º 5
0
        public void BacktraceMetricsUniqueEvents_ShouldntAddEmptyUniqueEvent_UniqueEventsAreEmpty()
        {
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            var added = backtraceMetrics.AddUniqueEvent(string.Empty);

            Assert.IsFalse(added);
            Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 0);
        }
Exemplo n.º 6
0
        public void BacktraceMetricsUniqueEvents_ShouldPreventFromAddingEventIfThereIsNoAttribute_StoreValidUniqueEvent()
        {
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            var added = backtraceMetrics.AddUniqueEvent($"{UniqueAttributeName}-not-existing");

            Assert.IsFalse(added);
            Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 0);
        }
        public void BacktraceMetrics_ShouldntTriggerDownloadAfterTimeIntervalFirstHit_DataWasSendToBacktrace()
        {
            const int timeInterval     = 10;
            var       requestHandler   = new BacktraceHttpClientMock();
            var       backtraceMetrics = new BacktraceMetrics(_attributeProvider, timeInterval, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);

            backtraceMetrics.Tick(timeInterval + 1);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);

            backtraceMetrics.Tick(timeInterval + 2);

            Assert.AreEqual(2, requestHandler.NumberOfRequests);
            Assert.AreEqual(2, backtraceMetrics.Count());
        }
Exemplo n.º 8
0
        public void BacktraceMetricsUniqueEvents_ShouldAddEventIfAttributeIsDefinedInCustomAttributes_StoreValidUniqueEvents()
        {
            var expectedAttributeName = "foo";
            var backtraceMetrics      = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            var added = backtraceMetrics.AddUniqueEvent(expectedAttributeName, new Dictionary <string, string>()
            {
                { expectedAttributeName, expectedAttributeName }
            });

            Assert.IsTrue(added);
            Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 1);
        }
Exemplo n.º 9
0
        public void BacktraceMetricsUniqueEvents_ShouldAddCorrectlyUniqueEventWithoutAttributes_StoreValidUniqueEvent()
        {
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);

            Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 1);
            var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value;

            Assert.AreEqual(uniqueEvent.Name, UniqueAttributeName);
            Assert.AreNotEqual(uniqueEvent.Timestamp, 0);
            Assert.AreEqual(uniqueEvent.Attributes.Count, _attributeProvider.GenerateAttributes().Count);
        }
        public void BacktraceMetrics_ShouldTriggerUploadAfterTimeIntervalHitAgain_DataWasSendToBacktrace()
        {
            const int timeInterval     = 10;
            var       requestHandler   = new BacktraceHttpClientMock();
            var       backtraceMetrics = new BacktraceMetrics(_attributeProvider, timeInterval, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);

            backtraceMetrics.Tick(timeInterval + 1);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);

            backtraceMetrics.Tick((timeInterval * 2) + 1);

            // we added two unique events - but because we added two the same reports
            // they should be combined
            Assert.AreEqual(1, backtraceMetrics.Count());
            Assert.AreEqual(4, requestHandler.NumberOfRequests);
        }
        public void BacktraceMetrics_ShouldTryOnlyOnceOnHttpFailure_DataWasntSendToBacktrace()
        {
            var requestHandler = new BacktraceHttpClientMock()
            {
                IsHttpError = true
            };
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl); backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            backtraceMetrics.Send();

            Assert.AreEqual(2, requestHandler.NumberOfRequests);
        }
Exemplo n.º 12
0
        public void BacktraceMetricsUniqueEvents_UniqueEventAttributeExistsAfterDeletingItFromAttributeProvider_UniqueEventAttributesStayTheSame()
        {
            const string initializationValue = "foo";

            _attributeProvider[UniqueAttributeName] = initializationValue;
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            _attributeProvider[UniqueAttributeName] = string.Empty;

            var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value;

            Assert.AreEqual(initializationValue, uniqueEvent.Attributes[UniqueAttributeName]);
        }
Exemplo n.º 13
0
        public void BacktraceMetricsUniqueEvents_UniqueEventAttributeValueDontChangeOverTime_UniqueEventAttributesStayTheSame()
        {
            const string initializationValue = "foo";
            const string updatedValue        = "bar";

            _attributeProvider[UniqueAttributeName] = initializationValue;
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            _attributeProvider[UniqueAttributeName] = updatedValue;

            var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value;

            Assert.AreEqual(initializationValue, uniqueEvent.Attributes[UniqueAttributeName]);
        }
        public void BacktraceMetrics_ShouldTriggerUploadAfterTimeIntervalHit_DataWasSendToBacktrace()
        {
            const int timeInterval             = 10;
            const int expectedNumberOfEvents   = 1; // we send successfully session event so we have one unique event
            const int expectedNumberOfRequests = 2;
            var       requestHandler           = new BacktraceHttpClientMock();
            var       backtraceMetrics         = new BacktraceMetrics(_attributeProvider, timeInterval, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddSummedEvent(MetricsEventName);
            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            backtraceMetrics.Tick(timeInterval + 1);


            Assert.AreEqual(expectedNumberOfEvents, backtraceMetrics.Count());
            Assert.AreEqual(expectedNumberOfRequests, requestHandler.NumberOfRequests);
        }
        public void BacktraceMetrics_ShouldSkipMoreUniqueEventsWhenHitTheLimit_DataWasntSendToBacktrace()
        {
            const int maximumNumberOfEvents = 3;
            const int numberOfTestEvents    = 10;
            var       backtraceMetrics      = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl)
            {
                MaximumUniqueEvents = maximumNumberOfEvents
            };

            for (int i = 0; i < numberOfTestEvents; i++)
            {
                backtraceMetrics.AddUniqueEvent(string.Format("{0} {1}", UniqueAttributeName, i), new Dictionary <string, string>()
                {
                    { string.Format("{0} {1}", UniqueAttributeName, i), "value" }
                });
            }

            Assert.AreEqual(maximumNumberOfEvents, backtraceMetrics.Count());
        }
Exemplo n.º 16
0
        public void BacktraceMetricsUniqueEvents_ShouldAddCorrectlyUniqueEventWithAttributes_StoreValidUniqueEvent()
        {
            const string expectedAttributeName  = "foo";
            const string expectedAttributeValue = "bar";
            var          attributes             = new Dictionary <string, string>()
            {
                { expectedAttributeName, expectedAttributeValue }
            };
            int expectedNumberOfAttributes = _attributeProvider.GenerateAttributes().Count + attributes.Count;

            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.AddUniqueEvent(UniqueAttributeName, attributes);

            Assert.AreEqual(backtraceMetrics.UniqueEvents.Count, 1);
            var uniqueEvent = backtraceMetrics.UniqueEvents.First.Value;

            Assert.AreEqual(uniqueEvent.Name, UniqueAttributeName);
            Assert.AreNotEqual(uniqueEvent.Timestamp, 0);
            Assert.AreEqual(uniqueEvent.Attributes.Count, expectedNumberOfAttributes);
        }
        public void BacktraceMetrics_ShouldTriggerUploadProcessOnSendMethodWithOnlyUniqueEvent_DataWasSendToTheService()
        {
            var jsonString     = string.Empty;
            var submissionUrl  = string.Empty;
            var requestHandler = new BacktraceHttpClientMock()
            {
                OnInvoke = (string url, BacktraceJObject json) =>
                {
                    jsonString    = json.ToJson();
                    submissionUrl = url;
                }
            };
            var backtraceMetrics = new BacktraceMetrics(_attributeProvider, 0, _defaultUniqueEventsSubmissionUrl, _defaultSummedEventsSubmissionUrl);

            backtraceMetrics.OverrideHttpClient(requestHandler);

            backtraceMetrics.AddUniqueEvent(UniqueAttributeName);
            backtraceMetrics.Send();

            Assert.IsNotEmpty(jsonString);
            Assert.AreEqual(submissionUrl, _expectedUniqueEventsSubmissionUrl);
            Assert.IsEmpty(backtraceMetrics.SummedEvents);
        }