public void WaitForMessage_WithMessageInQueue_ShouldSucceed()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            var sendMessageTask = new SendSQSMessageTask(awsClientFactory, logger)
                                      {
                                          QueueUrl = _queueUrl,
                                          MessageBody = "Test Wait for Mesage",
                                          EncryptionContainerName = TestHelper.EncryptionContainerName,
                                      };
            Assert.IsTrue(sendMessageTask.Execute(), "Failed to send setup message");

            // Message should have appeared in the 60 seconds timeout
            var task = new WaitForSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl = _queueUrl,
                TimeOutSeconds = 60,
                PollIntervalSeconds = 1,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceeded");
            Assert.IsNotNullOrEmpty(task.MessageBody, "MessageBody");
            Assert.IsNotNullOrEmpty(task.MessageId, "MessageId");
            Assert.IsNotNullOrEmpty(task.ReceiptHandle, "ReceiptHandle");
        }
        public void WaitForMessage_WithMessageInQueue_ShouldSucceed()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            var sendMessageTask = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                MessageBody             = "Test Wait for Mesage",
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            Assert.IsTrue(sendMessageTask.Execute(), "Failed to send setup message");

            // Message should have appeared in the 60 seconds timeout
            var task = new WaitForSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                TimeOutSeconds          = 60,
                PollIntervalSeconds     = 1,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceeded");
            Assert.IsNotNullOrEmpty(task.MessageBody, "MessageBody");
            Assert.IsNotNullOrEmpty(task.MessageId, "MessageId");
            Assert.IsNotNullOrEmpty(task.ReceiptHandle, "ReceiptHandle");
        }
        public void CreateQueueTwice_Should_Succeed()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            var task = new CreateSQSQueueTask(awsClientFactory, logger)
            {
                EncryptionContainerName = TestHelper.EncryptionContainerName,
                QueueName = "TestQ"
            };

            var task2 = new CreateSQSQueueTask(awsClientFactory, logger)
            {
                EncryptionContainerName = TestHelper.EncryptionContainerName,
                QueueName = "TestQ"
            };

            // Execute
            bool suceeded = task.Execute();
            bool suceeded2 = task2.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsTrue(suceeded2, "Task 2 did not suceed");

            Assert.IsNotNullOrEmpty(task.QueueUrl, "QueueUrl");
            Assert.AreEqual(task.QueueUrl, task2.QueueUrl, "Second queue url did not match first");
        }
Beispiel #4
0
        public Initialisor(IBus bus, IBus eventProcessingBus)
        {
            if (bus == null)
            {
                throw new ArgumentNullException("bus");
            }

            _bus = bus;
            _eventProcessingBus = eventProcessingBus;
            _membershipService  = new MembershipService(_bus);

            _s3Config = AwsConfigFactory.GetS3Config();
            var awsClientFactory = new AwsClientFactory();

            _fileStore = new S3FileStore(awsClientFactory);

            var dynamoDbConfig      = AwsConfigFactory.GetDynamoDbConfig();
            var mediaRepository     = new MediaRepository(dynamoDbConfig, awsClientFactory);
            var uniquNameRepository = new UniqueNameRepository(dynamoDbConfig, awsClientFactory);

            _mediaService = new MediaService(_bus, mediaRepository, uniquNameRepository, _fileStore);


            _heartbeatService = new HeartbeatService(_bus, ServerSettings.ServerName);
            _heartbeatService.Start();

            AutoMapperConfiguration.Configure();
        }
        public void CreateQueueTwice_Should_Succeed()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            var task = new CreateSQSQueueTask(awsClientFactory, logger)
            {
                EncryptionContainerName = TestHelper.EncryptionContainerName,
                QueueName = "TestQ"
            };

            var task2 = new CreateSQSQueueTask(awsClientFactory, logger)
            {
                EncryptionContainerName = TestHelper.EncryptionContainerName,
                QueueName = "TestQ"
            };

            // Execute
            bool suceeded  = task.Execute();
            bool suceeded2 = task2.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsTrue(suceeded2, "Task 2 did not suceed");

            Assert.IsNotNullOrEmpty(task.QueueUrl, "QueueUrl");
            Assert.AreEqual(task.QueueUrl, task2.QueueUrl, "Second queue url did not match first");
        }
        public TransportInfrastructure(SettingsHolder settings)
        {
            configuration = new ConnectionConfiguration(settings);

            sqsClient = AwsClientFactory.CreateSqsClient(configuration);
            s3Client  = AwsClientFactory.CreateS3Client(configuration);

            queueUrlCache = new QueueUrlCache(sqsClient);
        }
