Example #1
0
        public void Test_CreateQueue_With_QueueName_Having_SpecialCharacters_And_Check_For_Error_Response()
        {
            bool   hasCallbackArrived        = false;
            string actualValue               = string.Empty;
            string expectedValue             = "InvalidParameterValue";
            string queueNameWithSpecialChars = "queue&";

            SQSResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                ISQSResponse result = args.Response;
                //Unhook from event.
                _client.OnSQSResponse -= handler;
                AmazonSQSException exception = result as AmazonSQSException;
                if (null != exception)
                {
                    actualValue = exception.ErrorCode;
                }

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSQSResponse += handler;

            //Create request object.
            _client.CreateQueue(new CreateQueueRequest {
                QueueName = queueNameWithSpecialChars
            });

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
Example #2
0
        /// <summary>
        /// The callback for the Delete-Queue action.
        /// </summary>
        /// <param name="sqsResponse">The <see cref="ISQSResponse"/> instance.</param>
        private void GetDeleteQueueResponse(object sender, ResponseEventArgs args)
        {
            AmazonSQSException sqsResponse = args.Response as AmazonSQSException;

            sqs.OnSQSResponse -= GetDeleteQueueResponse;
            if (null != sqsResponse)
            {
                SQSErrorResponse(sqsResponse);
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.MessageDeletedNotification = "Error Deleting Queue.";
                });
                return;
            }

            DeleteQueueResponse response = args.Response as DeleteQueueResponse;

            if (response != null)
            {
                this.Dispatcher.BeginInvoke(() =>
                {
                    ClearAllProperties(false);
                    this.MessageDeletedNotification = "Queue Deleted Successfully. The queue list is refreshed.";
                    //Relist the queues.
                    btnListQueue_Click(this, null);
                });
            }
        }
Example #3
0
        /// <summary>
        /// The callback for the Get-Queue-Attribute action.
        /// </summary>
        /// <param name="result">The <see cref="ISQSResponse"/> instance.</param>
        void GetQueueAttributeResponse(object sender, ResponseEventArgs args)
        {
            AmazonSQSException sqsResponse = args.Response as AmazonSQSException;

            sqs.OnSQSResponse -= GetQueueAttributeResponse;
            if (null != sqsResponse)
            {
                SQSErrorResponse(sqsResponse);
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.AttributeValue = "Error getting attribute.";
                });
                return;
            }
            GetQueueAttributesResponse response = args.Response as GetQueueAttributesResponse;

            if (null == response)
            {
                return;
            }

            if (response.GetQueueAttributesResult.Attribute.Count > 0)
            {
                this.Dispatcher.BeginInvoke(() => this.AttributeValue =
                                                response.GetQueueAttributesResult.Attribute[0].Value);
            }
        }
Example #4
0
        /// <summary>
        /// The callback for the Receive-Message action.
        /// </summary>
        /// <param name="sqsResponse">The <see cref="ISQSResponse"/> instance.</param>
        private void GetReceiveMessageResponse(object sender, ResponseEventArgs args)
        {
            AmazonSQSException sqsResponse = args.Response as AmazonSQSException;

            sqs.OnSQSResponse -= GetReceiveMessageResponse;
            if (null != sqsResponse)
            {
                SQSErrorResponse(sqsResponse);
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.ReceivedMessage = "Error receiving message.";
                });
                return;
            }
            ReceiveMessageResponse response = args.Response as ReceiveMessageResponse;

            if (null == response)
            {
                return;
            }

            if (response.ReceiveMessageResult.Message.Count > 0)
            {
                this.Dispatcher.BeginInvoke(() =>
                                            this.ReceivedMessage = string.Format(CultureInfo.InvariantCulture, "Queue's Message: {0}", response.ReceiveMessageResult.Message[0].Body));
            }
            else
            {
                this.Dispatcher.BeginInvoke(() =>
                                            this.ReceivedMessage = string.Format(CultureInfo.InvariantCulture, "The server returned an Empty message."));
            }
        }
