Esempio n. 1
0
        public void LoadTest()
        {
            AddConfigValue("SQSWindow", "0.00:00:15");
            //QueueMessages(10000); uncomment to do a load test
            MockSQSService service = new MockSQSService();
            Stopwatch sw = new Stopwatch();
            sw.Start();
            service.Start();

            int count = 0;
            do
            {
                count = 0;
                List<NewWindowEventArgs> windows = new List<NewWindowEventArgs>();
                windows.AddRange(service.NewWindowEventArgsReceived);
                foreach (NewWindowEventArgs args in windows)
                {
                    count += args.Messages.Count();
                }
            }
            while ((count < 10000) &
                   (sw.Elapsed.TotalSeconds < 120));
            sw.Stop();
            service.Stop();
            Assert.IsTrue(sw.Elapsed.TotalSeconds <= 120);

            RemoveConfigValue("SQSWindow");
        }
Esempio n. 2
0
        public void MessageDeleted()
        {
            AddConfigValue("SQSWindow", "0.00:00:15");

            int visibilityTimeout = -1;
            // change the visibility timeout of the queue
            using (Amazon.SQS.AmazonSQSClient client = new AmazonSQSClient(
                ConfigurationManager.AppSettings["AWSAccessKey"],
                ConfigurationManager.AppSettings["AWSSecretAccessKey"],
                new AmazonSQSConfig()))
            {
                // store the visibilitytimeout so we can reset it
                GetQueueAttributesRequest getRequest = new GetQueueAttributesRequest();
                getRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                getRequest.AttributeName.Add("VisibilityTimeout");
                GetQueueAttributesResponse response = client.GetQueueAttributes(getRequest);
                visibilityTimeout = response.GetQueueAttributesResult.VisibilityTimeout;

                // set it to 1 second
                SetQueueAttributesRequest setRequest = new SetQueueAttributesRequest();
                setRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                setRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() { Name = "VisibilityTimeout", Value = "1" });
                client.SetQueueAttributes(setRequest);

                String[] messageIds = new String[] { QueueMessage() };
                MockSQSService service = new MockSQSService();
                service.Start();
                PollForMessages(messageIds, service);

                ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest();
                receiveRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                ReceiveMessageResponse receiveResponse = client.ReceiveMessage(receiveRequest);

                Assert.AreEqual(0, receiveResponse.ReceiveMessageResult.Message.Where((m) => m.MessageId == messageIds[0]).Count());

                // set the visibility timeout back
                setRequest = new SetQueueAttributesRequest();
                setRequest.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                setRequest.Attribute.Add(new Amazon.SQS.Model.Attribute() { Name = "VisibilityTimeout", Value = visibilityTimeout.ToString() });
                client.SetQueueAttributes(setRequest);

                RemoveConfigValue("SQSWindow");
            }
        }
Esempio n. 3
0
        public void MessagesPublished()
        {
            AddConfigValue("SQSWindow", "0.00:00:15");

            // add some messages to the queue
            String[] messageIds = new String[2];
            messageIds[0] = QueueMessage();
            messageIds[1] = QueueMessage();

            MockSQSService service = new MockSQSService();
            service.Start();
            Assert.IsTrue(PollForMessages(messageIds, service));

            RemoveConfigValue("SQSWindow");
        }
Esempio n. 4
0
 public void NewWindowWithNoEvents()
 {
     MockSQSService service = new MockSQSService();
     service.Start();
     Thread.Sleep(10000);
     service.Stop();
     Assert.AreEqual(1, service.NewWindowEventArgsReceived.Count);
 }
Esempio n. 5
0
        public void MessagesOrderedASC()
        {
            AddConfigValue("SQSWindow", "0.00:00:15");

            // add some messages to the queue
            String[] messageIds = new String[2];
            messageIds[0] = QueueMessage();
            messageIds[1] = QueueMessage();

            MockSQSService service = new MockSQSService();
            service.Start();
            PollForMessages(messageIds, service);
            service.Stop();

            int message1Index = -1;
            int message2Index = -1;

            int count = 0;
            foreach (NewWindowEventArgs arg in service.NewWindowEventArgsReceived)
            {
                count++;
                foreach (Message m in arg.Messages)
                {
                    count++;
                    if (m.MessageId == messageIds[0])
                    {
                        message1Index = count;
                    }
                    if (m.MessageId == messageIds[1])
                    {
                        message2Index = count;
                    }
                }
            }

            Assert.IsTrue(message1Index < message2Index);

            RemoveConfigValue("SQSWindow");
        }