Beispiel #1
0
        public void Sending_to_non_existent_queue_sets_exception_in_result()
        {
            var sqs = new InMemorySqsClient();
            var r   = sqs.Send("foo", AwsSqsMessage.FromBody("foo"), new Result <AwsSqsSendResponse>()).Block();

            Assert.IsTrue(r.HasException);
        }
Beispiel #2
0
        public void LIVE_Send_one_for_inspection()
        {
            var client = CreateLiveClient();
            var queue  = "encoding-test";

            client.CreateQueue(queue, new Result <AwsSqsResponse>()).Wait();
            var msg = AwsSqsMessage.FromBody("<deki-event wikiid=\"default\" event-time=\"2011-06-30T16:16:36Z\"><channel>event://default/deki/pages/dependentschanged/properties/update</channel><uri>http://ariel.mindtouch.com/@api/deki/pages/22?redirects=0</uri><pageid>22</pageid><user id=\"1\" anonymous=\"false\"><uri>http://ariel.mindtouch.com/@api/deki/users/1</uri></user><content.uri type=\"application/xml\">http://ariel.mindtouch.com/@api/deki/pages/22/contents?redirects=0&amp;revision=45&amp;format=xhtml</content.uri><revision.uri>http://ariel.mindtouch.com/@api/deki/pages/22/revisions?redirects=0&amp;revision=45</revision.uri><tags.uri>http://ariel.mindtouch.com/@api/deki/pages/22/tags?redirects=0</tags.uri><comments.uri>http://ariel.mindtouch.com/@api/deki/pages/22/comments?redirects=0</comments.uri><path></path><frommove>false</frommove></deki-event>");
            var r   = client.Send(queue, msg, new Result <AwsSqsSendResponse>()).Block();
            var v   = r.Value;
        }
Beispiel #3
0
        public void Cannot_receive_a_message_to_a_non_existent_queue()
        {
            var sqs  = new InMemorySqsClient();
            var sent = AwsSqsMessage.FromBody("foo");

            try {
                sqs.Receive("bar", new Result <IEnumerable <AwsSqsMessage> >()).Wait();
                Assert.Fail("didn't throw");
            } catch (AwsSqsRequestException e) {
                Assert.AreEqual("AWS.SimpleQueueService.NonExistentQueue", e.Error.Code);
            }
        }
Beispiel #4
0
        public void Can_see_messages_with_visibility_zero()
        {
            var sqs = new InMemorySqsClient();

            sqs.CreateQueue("bar", new Result <AwsSqsResponse>()).Wait();
            var sent      = sqs.Send("bar", AwsSqsMessage.FromBody("foo"), new Result <AwsSqsSendResponse>()).Wait();
            var received1 = sqs.Receive("bar", 10, TimeSpan.Zero, new Result <IEnumerable <AwsSqsMessage> >()).Wait();
            var received2 = sqs.Receive("bar", 10, TimeSpan.Zero, new Result <IEnumerable <AwsSqsMessage> >()).Wait();

            Assert.AreEqual(1, received1.Count());
            Assert.AreEqual(1, received2.Count());
            Assert.AreEqual(sent.MessageId, received1.First().MessageId);
            Assert.AreEqual(sent.MessageId, received2.First().MessageId);
        }
Beispiel #5
0
        public void Can_round_trip_message_through_queue()
        {
            var sqs = new InMemorySqsClient();

            sqs.CreateQueue("bar", new Result <AwsSqsResponse>()).Wait();
            var sent = AwsSqsMessage.FromBody("foo");

            sqs.Send("bar", sent, new Result <AwsSqsSendResponse>()).Wait();
            var msgs = sqs.Receive("bar", new Result <IEnumerable <AwsSqsMessage> >()).Wait();

            Assert.AreEqual(1, msgs.Count());
            var received = msgs.First();

            Assert.AreEqual(sent.Body, received.Body);
        }
Beispiel #6
0
        public void Can_delete_message_from_queue()
        {
            var sqs = new InMemorySqsClient();

            sqs.CreateQueue("bar", new Result <AwsSqsResponse>()).Wait();
            var sent = AwsSqsMessage.FromBody("foo");

            sqs.Send("bar", sent, new Result <AwsSqsSendResponse>()).Wait();
            var received = sqs.Receive("bar", 10, TimeSpan.Zero, new Result <IEnumerable <AwsSqsMessage> >()).Wait().First();

            sqs.Delete(received, new Result <AwsSqsResponse>()).Wait();
            var remaining = sqs.Receive("bar", 10, TimeSpan.Zero, new Result <IEnumerable <AwsSqsMessage> >()).Wait();

            Assert.IsFalse(remaining.Any());
        }