Example #5
0
        /// <summary>
        /// The callback for the CreateQueue action.
        /// </summary>
        /// <param name="sqsResponse">The <see cref="ISQSResponse"/> instance.</param>
        void GetCreateQueueResponse(object sender, ResponseEventArgs args)
        {
            AmazonSQSException sqsResponse = args.Response as AmazonSQSException;

            sqs.OnSQSResponse -= GetCreateQueueResponse;

            if (null != sqsResponse)
            {
                SQSErrorResponse(sqsResponse);
                return;
            }
            CreateQueueResponse response = args.Response as CreateQueueResponse;

            if (null == response)
            {
                return;
            }

            this.Dispatcher.BeginInvoke(() =>
            {
                this.QueueUrl     = "Url of Queue:\n" + response.CreateQueueResult.QueueUrl;
                this.HaveQueueUrl = true;
            });

            if (string.IsNullOrEmpty(QueuePath))
            {
                string[] parts     = response.CreateQueueResult.QueueUrl.Split('/');
                string   queuePath = parts[parts.Length - 2];
                QueuePath = queuePath;
            }
        }
        private void DiagnosticsSqsException(AmazonSQSException ex, Activity activity)
        {
            if (_diagnostics.IsEnabled(DiagnosticEvents.AmazonSqsException))
            {
                _diagnostics.Write(DiagnosticEvents.AmazonSqsException, new ExceptionPayload(ex, _receiveMessageRequest));
            }

            activity?.AddTag("error", "true");
        }
        public async Task Consume_if_batch_deletion_fails_rethrows() // will then be handled automatically in next receive iteration
        {
            await SetupInitializedPump();

            var messageIdOfDueMessage = Guid.NewGuid().ToString();

            mockSqsClient.ReceiveMessagesRequestResponse = (req, token) =>
            {
                return(new ReceiveMessageResponse
                {
                    Messages = new List <Message>
                    {
                        new Message
                        {
                            Attributes = new Dictionary <string, string>
                            {
                                { "SentTimestamp", "10" },
                                { "ApproximateFirstReceiveTimestamp", "15" },
                                { "ApproximateReceiveCount", "0" },
                                { "MessageDeduplicationId", messageIdOfDueMessage }
                            },
                            MessageAttributes = new Dictionary <string, MessageAttributeValue>
                            {
                                { TransportHeaders.DelaySeconds, new MessageAttributeValue {
                                      StringValue = "20"
                                  } },
                                { Headers.MessageId, new MessageAttributeValue {
                                      StringValue = messageIdOfDueMessage
                                  } }
                            },
                            Body = new string('a', 50 * 1024),
                            ReceiptHandle = "FirstMessage"
                        }
                    }
                });
            };

            var amazonSqsException = new AmazonSQSException("Problem");

            mockSqsClient.DeleteMessageBatchRequestResponse = tuple => throw amazonSqsException;

            var exception = Assert.ThrowsAsync <AmazonSQSException>(async() =>
            {
                await pump.ConsumeDelayedMessages(new ReceiveMessageRequest(), cancellationTokenSource.Token);
            });

            Assert.AreSame(amazonSqsException, exception);
        }
Example #8
0
        void SQSErrorResponse(AmazonSQSException error)
        {
            StringBuilder errorBuilder = new StringBuilder();

            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "ERROR CODE: {0}", error.ErrorCode));
            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "ERROR TYPE: {0}", error.ErrorType));
            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "INNER EXCEPTION: {0}", error.InnerException));
            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "MESSAGE: {0}", error.Message));
            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "REQUEST ID: {0}", error.RequestId));
            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "STATUS CODE: {0}", error.StatusCode));
            errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "\nERROR RESPONSE:\n {0}", error.XML));

            this.Dispatcher.BeginInvoke(() =>
            {
                MessageBox.Show(errorBuilder.ToString(), "Error Occured", MessageBoxButton.OK);
            });
        }
Example #9
0
        public void Test_SendMessage_With_InvalidQueueURL_And_Check_For_Error_Response()
        {
            bool   hasCallbackArrived = false;
            string actualValue        = string.Empty;
            string expectedValue      = "NotFound";
            string expectedValue2     = "BadGateway";
            string invalidQueueUrl    = "https://queue.amazonawsabcdpoiu.com";
            string messageBody        = "A test message body during Unit-Testing";

            SQSResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                ISQSResponse result = args.Response;
                //Unhook from event.
                _client.OnSQSResponse -= handler;
                AmazonSQSException exception = result as AmazonSQSException;
                if (null != exception)
                {
                    actualValue = exception.StatusCode.ToString();
                }

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSQSResponse += handler;

            //Create request object.
            SendMessageRequest request = new SendMessageRequest
            {
                QueueUrl    = (string.Format("{0}/{1}", invalidQueueUrl, _queue_UnitTesting)),
                MessageBody = messageBody
            };

            _client.SendMessage(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue((expectedValue == actualValue) || (expectedValue2 == actualValue)));
            EnqueueTestComplete();
        }
