public void Verify_setting_priority()
            {
                var attribValues = new AttributeValueCollection(AttributeDestinations.TransactionEvent);

                _attribDefs.Timestamp.TrySetValue(attribValues, DateTime.UtcNow);

                float priority        = 0.5f;
                var   emptyDictionary = new Dictionary <string, object>();
                var   object1         = new TransactionEventWireModel(attribValues, false, priority);

                Assert.That(priority == object1.Priority);

                priority         = 0.0f;
                object1.Priority = priority;
                Assert.That(priority == object1.Priority);

                priority         = 1.0f;
                object1.Priority = priority;
                Assert.That(priority == object1.Priority);

                priority         = 1.1f;
                object1.Priority = priority;
                Assert.That(priority == object1.Priority);

                priority = -0.00001f;
                Assert.Throws <ArgumentException>(() => object1.Priority = priority);
                priority = float.NaN;
                Assert.Throws <ArgumentException>(() => object1.Priority = priority);
                priority = float.NegativeInfinity;
                Assert.Throws <ArgumentException>(() => object1.Priority = priority);
                priority = float.PositiveInfinity;
                Assert.Throws <ArgumentException>(() => object1.Priority = priority);
                priority = float.MinValue;
                Assert.Throws <ArgumentException>(() => object1.Priority = priority);
            }
        public void LazyValueTest_TransactionEvents()
        {
            var attribValues = new AttributeValueCollection(AttributeValueCollection.AllTargetModelTypes);

            LazyValueTest_SetAttribValues(attribValues);

            var wireModel = new TransactionEventWireModel(attribValues, false, .5f);

            LazyValueTest_Assertions(wireModel.AttributeValues);
        }
            public void all_fields_serializes_correctly()
            {
                var attribValues = new AttributeValueCollection(AttributeDestinations.TransactionEvent);

                // ARRANGE
                var userAttributes = new Dictionary <string, object>
                {
                    { "identity.user", "user" },
                    { "identity.product", "product" },
                };

                _attribDefs.GetCustomAttributeForTransaction("identity.user").TrySetValue(attribValues, "user");
                _attribDefs.GetCustomAttributeForTransaction("identity.product").TrySetValue(attribValues, "product");

                var agentAttributes = new Dictionary <string, object>
                {
                    { "request.uri", "www.test.com" },
                };

                _attribDefs.RequestUri.TrySetValue(attribValues, "www.test.com");

                var intrinsicAttributes = new Dictionary <string, object>
                {
                    { "nr.tripId", "1234ABCD1234ABCD" },
                    { "nr.pathHash", "DCBA4321" },
                    { "nr.referringPathHash", "1234ABCD" },
                    { "nr.referringTransactionGuid", "DCBA43211234ABCD" },
                    { "nr.alternatePathHashes", "55f97a7f,6fc8d18f,72827114,9a3ed934,a1744603,a7d2798f,be1039f5,ccadfd2c,da7edf2e,eaca716b" },
                };

                _attribDefs.CatNrTripId.TrySetValue(attribValues, "1234ABCD1234ABCD");
                _attribDefs.CatNrPathHash.TrySetValue(attribValues, "DCBA4321");
                _attribDefs.CatReferringPathHash.TrySetValue(attribValues, "1234ABCD");
                _attribDefs.CatReferringTransactionGuidForEvents.TrySetValue(attribValues, "DCBA43211234ABCD");
                _attribDefs.CatAlternativePathHashes.TrySetValue(attribValues, new[] { "55f97a7f", "6fc8d18f", "72827114", "9a3ed934", "a1744603", "a7d2798f", "be1039f5", "ccadfd2c", "da7edf2e", "eaca716b" });

                var isSytheticsEvent = false;

                var expectedDictionaries = new Dictionary <string, object>[]
                {
                    intrinsicAttributes,
                    userAttributes,
                    agentAttributes
                };

                // ACT
                float priority = 0.5f;
                var   transactionEventWireModel = new TransactionEventWireModel(attribValues, isSytheticsEvent, priority);
                var   actualResult = JsonConvert.SerializeObject(transactionEventWireModel);
                var   deserialized = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(actualResult);

                // ASSERT
                AttributeComparer.CompareDictionaries(expectedDictionaries, deserialized);
            }
