Пример #1
0
        public void Long_Message_It_Is_Not_Stored_In_S3_If_IsLargePayloadSupportEnabled_Is_False()
        {
            var extendedClient = new AmazonSQSExtendedClient(sqsMock.Object, new ExtendedClientConfiguration().WithLargePayloadSupportDisabled());
            var body           = GenerateLongString(SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD + 1);
            var messageRequest = new SendMessageRequest(SQS_QUEUE_NAME, body);

            extendedClient.SendMessage(messageRequest);
            s3Mock.Verify(s => s.PutObject(It.IsAny <PutObjectRequest>()), Times.Never);
            sqsMock.Verify(s => s.SendMessage(It.Is <SendMessageRequest>(r => r.MessageBody.Equals(body))));
        }
Пример #2
0
        public void Short_Message_It_Is_Stored_In_S3_If_AlwaysThroughS3_Configured()
        {
            var extendedClient = new AmazonSQSExtendedClient(
                sqsMock.Object,
                new ExtendedClientConfiguration().WithLargePayloadSupportEnabled(s3Mock.Object, S3_BUCKET_NAME).WithAlwaysThroughS3(true));
            var body           = GenerateLongString(SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD + 1);
            var messageRequest = new SendMessageRequest(SQS_QUEUE_NAME, body);

            extendedClient.SendMessage(messageRequest);
            s3Mock.Verify(s => s.PutObject(It.IsAny <PutObjectRequest>()), Times.Once);
            sqsMock.Verify(s => s.SendMessage(It.Is <SendMessageRequest>(r => MessagePointerIsCorrect(r.MessageBody) && LargePayloadAttributeIsAdded(r.MessageAttributes))));
        }
Пример #3
0
        public void Short_Message_It_Is_Stored_In_S3_If_Exceeds_Threshold()
        {
            var extendedClient = new AmazonSQSExtendedClient(
                sqsMock.Object,
                new ExtendedClientConfiguration().WithLargePayloadSupportEnabled(s3Mock.Object, S3_BUCKET_NAME).WithMessageSizeThreshold(100));
            var body = GenerateLongString(101);

            var messageRequest = new SendMessageRequest(SQS_QUEUE_NAME, body);

            extendedClient.SendMessage(messageRequest);
            s3Mock.Verify(s => s.PutObject(It.IsAny <PutObjectRequest>()), Times.Once);
            sqsMock.Verify(s => s.SendMessage(It.Is <SendMessageRequest>(r => MessagePointerIsCorrect(r.MessageBody) && LargePayloadAttributeIsAdded(r.MessageAttributes))));
        }
        private void QueueRequest(SearchIndexQueueRequestModel request)
        {
            var message = JsonConvert.SerializeObject(request, Formatting.None, _jsonSettings);

            var response = _sqsExtendedClient.SendMessage(_searchConfiguration.AWSSQSEndpoint, message);

            if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                LogHelper.Warn <SearchIndexingQueueService>("[Failure] Document Request (ID: {0}, Title: {1}) has not been pushed up to SQS. Response HTTP Status Code: {2}. MD5 of message attributes: {3}. MD5 of message body: {4}.", () => request.Document.NodeId, () => request.Document.Title, () => response.HttpStatusCode, () => response.MD5OfMessageAttributes, () => response.MD5OfMessageBody);
            }
            else
            {
                LogHelper.Info <SearchIndexingQueueService>("[Success] Document Request (ID: {0}, Title: {1}) has been pushed up to SQS.", () => request.Document.NodeId, () => request.Document.Title);
            }
        }
Пример #5
0
        public void Long_Message_S3KeyProvider_Is_Used_If_Configured()
        {
            var mockS3Provider = new Mock <IS3KeyProvider>();

            mockS3Provider.Setup(m => m.GenerateName()).Returns(Constants.CustomPrefix + Guid.NewGuid().ToString("N"));

            var extendedClient = new AmazonSQSExtendedClient(
                sqsMock.Object,
                new ExtendedClientConfiguration()
                .WithLargePayloadSupportEnabled(s3Mock.Object, S3_BUCKET_NAME)
                .WithS3KeyProvider(mockS3Provider.Object));
            var body           = GenerateLongString(SQSExtendedClientConstants.DEFAULT_MESSAGE_SIZE_THRESHOLD + 1);
            var messageRequest = new SendMessageRequest(SQS_QUEUE_NAME, body);

            extendedClient.SendMessage(messageRequest);
            mockS3Provider.Verify(s => s.GenerateName(), Times.Once);
            s3Mock.Verify(s => s.PutObject(It.Is <PutObjectRequest>(r => r.Key.StartsWith(Constants.CustomPrefix))), Times.Once);
            sqsMock.Verify(s => s.SendMessage(It.Is <SendMessageRequest>(r => MessagePointerIsCorrect(r.MessageBody, Constants.CustomPrefix) && LargePayloadAttributeIsAdded(r.MessageAttributes))), Times.Once);
        }