Beispiel #7
0
        public SqsTransportInfrastructure(SettingsHolder settings)
        {
            _connectionConfiguration = new SqsConnectionConfiguration(settings);

            _sqsClient = AwsClientFactory.CreateSqsClient(_connectionConfiguration);
            _s3Client  = AwsClientFactory.CreateS3Client(_connectionConfiguration);

            _sqsQueueUrlCache = new SqsQueueUrlCache
            {
                SqsClient = _sqsClient
            };
        }
Beispiel #8
0
        public void CanCreateAmazonIdentityManagementServiceClient()
        {
            //Arrange
            var sut = new AwsClientFactory(_options);

            //Act
            var result = sut.Create <AmazonIdentityManagementServiceClient>();

            //Assert
            Assert.NotNull(sut);
            Assert.NotNull(result);
            Assert.Equal(result.Config.RegionEndpoint.SystemName, _options.Value.Region);
        }
        public SqsTestContext(object fixture)
        {
            Address = new Address(fixture.GetType().Name, Environment.MachineName);
            ConnectionConfiguration =
                SqsConnectionStringParser.Parse(ConfigurationManager.AppSettings["TestConnectionString"]);

            S3Client  = AwsClientFactory.CreateS3Client(ConnectionConfiguration);
            SqsClient = AwsClientFactory.CreateSqsClient(ConnectionConfiguration);

            Creator = new SqsQueueCreator
            {
                ConnectionConfiguration = ConnectionConfiguration,
                SqsClient = SqsClient,
                S3Client  = S3Client
            };

            _receivedMessages           = new Subject <TransportMessage>();
            _exceptionsThrownByReceiver = new Subject <Exception>();

            QueueUrlCache = new SqsQueueUrlCache
            {
                SqsClient = SqsClient,
                ConnectionConfiguration = ConnectionConfiguration
            };


            Sender = new SqsQueueSender
            {
                ConnectionConfiguration = ConnectionConfiguration,
                SqsClient     = SqsClient,
                S3Client      = S3Client,
                QueueUrlCache = QueueUrlCache,
                QueueCreator  = Creator
            };

            DequeueStrategy = new SqsDequeueStrategy(null)
            {
                ConnectionConfiguration = ConnectionConfiguration,
                SqsClient = SqsClient,
                S3Client  = S3Client
            };
        }
        public void CreateQueue_Should_CreateQueue()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            var task = new CreateSQSQueueTask(awsClientFactory, logger)
                           {
                               EncryptionContainerName = TestHelper.EncryptionContainerName,
                               QueueName = "TestQ"
                           };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsNotNullOrEmpty(task.QueueUrl, "QueueUrl");
        }
        public void CreateQueue_Should_CreateQueue()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            var task = new CreateSQSQueueTask(awsClientFactory, logger)
            {
                EncryptionContainerName = TestHelper.EncryptionContainerName,
                QueueName = "TestQ"
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsNotNullOrEmpty(task.QueueUrl, "QueueUrl");
        }
        public void WaitForMessage_WithNoMessage_ShouldFail()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            var task = new WaitForSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl = _queueUrl,
                TimeOutSeconds = 10,
                PollIntervalSeconds = 5,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsFalse(suceeded, "Should not have suceeded");
        }
        async Task SendPoisonMessage(string inputQueueName)
        {
            var transportConfiguration = new TransportExtensions <SqsTransport>(new SettingsHolder());

            transportConfiguration = transportConfiguration.ConfigureSqsTransport(SetupFixture.SqsQueueNamePrefix);
            var connectionConfiguration = new ConnectionConfiguration(transportConfiguration.GetSettings());

            using (var sqsClient = AwsClientFactory.CreateSqsClient(connectionConfiguration))
            {
                var getQueueUrlResponse = await sqsClient.GetQueueUrlAsync(new GetQueueUrlRequest
                {
                    QueueName = QueueNameHelper.GetSqsQueueName(inputQueueName, connectionConfiguration)
                }).ConfigureAwait(false);

                await sqsClient.SendMessageAsync(new SendMessageRequest
                {
                    QueueUrl    = getQueueUrlResponse.QueueUrl,
                    MessageBody = PoisonMessageBody
                }).ConfigureAwait(false);
            }
        }
        public void WaitForMessage_WithNoMessage_ShouldFail()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            var task = new WaitForSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                TimeOutSeconds          = 10,
                PollIntervalSeconds     = 5,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsFalse(suceeded, "Should not have suceeded");
        }
        public void DeleteQueue_Should_DeleteQueue()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            // Create a queue to delete.
            string queueUrl = TestHelper.CreateQueue("TestQ", TestHelper.EncryptionContainerName);

            var task = new DeleteSQSQueueTask(awsClientFactory, logger)
                           {
                               QueueUrl = queueUrl,
                               EncryptionContainerName = TestHelper.EncryptionContainerName
                           };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
        }
