Exemplo n.º 1
0
        public void ReceiveMessage_WithWaitTimeSet_ShouldEnableLongPolling()
        {
            const string queueName       = "MessageWaitTime_StandardQueue";
            const int    waitTimeSeconds = 10;
            var          message         = new SqsMessage("Test");

            var sqsRequest          = new CreateQueueRequest(queueName);
            var createQueueResponse = _sqs.CreateQueue(sqsRequest);

            _queueUrl = createQueueResponse.QueueUrl;

            var secondSqsClient       = LocalSQSClientBuilder.CreateClient();
            var receiveMessageRequest = new ReceiveMessageRequest()
            {
                QueueUrl        = _queueUrl,
                WaitTimeSeconds = waitTimeSeconds
            };

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();
            var receiveMessageResponseWithinTimeout = secondSqsClient.ReceiveMessage(receiveMessageRequest);

            stopwatch.Stop();

            Assert.True(stopwatch.ElapsedMilliseconds < (waitTimeSeconds * 1000) + 1000);
            Assert.Empty(receiveMessageResponseWithinTimeout.Messages);

            var response = _sqs.SendMessage(new SendMessageRequest(_queueUrl, message.Body));

            stopwatch.Reset();
            stopwatch.Start();

            var receiveMessageResponseAfterTimeout = secondSqsClient.ReceiveMessage(_queueUrl);

            stopwatch.Stop();

            // The ReceiveMessage call should be quick as there is a message in the queue to receive
            Assert.True(stopwatch.ElapsedMilliseconds < waitTimeSeconds * 1000);
            Assert.Equal(message.Body, receiveMessageResponseAfterTimeout.Messages.First().Body);
        }
Exemplo n.º 2
0
        public void ReceiveMessage_WithVisibilityTimeout_ShouldPreventConsumerFromRetrievingMessageDuringTheVisibilityTimeout()
        {
            const string queueName = "MessageVisibility_StandardQueue";
            const int    visibilityTimeoutSeconds = 15;
            var          message = new SqsMessage("Test");

            var sqsRequest = new CreateQueueRequest(queueName)
            {
                Attributes = new Dictionary <string, string>()
                {
                    { QueueAttributeName.VisibilityTimeout, visibilityTimeoutSeconds.ToString() }
                }
            };
            var createQueueResponse = _sqs.CreateQueue(sqsRequest);

            _queueUrl = createQueueResponse.QueueUrl;
            var response = _sqs.SendMessage(new SendMessageRequest(_queueUrl, message.Body));

            var receiveMessageRequest = new ReceiveMessageRequest()
            {
                QueueUrl = _queueUrl
            };

            var receiveMessageResponse = _sqs.ReceiveMessage(receiveMessageRequest);

            Assert.Equal(message.Body, receiveMessageResponse.Messages.First().Body);

            var secondSqsClient = LocalSQSClientBuilder.CreateClient();
            var receiveMessageResponseWithinTimeout = secondSqsClient.ReceiveMessage(_queueUrl);

            Assert.Empty(receiveMessageResponseWithinTimeout.Messages);

            Thread.Sleep((visibilityTimeoutSeconds) * 1000);

            var receiveMessageResponseAfterTimeout = secondSqsClient.ReceiveMessage(_queueUrl);

            Assert.Equal(message.Body, receiveMessageResponseAfterTimeout.Messages.First().Body);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Note: xUnit will create an instance of the test class on every test case hence each test
 /// will have a new client.
 /// </summary>
 public SQSTestBase()
 {
     _sqs = LocalSQSClientBuilder.CreateClient();
 }