Example #10
0
        public void Test_SendMessage_To_Queue_With_SpecialCharacters_And_Check_For_Error_Response()
        {
            bool   hasCallbackArrived             = false;
            string actualValue                    = string.Empty;
            string expectedValue                  = "";
            string queueNameWithSpecialCharacters = "hello%";
            string messageBody                    = "A test message body during Unit-Testing";

            SQSResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                ISQSResponse result = args.Response;
                //Unhook from event.
                _client.OnSQSResponse -= handler;
                AmazonSQSException exception = result as AmazonSQSException;
                if (null != exception)
                {
                    actualValue = exception.ErrorCode;
                }


                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSQSResponse += handler;

            //Create request object.
            SendMessageRequest request = new SendMessageRequest
            {
                QueueUrl    = (string.Format("{0}/{1}", QueueURL, queueNameWithSpecialCharacters)),
                MessageBody = messageBody
            };

            _client.SendMessage(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
Example #11
0
        public void Test_SetQueueAttributes_With_Multiple_Attributes_With_One_InvalidAttribute_And_Check_For_Error_Response()
        {
            bool   hasCallbackArrived = false;
            string actualValue        = string.Empty;
            string expectedValue      = "InvalidAttributeName";

            SQSResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                ISQSResponse result = args.Response;
                //Unhook from event.
                _client.OnSQSResponse -= handler;
                AmazonSQSException exception = result as AmazonSQSException;
                if (null != exception)
                {
                    actualValue = exception.ErrorCode;
                }

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSQSResponse += handler;

            //Create request object.
            SetQueueAttributesRequest request = new SetQueueAttributesRequest();

            request.QueueUrl = string.Format("{0}/{1}", QueueURL, _queue_UnitTesting);
            request.Attribute.Add(new Amazon.SQS.Model.Attribute {
                Name = "VisibilityTimeout", Value = "3"
            });
            request.Attribute.Add(new Amazon.SQS.Model.Attribute {
                Name = "invalidAttribute", Value = "6000"
            });
            _client.SetQueueAttributes(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(string.Compare(expectedValue, actualValue) == 0));
            EnqueueTestComplete();
        }
Example #12
0
        /// <summary>
        /// The callback for the List-Queues action.
        /// </summary>
        /// <param name="sqsResponse">The <see cref="ISQSResponse"/>.</param>
        void GetListQueueResponse(object sender, ResponseEventArgs args)
        {
            AmazonSQSException sqsResponse = args.Response as AmazonSQSException;

            sqs.OnSQSResponse -= GetListQueueResponse;
            if (null != sqsResponse)
            {
                SQSErrorResponse(sqsResponse);
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.QueueNames.Clear();
                });
                return;
            }
            ListQueuesResponse response = args.Response as ListQueuesResponse;

            if (null != response)
            {
                ListQueuesResult result = response.ListQueuesResult;
                if (null != result)
                {
                    this.Dispatcher.BeginInvoke(() =>
                    {
                        this.QueueNames.Clear();
                        System.Collections.Generic.List <string> queueList = result.QueueUrl.ToList();
                        foreach (string queueListEntry in queueList)
                        {
                            string[] parts   = queueListEntry.Split('/');
                            string queueName = parts[parts.Length - 1];
                            QueueNames.Add(queueName);

                            if (string.IsNullOrEmpty(QueuePath))
                            {
                                string queuePath = parts[parts.Length - 2];
                                QueuePath        = queuePath;
                            }
                        }
                    });
                }
            }
        }
Example #13
0
        private void GetSendMessageResponse(object sender, ResponseEventArgs args)
        {
            AmazonSQSException sqsResponse = args.Response as AmazonSQSException;

            sqs.OnSQSResponse -= GetSendMessageResponse;
            if (null != sqsResponse)
            {
                SQSErrorResponse(sqsResponse as AmazonSQSException);
                this.Dispatcher.BeginInvoke(() =>
                {
                    this.MessageSentNotification = "Error sending message";
                });
                return;
            }
            SendMessageResponse response = args.Response as SendMessageResponse;

            if (response != null)
            {
                this.Dispatcher.BeginInvoke(() => this.MessageSentNotification = "Message sent successfully");
            }
        }
Example #14
0
        public void Test_ReceiveMessage_With_NonExistingQueue_And_Check_For_Error_Response()
        {
            bool   hasCallbackArrived = false;
            string actualValue        = string.Empty;
            string expectedValue      = "AWS.SimpleQueueService.NonExistentQueue";
            string invalidQueueName   = "InvalidQueueName_poiu";

            SQSResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                ISQSResponse result = args.Response;
                //Unhook from event.
                _client.OnSQSResponse -= handler;
                AmazonSQSException exception = result as AmazonSQSException;
                if (null != exception)
                {
                    actualValue = exception.ErrorCode;
                }

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSQSResponse += handler;

            //Create request object.
            ReceiveMessageRequest request = new ReceiveMessageRequest
            {
                QueueUrl = (string.Format("{0}/{1}", QueueURL, invalidQueueName)),
            };

            _client.ReceiveMessage(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(string.Compare(expectedValue, actualValue) == 0));
            EnqueueTestComplete();
        }
Example #15
0
        public void Test_GetQueueAttributes_With_NonExisting_Attribute_And_Check_For_Error_Response()
        {
            bool   hasCallbackArrived   = false;
            string actualValue          = string.Empty;
            string expectedValue        = "InvalidAttributeName";
            string nonExistingAttribute = "poiu";

            SQSResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                ISQSResponse result = args.Response;
                //Unhook from event.
                _client.OnSQSResponse -= handler;
                AmazonSQSException exception = result as AmazonSQSException;
                if (null != exception)
                {
                    actualValue = exception.ErrorCode;
                }

                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSQSResponse += handler;

            //Create request object.
            GetQueueAttributesRequest request = new GetQueueAttributesRequest();

            request.QueueUrl = string.Format("{0}/{1}", QueueURL, _queue_UnitTesting);
            request.AttributeName.Add(nonExistingAttribute);
            _client.GetQueueAttributes(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }