Exemplo n.º 1
0
        protected void TestInboxError(string queueSchemeAndHost, bool useJournal, bool isTransactional)
        {
            var configuration = GetTestInboxConfiguration(queueSchemeAndHost, useJournal, 1, isTransactional);

            using (var bus = new ServiceBus(configuration))
            {
                var message = bus.CreateTransportMessage(new NoHandlerCommand());

                configuration.Inbox.WorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message));

                var working = true;

                bus.Events.ThreadWaiting += (sender, args) => { working = false; };

                bus.Start();

                while (working)
                {
                    Thread.Sleep(5);
                }
            }

            Assert.NotNull(configuration.Inbox.ErrorQueue.Dequeue());

            AttemptDropQueues(queueSchemeAndHost, useJournal);
        }
Exemplo n.º 2
0
        public void Should_be_able_to_roll_back_any_database_and_queue_changes_when_an_exception_occurs_in_the_receive_pipeline()
        {
            var configuration = DefaultConfiguration(true);

            var inboxWorkQueue    = QueueManager.Instance.GetQueue("msmq://./test-inbox-work");
            var inboxJournalQueue = QueueManager.Instance.GetQueue("msmq://./test-inbox-journal");
            var inboxErrorQueue   = QueueManager.Instance.GetQueue("msmq://./test-error");

            configuration.Inbox =
                new InboxQueueConfiguration
            {
                WorkQueue                 = inboxWorkQueue,
                JournalQueue              = inboxJournalQueue,
                ErrorQueue                = inboxErrorQueue,
                DurationToSleepWhenIdle   = new[] { TimeSpan.FromMilliseconds(5) },
                DurationToIgnoreOnFailure = new[] { TimeSpan.FromMilliseconds(5) },
                MaximumFailureCount       = 100,
                ThreadCount               = 1
            };


            inboxWorkQueue.Drop();
            inboxJournalQueue.Drop();
            inboxErrorQueue.Drop();

            QueueManager.Instance.CreatePhysicalQueues(configuration, QueueCreationType.All);

            var module = new ReceivePipelineExceptionModule(inboxWorkQueue);

            configuration.Modules.Add(module);

            using (var bus = new ServiceBus(configuration))
            {
                var message = bus.CreateTransportMessage(new ReceivePipelineCommand());

                inboxWorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message));

                Assert.AreEqual(1, inboxWorkQueue.Count());

                bus.Start();

                while (module.ShouldWait())
                {
                    Thread.Sleep(10);
                }
            }
        }
Exemplo n.º 3
0
        protected void TestInboxConcurrency(string queueSchemeAndHost, int msToComplete, bool useJournal, bool isTransactional)
        {
            const int COUNT = 10;

            var padlock          = new object();
            var configuration    = GetTestInboxConfiguration(queueSchemeAndHost, useJournal, COUNT, isTransactional);
            var afterDequeueDate = new List <DateTime>();
            var offsetDate       = DateTime.MinValue;

            using (var bus = new ServiceBus(configuration))
            {
                for (var i = 0; i < COUNT; i++)
                {
                    var message = bus.CreateTransportMessage(new ConcurrentCommand
                    {
                        MessageIndex = i
                    });

                    configuration.Inbox.WorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message));
                }

                var idleCount = 0;

                bus.Events.ThreadWaiting += (sender, args) =>
                {
                    lock (padlock)
                    {
                        idleCount++;
                    }
                };

                bus.Events.AfterDequeueStream += (sender, args) =>
                {
                    lock (padlock)
                    {
                        if (offsetDate == DateTime.MinValue)
                        {
                            offsetDate = DateTime.Now;

                            Console.WriteLine("Offset date: {0}", offsetDate.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                        }

                        var dateTime = DateTime.Now;

                        afterDequeueDate.Add(dateTime);

                        Console.WriteLine("Dequeued date: {0}", dateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"));
                    }
                };

                bus.Start();

                while (idleCount < COUNT)
                {
                    Thread.Sleep(30);
                }
            }

            Assert.AreEqual(COUNT, afterDequeueDate.Count,
                            string.Format("Dequeued {0} messages but {1} were sent.", afterDequeueDate.Count, COUNT));

            foreach (var dateTime in afterDequeueDate)
            {
                Assert.IsTrue(dateTime.Subtract(offsetDate) < TimeSpan.FromMilliseconds(msToComplete),
                              "All dequeued messages have to be within {0} ms of first dequeue.", msToComplete);
            }

            AttemptDropQueues(queueSchemeAndHost, useJournal);
        }
Exemplo n.º 4
0
        protected void TestInboxThroughput(string queueSchemeAndHost, int timeoutMilliseconds, int count,
                                           bool useIdempotenceTracker, bool useJournal, bool isTransactional)
        {
            var configuration = GetTestInboxConfiguration(queueSchemeAndHost, useJournal, 1, isTransactional);

            Console.WriteLine("Sending {0} messages to input queue '{1}'.", count, configuration.Inbox.WorkQueue.Uri);

            var sw = new Stopwatch();

            using (var bus = new ServiceBus(configuration))
            {
                for (var i = 0; i < 5; i++)
                {
                    var warmup = bus.CreateTransportMessage(new SimpleCommand("warmup"));

                    configuration.Inbox.WorkQueue.Enqueue(warmup.MessageId, configuration.Serializer.Serialize(warmup));
                }

                var working = true;

                bus.Events.ThreadWaiting += (sender, args) => { working = false; };

                bus.Start();

                while (working)
                {
                    Thread.Sleep(25);
                }

                bus.Stop();

                sw.Start();

                for (var i = 0; i < count; i++)
                {
                    var message = bus.CreateTransportMessage(new SimpleCommand("command " + i));

                    configuration.Inbox.WorkQueue.Enqueue(message.MessageId, configuration.Serializer.Serialize(message));
                }

                sw.Stop();

                Console.WriteLine("Took {0} ms to send {1} messages.  Starting processing.", sw.ElapsedMilliseconds,
                                  count);

                bus.Start();

                sw.Reset();
                sw.Start();

                working = true;

                while (working)
                {
                    Thread.Sleep(25);
                }

                sw.Stop();
            }

            var ms = sw.ElapsedMilliseconds;

            Console.WriteLine("Processed {0} messages in {1} ms", count, ms);

            Assert.IsTrue(ms < timeoutMilliseconds,
                          "Should be able to process at least {0} messages in {1} ms but it ook {2} ms.",
                          count, timeoutMilliseconds, ms);

            AttemptDropQueues(queueSchemeAndHost, useJournal);
        }