WaitForDeliveries() public method

public WaitForDeliveries ( int deliveryCount, System.TimeSpan timeout, System.Action inner ) : void
deliveryCount int
timeout System.TimeSpan
inner System.Action
return void
        public void FileSystemDispatcher_Can_Send_To_FileSystemListener()
        {
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

            ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "File System Dispatcher", null, null, typeof(IContract), new FileSystemDispatcher(new ConverterMessageDeliveryWriterFactory(encoder, typeof(IContract)), Config.IncomingFilePath), new PassThroughMessageFilter());
            dispatchRuntime.Subscribe(subscription);

            ServiceBusRuntime listenerRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var listener = new ListenerEndpoint(Guid.NewGuid(), "File System Listener", null, null, typeof(IContract), new FileSystemListener(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)), Config.IncomingFilePath, Config.ProcessedFilePath));
            listenerRuntime.AddListener(listener);
            listenerRuntime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Pass through", null, null, typeof(IContract), new ActionDispatcher((se, md) => { }), new PassThroughMessageFilter()));

            var dispatchTester = new ServiceBusTest(dispatchRuntime);
            var listenerTester = new ServiceBusTest(listenerRuntime);

            string message = "test this thing";

            dispatchTester.StartAndStop(() =>
            {
                listenerTester.WaitForDeliveries(1, TimeSpan.FromSeconds(10), ()=>
                {
                    dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", message);
                });
            });

            dispatchRuntime.RemoveSubscription(subscription);
        }
        public void Not_Yet_Expired_Subscriptions_Get_Messages()
        {
            using (var serviceBusRuntime = new ServiceBusRuntime())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                string message            = "Publish this message";
                ContractImplementation ci = new ContractImplementation();

                tester.AddTestSubscription(ci, new PassThroughMessageFilter(), DateTime.MaxValue);


                try
                {
                    tester.WaitForDeliveries(2, TimeSpan.FromSeconds(1), () =>
                    {
                        serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                    });
                }
                catch (TimeoutException)
                {
                    Assert.Fail("Message should have been delivered to not yet expired subscription.");
                }
            }
        }
        public void MessageFilter_Properly_Includes_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime <IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);
                tester.OnlyRetryOnce();

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new BooleanMessageFilter(true));

                string message = "Publish this message";

                tester.WaitForDeliveries(2, TimeSpan.FromMinutes(1), () =>
                {
                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                });

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(message, ci.PublishedMessages[0]);

                tester.VerifyQueuesEmpty();
            }
        }
        public void FileSystemDispatcher_Picks_Up_Existing_Messages()
        {
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

            ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "File System Dispatcher", null, null, typeof(IContract), new FileSystemDispatcher(new ConverterMessageDeliveryWriterFactory(encoder, typeof(IContract)), Config.IncomingFilePath), new PassThroughMessageFilter());

            dispatchRuntime.Subscribe(subscription);

            ServiceBusRuntime listenerRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
            var listener = new ListenerEndpoint(Guid.NewGuid(), "File System Listener", null, null, typeof(IContract), new FileSystemListener(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)), Config.IncomingFilePath, Config.ProcessedFilePath));

            listenerRuntime.AddListener(listener);
            listenerRuntime.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "Pass through", null, null, typeof(IContract), new ActionDispatcher((se, md) => { }), new PassThroughMessageFilter()));

            var dispatchTester = new ServiceBusTest(dispatchRuntime);
            var listenerTester = new ServiceBusTest(listenerRuntime);


            string message = "test this thing";

            dispatchTester.StartAndStop(() =>
            {
                dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", message);

                listenerTester.WaitForDeliveries(1, TimeSpan.FromSeconds(10), () =>
                {
                });
            });

            dispatchRuntime.RemoveSubscription(subscription);
        }
        public void MessageFilter_Properly_Excludes_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime <IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                string message = "Publish this message";

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(1);

                tester.OnlyRetryOnce();

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new BooleanMessageFilter(false));


                try
                {
                    tester.WaitForDeliveries(2, TimeSpan.FromSeconds(5), () =>
                    {
                        serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                    });
                }
                catch (TimeoutException) // should timeout while waiting
                {
                }

                Assert.AreEqual(0, ci.PublishedCount);

                tester.VerifyQueuesEmpty();
            }
        }
        public void Can_Deliver_Many_Messages_With_Failures()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime <IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);
                tester.OnlyRetryOnce();

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);
                ci.SetFailInterval(10);

                QueuedDeliveryCore qc = serviceBusRuntime.ServiceLocator.GetInstance <QueuedDeliveryCore>();
                qc.RetryDelay = 1;

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new PassThroughMessageFilter());

                int messageCount = 1000;

                DateTime start = DateTime.Now;


                tester.WaitForDeliveries(messageCount * 2, TimeSpan.FromMinutes(1), () =>
                {
                    for (int i = 0; i < messageCount; i++)
                    {
                        string message = i.ToString();
                        serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                    }
                });


                bool[] results = new bool[messageCount];
                // Wait for delivery
                DateTime end = DateTime.Now;
                System.Diagnostics.Trace.TraceInformation("Time to deliver " + messageCount + " = " + (end - start));

                for (int i = 0; i < ci.PublishedCount; i++)
                {
                    results[Convert.ToInt32(ci.PublishedMessages[i])] = true;
                }

                for (int i = 0; i < messageCount; i++)
                {
                    Assert.IsTrue(results[i]);
                }

                Assert.AreEqual(messageCount, ci.PublishedCount);
                tester.VerifyQueuesEmpty();
            }
        }
        public void Can_Deliver_Many_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime <IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new PassThroughMessageFilter());

                int messageCount = 1000;


                for (int i = 0; i < messageCount; i++)
                {
                    string message = i.ToString();
                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                }

                DateTime start = DateTime.Now;

                tester.WaitForDeliveries(messageCount * 2, TimeSpan.FromMinutes(1), () =>
                {
                });


                bool[] results = new bool[messageCount];

                DateTime end = DateTime.Now;

                System.Diagnostics.Trace.TraceInformation("Time to deliver messages " + messageCount + " = " + (end - start));

                Assert.AreEqual(messageCount, ci.PublishedCount);

                for (int i = 0; i < ci.PublishedCount; i++)
                {
                    int j = Convert.ToInt32(ci.PublishedMessages[i]);
                    results[j] = true;
                }

                for (int i = 0; i < messageCount; i++)
                {
                    Assert.IsTrue(results[i]);
                }

                tester.VerifyQueuesEmpty();
            }
        }
Esempio n. 8
0
        public void WcfListener_Publishes_Incoming_Messages_Properly()
        {
            ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore());
            runtime.AddListener(new ListenerEndpoint("test", "NamedPipeListener", "net.pipe://localhost/remotehello", typeof(IContract), new WcfServiceHostListener()));

            string message = "This is a test";

            runtime.Subscribe(new SubscriptionEndpoint("test subscription", null, null, typeof(IContract), new ActionDispatcher((se, md) => { Assert.AreEqual(message, (string)md.Message); }), new PassThroughMessageFilter()));

            ServiceBusTest tester = new ServiceBusTest(runtime);
            tester.WaitForDeliveries(1, TimeSpan.FromSeconds(5), () =>
            {
                Service.Use<IContract>("NamedPipeClient", contract =>
                {
                    contract.PublishThis(message);
                });
            });
        }
Esempio n. 9
0
        public void WcfListener_Can_Listen_For_Raw_Messages()
        {
            ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore());
            runtime.AddListener(new ListenerEndpoint("test", "PassThroughListener", "net.pipe://localhost/passthrough", typeof(IPassThroughServiceContract), new WcfServiceHostListener()));

            string action = "http://someaction";
            string body = "some body";

            runtime.Subscribe(new SubscriptionEndpoint("test subscription", null, null, typeof(IContract), new ActionDispatcher((se, md) => { Assert.AreEqual(action, ((Message)md.Message).Headers.Action); Assert.AreEqual(body, ((Message)md.Message).GetBody<string>()); }), new PassThroughMessageFilter()));

            ServiceBusTest tester = new ServiceBusTest(runtime);
            tester.WaitForDeliveries(1, TimeSpan.FromSeconds(5), () =>
            {
                Service.Use<IPassThroughServiceContract>("PassThroughClient", contract =>
                {
                    Message message = Message.CreateMessage(MessageVersion.Default, action, body);
                    contract.Send(message);
                });
            });
        }
        public void WcfListener_Publishes_Incoming_Messages_Properly()
        {
            ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore());

            runtime.AddListener(new ListenerEndpoint("test", "NamedPipeListener", "net.pipe://localhost/remotehello", typeof(IContract), new WcfServiceHostListener()));

            string message = "This is a test";

            runtime.Subscribe(new SubscriptionEndpoint("test subscription", null, null, typeof(IContract), new ActionDispatcher((se, md) => { Assert.AreEqual(message, (string)md.Message); }), new PassThroughMessageFilter()));

            ServiceBusTest tester = new ServiceBusTest(runtime);

            tester.WaitForDeliveries(1, TimeSpan.FromSeconds(5), () =>
            {
                Service.Use <IContract>("NamedPipeClient", contract =>
                {
                    contract.PublishThis(message);
                });
            });
        }
        public void WcfListener_Can_Listen_For_Raw_Messages()
        {
            ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore());

            runtime.AddListener(new ListenerEndpoint("test", "PassThroughListener", "net.pipe://localhost/passthrough", typeof(IPassThroughServiceContract), new WcfServiceHostListener()));

            string action = "http://someaction";
            string body   = "some body";

            runtime.Subscribe(new SubscriptionEndpoint("test subscription", null, null, typeof(IContract), new ActionDispatcher((se, md) => { Assert.AreEqual(action, ((Message)md.Message).Headers.Action); Assert.AreEqual(body, ((Message)md.Message).GetBody <string>()); }), new PassThroughMessageFilter()));

            ServiceBusTest tester = new ServiceBusTest(runtime);

            tester.WaitForDeliveries(1, TimeSpan.FromSeconds(5), () =>
            {
                Service.Use <IPassThroughServiceContract>("PassThroughClient", contract =>
                {
                    Message message = Message.CreateMessage(MessageVersion.Default, action, body);
                    contract.Send(message);
                });
            });
        }
        public void Dispatcher_Receives_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime <IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                string message            = "Publish this message";
                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new PassThroughMessageFilter());

                tester.WaitForDeliveries(2, TimeSpan.FromSeconds(50), () =>
                {
                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                });

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(message, ci.PublishedMessages[0]);

                tester.VerifyQueuesEmpty();
            }
        }
        public void Can_Deliver_Many_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime<IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new PassThroughMessageFilter());

                int messageCount = 1000;

                for (int i = 0; i < messageCount; i++)
                {
                    string message = i.ToString();
                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                }

                DateTime start = DateTime.Now;

                tester.WaitForDeliveries(messageCount*2, TimeSpan.FromMinutes(1), () =>
                {

                });

                bool[] results = new bool[messageCount];

                DateTime end = DateTime.Now;

                System.Diagnostics.Trace.TraceInformation("Time to deliver messages "+messageCount+" = "+(end - start));

                Assert.AreEqual(messageCount, ci.PublishedCount);

                for(int i = 0; i < ci.PublishedCount; i++)
                {
                    int j = Convert.ToInt32(ci.PublishedMessages[i]);
                    results[j] = true;
                }

                for (int i = 0; i < messageCount; i++)
                {
                    Assert.IsTrue(results[i]);
                }

                tester.VerifyQueuesEmpty();
            }
        }
        public void Can_Deliver_Many_Messages_With_Failures()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime<IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);
                tester.OnlyRetryOnce();

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);
                ci.SetFailInterval(10);

                QueuedDeliveryCore qc = serviceBusRuntime.ServiceLocator.GetInstance<QueuedDeliveryCore>();
                qc.RetryDelay = 1;

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new PassThroughMessageFilter());

                int messageCount = 1000;

                DateTime start = DateTime.Now;

                tester.WaitForDeliveries(messageCount*2, TimeSpan.FromMinutes(1), () =>
                {
                    for (int i = 0; i < messageCount; i++)
                    {
                        string message = i.ToString();
                        serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                    }
                });

                bool[] results = new bool[messageCount];
                // Wait for delivery
                DateTime end = DateTime.Now;
                System.Diagnostics.Trace.TraceInformation("Time to deliver " + messageCount + " = " + (end - start));

                for (int i = 0; i < ci.PublishedCount; i++)
                {
                    results[Convert.ToInt32(ci.PublishedMessages[i])] = true;
                }

                for (int i = 0; i < messageCount; i++)
                {
                    Assert.IsTrue(results[i]);
                }

                Assert.AreEqual(messageCount, ci.PublishedCount);
                tester.VerifyQueuesEmpty();
            }
        }
        public void Not_Yet_Expired_Subscriptions_Get_Messages()
        {
            using (var serviceBusRuntime = new ServiceBusRuntime())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                string message = "Publish this message";
                ContractImplementation ci = new ContractImplementation();

                tester.AddTestSubscription(ci, new PassThroughMessageFilter(), DateTime.MaxValue);

                try
                {
                    tester.WaitForDeliveries(2, TimeSpan.FromSeconds(1), () =>
                    {
                        serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                    });
                }
                catch (TimeoutException)
                {
                    Assert.Fail("Message should have been delivered to not yet expired subscription.");
                }
            }
        }
        public void MessageFilter_Properly_Includes_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime<IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);
                tester.OnlyRetryOnce();

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new BooleanMessageFilter(true));

                string message = "Publish this message";

                tester.WaitForDeliveries(2, TimeSpan.FromMinutes(1), ()=>
                {
                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                });

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(message, ci.PublishedMessages[0]);

                tester.VerifyQueuesEmpty();
            }
        }
        public void MessageFilter_Properly_Excludes_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime<IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                string message = "Publish this message";

                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(1);

                tester.OnlyRetryOnce();

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new BooleanMessageFilter(false));

                try
                {
                    tester.WaitForDeliveries(2, TimeSpan.FromSeconds(5), () =>
                    {
                        serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                    });
                }
                catch (TimeoutException) // should timeout while waiting
                {
                }

                Assert.AreEqual(0, ci.PublishedCount);

                tester.VerifyQueuesEmpty();
            }
        }
        public void Dispatcher_Receives_Messages()
        {
            using (var serviceBusRuntime = Create.MsmqRuntime<IContract>())
            {
                ServiceBusTest tester = new ServiceBusTest(serviceBusRuntime);

                string message = "Publish this message";
                ContractImplementation ci = new ContractImplementation();
                ci.SetFailCount(0);

                tester.AddTestListener();
                tester.AddTestSubscription(ci, new PassThroughMessageFilter());

                tester.WaitForDeliveries(2, TimeSpan.FromSeconds(50), () =>
                {
                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));
                });

                Assert.AreEqual(1, ci.PublishedCount);
                Assert.AreEqual(message, ci.PublishedMessages[0]);

                tester.VerifyQueuesEmpty();
            }
        }