Esempio n. 1
0
        public void GetTopicName_caches()
        {
            var called = 0;

            string Generator(Type eventType, string prefix)
            {
                called++;
                return($"{prefix}{eventType.Name}");
            }

            var settings = new SettingsHolder();

            settings.Set(SettingsKeys.TopicNamePrefix, "PREFIX");
            settings.Set(SettingsKeys.TopicNameGenerator, (Func <Type, string, string>)Generator);

            var configuration = new TransportConfiguration(settings);

            var metadataRegistry = settings.SetupMessageMetadataRegistry();
            var metadata         = metadataRegistry.GetMessageMetadata(typeof(Event));

            var cache = new TopicCache(null, metadataRegistry, configuration);

            cache.GetTopicName(metadata);
            cache.GetTopicName(metadata);

            Assert.AreEqual(1, called);
        }
Esempio n. 2
0
        public async Task GetTopicArn_caches()
        {
            var settings = new SettingsHolder();

            settings.Set(SettingsKeys.TopicNamePrefix, "PREFIX");
            settings.Set(SettingsKeys.TopicNameGenerator, (Func <Type, string, string>)TopicNameGenerator);

            var configuration = new TransportConfiguration(settings);
            var snsClient     = new MockSnsClient();

            var metadataRegistry = settings.SetupMessageMetadataRegistry();

            var cache = new TopicCache(snsClient, metadataRegistry, configuration);

            await cache.GetTopicArn(typeof(Event));

            var requestsSent = new List <string>(snsClient.FindTopicRequests);

            snsClient.FindTopicRequests.Clear();

            await cache.GetTopicArn(typeof(Event));

            Assert.IsEmpty(snsClient.FindTopicRequests);
            CollectionAssert.AreEqual(new List <string> {
                "PREFIXEvent"
            }, requestsSent);
        }
    public TransportConfigurationResult Configure(SettingsHolder settings, TransportTransactionMode transactionMode)
    {
        var sqsTransport = new SqsTransport();
        var sqsConfig    = new TransportExtensions <SqsTransport>(settings);

        sqsConfig.ConfigureSqsTransport(SetupFixture.NamePrefix);

        settings.SetupMessageMetadataRegistry();

        return(new TransportConfigurationResult
        {
            TransportInfrastructure = sqsTransport.Initialize(settings, ""),
            PurgeInputQueueOnStartup = false
        });
    }
        public void SetUp()
        {
            sqsClient = new MockSqsClient();
            snsClient = new MockSnsClient();
            sqsClient.EnableGetAttributeReturnsWhatWasSet();
            settings = new SettingsHolder();

            customEventToTopicsMappings = new EventToTopicsMappings();
            settings.Set(customEventToTopicsMappings);

            customEventToEventsMappings = new EventToEventsMappings();
            settings.Set(customEventToEventsMappings);

            messageMetadataRegistry = settings.SetupMessageMetadataRegistry();
            queueName = "fakeQueue";

            manager = CreateNonBatchingSubscriptionManager();
        }
Esempio n. 5
0
        public async Task Should_upload_large_multicast_operations_request_to_s3()
        {
            var settings            = new SettingsHolder();
            var transportExtensions = new TransportExtensions <SqsTransport>(settings);

            transportExtensions.S3("someBucket", "somePrefix");

            var mockS3Client  = new MockS3Client();
            var mockSnsClient = new MockSnsClient();

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, mockS3Client, null, mockSnsClient, new QueueCache(null, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes(new string('x', 256 * 1024))),
                    new MulticastAddressTag(typeof(Event)),
                    DispatchConsistency.Isolated),
                new TransportOperation( /* Crazy long message id will cause the message to go over limits because attributes count as well */
                    new OutgoingMessage(new string('x', 256 * 1024), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(AnotherEvent)),
                    DispatchConsistency.Isolated));

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.AreEqual(2, mockSnsClient.PublishedEvents.Count);
            Assert.AreEqual(2, mockS3Client.PutObjectRequestsSent.Count);

            var firstUpload  = mockS3Client.PutObjectRequestsSent.ElementAt(0);
            var secondUpload = mockS3Client.PutObjectRequestsSent.ElementAt(1);

            Assert.AreEqual("someBucket", firstUpload.BucketName);
            Assert.AreEqual("someBucket", secondUpload.BucketName);
            StringAssert.Contains($@"""Body"":"""",""S3BodyKey"":""{firstUpload.Key}", mockSnsClient.PublishedEvents.ElementAt(0).Message);
            StringAssert.Contains($@"""Body"":"""",""S3BodyKey"":""{secondUpload.Key}", mockSnsClient.PublishedEvents.ElementAt(1).Message);
        }