Example #4
0
        public static IDictionary <string, object> GetAttributes(this TransactionEventWireModel transactionEvent, AttributeClassification attributeClassification)
        {
            switch (attributeClassification)
            {
            case AttributeClassification.Intrinsics:
                return(transactionEvent.IntrinsicAttributes());

            case AttributeClassification.AgentAttributes:
                return(transactionEvent.AgentAttributes());

            case AttributeClassification.UserAttributes:
                return(transactionEvent.UserAttributes());

            default:
                throw new NotImplementedException();
            }
        }
Example #5
0
        public void Collections_are_reset_on_configuration_update_event()
        {
            // Arrange
            var configuration = GetDefaultConfiguration(int.MaxValue);
            var sentEvents    = null as IEnumerable <TransactionEventWireModel>;

            Mock.Arrange(() => _dataTransportService.Send(Arg.IsAny <EventHarvestData>(), Arg.IsAny <IEnumerable <TransactionEventWireModel> >()))
            .DoInstead <IEnumerable <TransactionEventWireModel> >(events => sentEvents = events);
            var transactionEventWireModel = new TransactionEventWireModel(_attribValues, false, 0.3f);

            _transactionEventAggregator.Collect(transactionEventWireModel);

            // Act
            EventBus <ConfigurationUpdatedEvent> .Publish(new ConfigurationUpdatedEvent(configuration, ConfigurationUpdateSource.Local));

            _harvestAction();

            // Assert
            Assert.Null(sentEvents);
        }
            public void only_required_fields_serialize_correctly()
            {
                // Arrange
                var attribValues = new AttributeValueCollection(AttributeDestinations.ErrorEvent);

                var isSytheticsEvent = false;

                var expectedDictionaries = new IDictionary <string, object>[]
                {
                    new Dictionary <string, object>(),
                    new Dictionary <string, object>(),
                    new Dictionary <string, object>()
                };

                // Act
                float priority = 0.5f;
                var   transactionEventWireModel = new TransactionEventWireModel(attribValues, isSytheticsEvent, priority);
                var   actualResult = JsonConvert.SerializeObject(transactionEventWireModel);
                var   deserialized = JsonConvert.DeserializeObject <Dictionary <string, object>[]>(actualResult);

                // Assert
                AttributeComparer.CompareDictionaries(expectedDictionaries, deserialized);
            }
Example #7
0
        public void Zero_events_are_retained_after_harvest_if_response_equals_post_too_big_error_with_only_one_event_in_post()
        {
            // Arrange
            IEnumerable <TransactionEventWireModel> sentEvents = null;

            Mock.Arrange(() => _dataTransportService.Send(Arg.IsAny <EventHarvestData>(), Arg.IsAny <IEnumerable <TransactionEventWireModel> >()))
            .Returns <EventHarvestData, IEnumerable <TransactionEventWireModel> >((_, events) =>
            {
                sentEvents = events;
                return(DataTransportResponseStatus.ReduceSizeIfPossibleOtherwiseDiscard);
            });
            var transactionEventWireModel = new TransactionEventWireModel(_attribValues, false, 0.3f);

            _transactionEventAggregator.Collect(transactionEventWireModel);
            _harvestAction();
            sentEvents = null; // reset

            // Act
            _harvestAction();

            // Assert
            Assert.Null(sentEvents);
            Mock.Assert(() => _agentHealthReporter.ReportTransactionEventsRecollected(1));
        }
Example #8
0
        public static void DoesNotHaveAttributes(IEnumerable <string> unexpectedAttributes, AttributeClassification attributeClassification, TransactionEventWireModel transactionEvent)
        {
            var errorMessageBuilder   = new StringBuilder();
            var actualAttributes      = transactionEvent.GetAttributes(attributeClassification);
            var allAttributesNotFound = ExpectedAttribute.CheckIfAllAttributesNotFound(actualAttributes, unexpectedAttributes, errorMessageBuilder);

            Assert.True(allAttributesNotFound, errorMessageBuilder.ToString());
        }
Example #9
0
        public static void HasAttributes(IEnumerable <ExpectedAttribute> expectedAttributes, AttributeClassification attributeClassification, TransactionEventWireModel transactionEvent)
        {
            var errorMessageBuilder = new StringBuilder();
            var actualAttributes    = transactionEvent.GetAttributes(attributeClassification);
            var allAttributesMatch  = ExpectedAttribute.CheckIfAllAttributesMatch(actualAttributes, expectedAttributes, errorMessageBuilder);

            Assert.True(allAttributesMatch, errorMessageBuilder.ToString());
        }