Beispiel #7
0
        public void LIVE_Can_send_and_receive()
        {
            var client = CreateLiveClient();
            var queue  = "test-" + StringUtil.CreateAlphaNumericKey(8);

            client.CreateQueue(queue, new Result <AwsSqsResponse>()).Wait();
            try {
                var body1 = "\"&quot; %20+<>:?";
                var r1    = client.Send(queue, AwsSqsMessage.FromBody(body1), new Result <AwsSqsSendResponse>()).Wait();
                _log.DebugFormat("created message {0}", r1.MessageId);
                var doc = new XDoc("doc")
                          .Elem("foo", StringUtil.CreateAlphaNumericKey(100))
                          .Start("baz")
                          .Elem("bar", StringUtil.CreateAlphaNumericKey(100))
                          .Elem("baz", StringUtil.CreateAlphaNumericKey(100))
                          .End()
                          .Elem("bing", StringUtil.CreateAlphaNumericKey(100));
                var body2Str = "<deki-event wikiid=\"default\" event-time=\"2011-06-30T16:16:36Z\"><channel>event://default/deki/pages/dependentschanged/properties/update</channel><uri>http://ariel.mindtouch.com/@api/deki/pages/22?redirects=0</uri><pageid>22</pageid><user id=\"1\" anonymous=\"false\"><uri>http://ariel.mindtouch.com/@api/deki/users/1</uri></user><content.uri type=\"application/xml\">http://ariel.mindtouch.com/@api/deki/pages/22/contents?redirects=0&amp;revision=45&amp;format=xhtml</content.uri><revision.uri>http://ariel.mindtouch.com/@api/deki/pages/22/revisions?redirects=0&amp;revision=45</revision.uri><tags.uri>http://ariel.mindtouch.com/@api/deki/pages/22/tags?redirects=0</tags.uri><comments.uri>http://ariel.mindtouch.com/@api/deki/pages/22/comments?redirects=0</comments.uri><path>Announcements/2008-10-03_-_Slide_Show_of_T2's_Big_Give</path><frommove>false</frommove></deki-event>";
                var body2Doc = XDocFactory.From(body2Str, MimeType.XML);
                var body2    = body2Doc.ToCompactString();
                var r2       = client.Send(queue, AwsSqsMessage.FromBodyDocument(body2Doc), new Result <AwsSqsSendResponse>()).Wait();
                _log.DebugFormat("created message {0}", r2.MessageId);
                var messages = new List <AwsSqsMessage>();
                Assert.IsTrue(
                    Wait.For(() => {
                    var r = client.Receive(queue, new Result <IEnumerable <AwsSqsMessage> >()).Wait();
                    foreach (var m in r)
                    {
                        _log.DebugFormat("retrieved message {0}", m.MessageId);
                        messages.Add(m);
                    }
                    return(messages.Count == 2);
                },
                             10.Seconds()),
                    string.Format("only received {0} messages from queue before timeout", messages.Count)
                    );
                var msg1 = messages.Where(x => x.MessageId == r1.MessageId).FirstOrDefault();
                var msg2 = messages.Where(x => x.MessageId == r2.MessageId).FirstOrDefault();
                Assert.IsNotNull(msg1, "message 1 was not in response");
                Assert.IsNotNull(msg2, "message 2 was not in response");
                Assert.AreEqual(body1, msg1.Body, "msg 1 body didn't match");
                Assert.AreEqual(body2, msg2.Body, "msg 2 body didn't match");
            } finally {
                _log.DebugFormat("cleaning up queue '{0}'", queue);
                client.DeleteQueue(queue, new Result <AwsSqsResponse>()).Wait();
            }
        }
