Exemplo n.º 1
0
        public void polling_client_pulls_from_sqs_and_calls_callback()
        {
            var mockSqsClient = new MockSqsClient();
            mockSqsClient.FillQueue(15);
            var pollster = new SqsPollingClient(mockSqsClient);
            Assert.AreEqual(15, mockSqsClient.Queued.Count, "queue was accessed prematurely");
            var posted = new List<SqsMessage>();
            var fooQueue = new SqsQueueName("foo");
            pollster.Listen(new SqsPollingClientSettings(
                                queueName: fooQueue,
                                callback: messages => {
                                    posted.AddRange(messages);
                                    foreach(var msg in messages) {
                                        mockSqsClient.DeleteMessage(fooQueue, msg.MessageReceipt);
                                    }
                                },
                                longPollInterval: 0.Seconds(),
                                maxNumberOfMessages: SqsUtils.MAX_NUMBER_OF_MESSAGES_TO_FETCH,
                                waitTimeOnError: 1.Seconds()));
            Assert.IsTrue(Wait.For(() => mockSqsClient.Queued.Count == 0, 10.Seconds()), "queue did not get depleted in time");
            Assert.IsTrue(
                Wait.For(() => mockSqsClient.ReceiveCalled > 0, 5.Seconds()),
                string.Format("receive called the wrong number of times: Expected {0} != {1}", 3, mockSqsClient.ReceiveCalled)
                );
            Assert.AreEqual(15, mockSqsClient.Delivered.Count, "delivered has the wrong number of messages");

            // Compare delivered and deleted
            Assert.AreEqual(mockSqsClient.Delivered.Count(), mockSqsClient.Deleted.Count(), "The count of delivered messages and deleted messages does not match and it must");
            for(var i = 0; i < mockSqsClient.Delivered.Count(); i++) {
                Assert.AreEqual(
                    mockSqsClient.Delivered[i].MessageReceipt,
                    mockSqsClient.Deleted[i],
                    "delivered message and deleted message don't match on index " + i);
            }
            Assert.AreEqual(mockSqsClient.Delivered.Count(), posted.Count(), "The number of delivered messages and posted messages does not match and it should");
            for(var i = 0; i < mockSqsClient.Delivered.Count(); i++) {
                Assert.AreEqual(
                    mockSqsClient.Delivered[i],
                    posted[i],
                    "delivered and posted don't match");
            }
        }
Exemplo n.º 2
0
 public void polling_client_pulls_from_sqs_and_calls_callback_but_does_not_automatically_deletes_messages()
 {
     var mockSqsClient = new MockSqsClient();
     mockSqsClient.FillQueue(15);
     var pollster = new SqsPollingClient(mockSqsClient);
     Assert.AreEqual(15, mockSqsClient.Queued.Count, "queue was accessed prematurely");
     var posted = new List<SqsMessage>();
     var queueName = new SqsQueueName("foo");
     pollster.Listen(new SqsPollingClientSettings(
                         queueName: queueName,
                         callback: posted.AddRange,
                         longPollInterval: 10.Seconds(),
                         maxNumberOfMessages: SqsUtils.MAX_NUMBER_OF_MESSAGES_TO_FETCH,
                         waitTimeOnError: 1.Seconds()));
     Assert.IsTrue(Wait.For(() => mockSqsClient.Queued.Count == 0, 10.Seconds()), "queue did not get depleted in time");
     Assert.IsTrue(
         Wait.For(() => mockSqsClient.ReceiveCalled > 0, 5.Seconds()),
         string.Format("receive called the wrong number of times: {0} != {1}", 3, mockSqsClient.ReceiveCalled)
         );
     Assert.AreEqual(15, mockSqsClient.Delivered.Count, "delivered has the wrong number of messages");
     Assert.AreNotEqual(
         mockSqsClient.Delivered.Count,
         mockSqsClient.Deleted.Count,
         "delivered and deleted don't match");
     Assert.AreEqual(
         mockSqsClient.Delivered.Count,
         posted.Count,
         "delivered and posted don't match");
 }