Beispiel #16
0
        public void DeleteQueue_Should_DeleteQueue()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            // Create a queue to delete.
            string queueUrl = TestHelper.CreateQueue("TestQ", TestHelper.EncryptionContainerName);

            var task = new DeleteSQSQueueTask(awsClientFactory, logger)
            {
                QueueUrl = queueUrl,
                EncryptionContainerName = TestHelper.EncryptionContainerName
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
        }
Beispiel #17
0
        private void ApplyDbTransforms()
        {
            try
            {
                // Ensure that the bucket exists on start-up rather than rely on
                try
                {
                    Logger.LogMessage("Create Bucket for processed images.");
                    var bucket = _s3Config.ProcessedImagesBucket;
                    _fileStore.EnsureBucketExists(bucket);
                    Logger.LogMessage("Create Bucket - Completed.");
                }
                catch (Exception ex)
                {
                    // Failed occasionally when bucket exists.
                    // Sink
                    Logger.LogException(ex, "Failed to create bucked for processed images on startup");
                }

                var awsClientFactory = new AwsClientFactory();

                // Create DynamoDB tables...
                Logger.LogMessage("Applying DB Transformations");
                var config = AwsConfigFactory.GetDynamoDbConfig();
                MediaRepositoryMigrationV1 v1Migations = new MediaRepositoryMigrationV1(config, awsClientFactory);
                v1Migations.CreateMediaItemTable().Wait();
                Logger.LogMessage("Apply Media V1 Transforms - Completed.");

                Logger.LogMessage("Apply Unique Name V1 Transforms.");
                UniqueNameRepositoryMigrationV1 uniqueNameV1Migrations = new UniqueNameRepositoryMigrationV1(config, awsClientFactory);
                uniqueNameV1Migrations.CreateTable().Wait();
                Logger.LogMessage("Apply Unique Name V1 Transforms - Completed.");
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, "Failed during ApplyDbTransforms");
            }
        }
Beispiel #18
0
        public void SendMessage_Should_ReturnMessageId()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            const string messageBody = "TestMessageBody";

            var task = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                MessageBody             = messageBody,
                EncryptionContainerName = TestHelper.EncryptionContainerName
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsNotNullOrEmpty(task.MessageId, "MessageId");
        }
        public void SendMessage_Should_ReturnMessageId()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            const string messageBody = "TestMessageBody";

            var task = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl = _queueUrl,
                MessageBody = messageBody,
                EncryptionContainerName = TestHelper.EncryptionContainerName
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsNotNullOrEmpty(task.MessageId, "MessageId");
        }
Beispiel #20
0
        public async Task OneTimeTearDown()
        {
            // Once all tests have completed, delete all queues that were created.
            // Use the QueueNamePrefix to determine which queues to delete.
            var transportConfiguration = new TransportExtensions <SqsTransport>(new SettingsHolder());

            transportConfiguration = transportConfiguration.ConfigureSqsTransport(SqsQueueNamePrefix);
            var connectionConfiguration = new ConnectionConfiguration(transportConfiguration.GetSettings());
            var sqsClient        = AwsClientFactory.CreateSqsClient(connectionConfiguration);
            var listQueuesResult = await sqsClient.ListQueuesAsync(connectionConfiguration.QueueNamePrefix).ConfigureAwait(false);

            foreach (var queueUrl in listQueuesResult.QueueUrls)
            {
                try
                {
                    await sqsClient.DeleteQueueAsync(queueUrl).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Exception when deleting queue: {ex}");
                }
            }
        }