Beispiel #8
0
        public Result <Production> Produce(int messages)
        {
            var production = new Production();
            var final      = new Result <Production>();

            AsyncUtil.Fork(() => {
                try {
                    _log.DebugFormat("{0}: Producing {1} messages", production.Id, messages);
                    var responses = new List <Result <string> >();
                    var client    = new AwsSqsClient(_clientConfig);
                    for (var i = 0; i < messages; i++)
                    {
                        var result = new Result <string>();
                        responses.Add(result);
                        var msg = production.Id + ":" + messages;
                        client.Send(_queue, AwsSqsMessage.FromBody(msg), new Result <AwsSqsSendResponse>()).WhenDone(r => {
                            if (r.HasException)
                            {
                                result.Throw(r.Exception);
                                return;
                            }
                            result.Return(msg);
                        });
                    }
                    responses.Join(new Result()).WhenDone(r => {
                        if (r.HasException)
                        {
                            final.Throw(r.Exception);
                            return;
                        }
                        production.Stopwatch.Stop();
                        production.Sent.AddRange(responses.Select(x => x.Value));
                        _log.DebugFormat("{0}: Sent {1} messages in {2:0.00}s @ {3:0.00}msg/sec",
                                         production.Id,
                                         production.Sent.Count,
                                         production.Stopwatch.Elapsed.TotalSeconds,
                                         production.Sent.Count / production.Stopwatch.Elapsed.TotalSeconds
                                         );
                        final.Return(production);
                    });
                } catch (Exception e) {
                    final.Throw(e);
                }
            });
            return(final);
        }
Beispiel #9
0
        public void LIVE_STRESS_TEST_multiple_producers_multiple_queues_one_consumer_per_queue()
        {
            var messagesPerProducer = 100;
            var producerCount       = 1;
            var client = CreateLiveClient();
            var queues = new List <string>();

            foreach (var x in new[] { "a", "b", "c", "d" })
            {
                var queue = "test-" + x + "-" + StringUtil.CreateAlphaNumericKey(4);
                client.CreateQueue(queue, new Result <AwsSqsResponse>()).Wait();
                queues.Add(queue);
            }
            try {
                var producers = new List <Result <List <string> > >();
                for (var i = 0; i < producerCount; i++)
                {
                    var producer = i;
                    producers.Add(AsyncUtil.Fork(() => {
                        _log.DebugFormat("producer {0} started", producer);
                        var c    = CreateLiveClient();
                        var msgs = new List <string>();
                        for (var j = 0; j < messagesPerProducer; j++)
                        {
                            var msg = StringUtil.CreateAlphaNumericKey(1024);
                            foreach (var queue in queues)
                            {
                                c.Send(queue, AwsSqsMessage.FromBody(msg), new Result <AwsSqsSendResponse>()).Wait();
                            }
                            msgs.Add(msg);
                            if (msgs.Count % 10 == 0)
                            {
                                _log.DebugFormat("producer {0} sent {1}/{2} msgs", producer, msgs.Count, messagesPerProducer);
                            }
                        }
                        _log.DebugFormat("producer {0} finished", producer);
                        return(msgs);
                    }, new Result <List <string> >()));
                }
                var consumers = queues.ToDictionary(queue => queue, queue => AsyncUtil.Fork(() => {
                    _log.DebugFormat("consumer {0} started", queue);
                    var c          = CreateLiveClient();
                    var msgs       = new List <string>();
                    var expected   = messagesPerProducer * producerCount;
                    var lastReport = 0;
                    while (msgs.Count < expected)
                    {
                        var received = c.ReceiveMax(queue, new Result <IEnumerable <AwsSqsMessage> >()).Wait();
                        var count    = 0;
                        foreach (var msg in received)
                        {
                            count++;
                            msgs.Add(msg.Body);
                            c.Delete(msg, new Result <AwsSqsResponse>()).Wait();
                        }
                        if (count > 0 && msgs.Count > lastReport + 10)
                        {
                            _log.DebugFormat("consumer '{0}' received: {1}/{2}", queue, msgs.Count, expected);
                            lastReport = msgs.Count;
                        }
                    }
                    return(msgs);
                }, new Result <List <string> >()));
                producers.Join(new Result()).Wait();
                consumers.Values.Join(new Result()).Wait();
                var allMessages = producers.SelectMany(x => x.Value).OrderBy(x => x).ToArray();
                foreach (var consumed in consumers)
                {
                    var queue    = consumed.Key;
                    var messages = consumed.Value.Value.OrderBy(x => x).ToArray();
                    Assert.AreEqual(allMessages, messages, string.Format("message list for queue '{0}' is wrong", queue));
                }
            } finally {
                foreach (var queue in queues)
                {
                    _log.DebugFormat("cleaning up queue '{0}'", queue);
                    client.DeleteQueue(queue, new Result <AwsSqsResponse>()).Wait();
                }
            }
        }