Esempio n. 6
0
        public async Task Should_not_dispatch_multicast_operation_if_event_type_is_object()
        {
            var settings = new SettingsHolder();

            var mockSnsClient = new MockSnsClient();

            //given that a subscriber never sets up a topic for object this has to return null
            mockSnsClient.FindTopicAsyncResponse = topic => null;

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, null, null, mockSnsClient, new QueueCache(null, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(object)))
                );

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.IsEmpty(mockSnsClient.PublishedEvents);
        }
Esempio n. 7
0
        public async Task Should_not_deduplicate_if_compatibility_mode_is_enabled_and_no_subscription_found()
        {
            var settings = new SettingsHolder();

            var mockSnsClient = new MockSnsClient();
            var mockSqsClient = new MockSqsClient();

            var transportConfiguration = new TransportConfiguration(settings);
            var dispatcher             = new MessageDispatcher(transportConfiguration, null, mockSqsClient, mockSnsClient, new QueueCache(mockSqsClient, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var messageId = Guid.NewGuid().ToString();
            var headers   = new Dictionary <string, string>()
            {
                { Headers.EnclosedMessageTypes, typeof(Event).AssemblyQualifiedName }
            };
            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(messageId, headers, Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(Event))),
                new TransportOperation(
                    new OutgoingMessage(messageId, headers, Encoding.Default.GetBytes("{}")),
                    new UnicastAddressTag("abc"))
                );

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.AreEqual(1, mockSnsClient.PublishedEvents.Count);
            Assert.AreEqual(1, mockSqsClient.BatchRequestsSent.Count);
        }
Esempio n. 8
0
        public async Task Should_dispatch_multicast_operations()
        {
            var settings = new SettingsHolder();

            var mockSnsClient = new MockSnsClient();

            var transportConfiguration = new TransportConfiguration(settings);

            var dispatcher = new MessageDispatcher(transportConfiguration, null, null, mockSnsClient, new QueueCache(null, transportConfiguration), new TopicCache(mockSnsClient, settings.SetupMessageMetadataRegistry(), transportConfiguration));

            var transportOperations = new TransportOperations(
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(Event))),
                new TransportOperation(
                    new OutgoingMessage(Guid.NewGuid().ToString(), new Dictionary <string, string>(), Encoding.Default.GetBytes("{}")),
                    new MulticastAddressTag(typeof(AnotherEvent)))
                );

            var transportTransaction = new TransportTransaction();
            var context = new ContextBag();

            await dispatcher.Dispatch(transportOperations, transportTransaction, context);

            Assert.AreEqual(2, mockSnsClient.PublishedEvents.Count);
            Assert.AreEqual("arn:aws:sns:us-west-2:123456789012:NServiceBus-Transport-SQS-Tests-MessageDispatcherTests-Event", mockSnsClient.PublishedEvents.ElementAt(0).TopicArn);
            Assert.AreEqual("arn:aws:sns:us-west-2:123456789012:NServiceBus-Transport-SQS-Tests-MessageDispatcherTests-AnotherEvent", mockSnsClient.PublishedEvents.ElementAt(1).TopicArn);
        }