Beispiel #21
0
        protected override void Configure(FeatureConfigurationContext context, string connectionString)
        {
            var connectionConfiguration = SqsConnectionStringParser.Parse(connectionString);

            context.Container.ConfigureComponent(_ => connectionConfiguration, DependencyLifecycle.SingleInstance);

            context.Container.ConfigureComponent(_ => AwsClientFactory.CreateSqsClient(connectionConfiguration), DependencyLifecycle.SingleInstance);

            context.Container.ConfigureComponent(_ => AwsClientFactory.CreateS3Client(connectionConfiguration), DependencyLifecycle.SingleInstance);

            context.Container.ConfigureComponent <SqsQueueUrlCache>(DependencyLifecycle.SingleInstance);

            context.Container.ConfigureComponent <SqsDequeueStrategy>(DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent <SqsQueueSender>(DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent <SqsQueueCreator>(DependencyLifecycle.InstancePerCall);

            if (context.Settings.UseSqsDeferral())
            {
                context.Container.ConfigureComponent <SqsDeferrer>(DependencyLifecycle.InstancePerCall);
            }
        }
Beispiel #22
0
        public void ReceiveMessage_Should_ReceiveMessage()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger       logger           = new NullLogger();

            // Add a message to the queue to ensure that their is one and wait for 2 seconds to allow
            // the message to propogate.
            // Add the time on to ensure the correct message is received.
            string expectedMessage    = "Sample test message " + DateTime.Now.ToLongTimeString();
            var    sendSqsMessageTask = new SendSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl                = _queueUrl,
                MessageBody             = expectedMessage,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            sendSqsMessageTask.Execute();

            // Messages can be very slow to appear on the queue.
            Thread.Sleep(60000);

            var task = new ReceiveSQSMessageTask(awsClientFactory, logger)
            {
                QueueUrl = _queueUrl,
                EncryptionContainerName = TestHelper.EncryptionContainerName,
            };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsTrue(task.HasMessage, "No message");
            Assert.IsNotNullOrEmpty(expectedMessage, task.MessageBody, "MessageId");
        }
        public void ReceiveMessage_Should_ReceiveMessage()
        {
            // Setup
            // TODO: Replace this with a mocked factory.
            IAwsClientFactory awsClientFactory = new AwsClientFactory();
            ITaskLogger logger = new NullLogger();

            // Add a message to the queue to ensure that their is one and wait for 2 seconds to allow
            // the message to propogate.
            // Add the time on to ensure the correct message is received.
            string expectedMessage = "Sample test message " + DateTime.Now.ToLongTimeString();
            var sendSqsMessageTask = new SendSQSMessageTask(awsClientFactory, logger)
                                         {
                                             QueueUrl = _queueUrl,
                                             MessageBody = expectedMessage,
                                             EncryptionContainerName = TestHelper.EncryptionContainerName,
                                         };

            sendSqsMessageTask.Execute();

            // Messages can be very slow to appear on the queue.
            Thread.Sleep(60000);

            var task = new ReceiveSQSMessageTask(awsClientFactory, logger)
                           {
                               QueueUrl = _queueUrl,
                               EncryptionContainerName = TestHelper.EncryptionContainerName,
                           };

            // Execute
            bool suceeded = task.Execute();

            // Test
            Assert.IsTrue(suceeded, "Did not suceed");
            Assert.IsTrue(task.HasMessage, "No message");
            Assert.IsNotNullOrEmpty(expectedMessage, task.MessageBody, "MessageId");
        }
        async Task CheckErrorQueue(string errorQueueName, CancellationToken cancellationToken)
        {
            var transportConfiguration = new TransportExtensions <SqsTransport>(new SettingsHolder());

            transportConfiguration = transportConfiguration.ConfigureSqsTransport(SetupFixture.SqsQueueNamePrefix);
            var connectionConfiguration = new ConnectionConfiguration(transportConfiguration.GetSettings());

            using (var sqsClient = AwsClientFactory.CreateSqsClient(connectionConfiguration))
            {
                var getQueueUrlResponse = await sqsClient.GetQueueUrlAsync(new GetQueueUrlRequest
                {
                    QueueName = QueueNameHelper.GetSqsQueueName(errorQueueName, connectionConfiguration)
                }, cancellationToken).ConfigureAwait(false);

                var messageReceived = false;
                ReceiveMessageResponse receiveMessageResponse = null;

                while (messageReceived == false && !cancellationToken.IsCancellationRequested)
                {
                    receiveMessageResponse = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest
                    {
                        QueueUrl        = getQueueUrlResponse.QueueUrl,
                        WaitTimeSeconds = 20
                    }, cancellationToken).ConfigureAwait(false);

                    if (receiveMessageResponse.Messages.Any())
                    {
                        messageReceived = true;
                    }
                }

                Assert.NotNull(receiveMessageResponse);
                Assert.AreEqual(1, receiveMessageResponse.Messages.Count);
                Assert.AreEqual(PoisonMessageBody, receiveMessageResponse.Messages.Single().Body);
            }
        }
 protected AmazonSQS GetClient(AwsClientDetails clientDetails)
 {
     return(AwsClientFactory.CreateAmazonSQSClient(clientDetails.AwsAccessKeyId, clientDetails.AwsSecretAccessKey));
 }
 protected AmazonIdentityManagementService GetService(AwsClientDetails clientDetails)
 {
     return(AwsClientFactory.CreateAmazonIdentityManagementService(clientDetails.AwsAccessKeyId,
                                                                   clientDetails.AwsSecretAccessKey));
 }