StartAndStop() 공개 메소드

public StartAndStop ( System.Action inner ) : void
inner System.Action
리턴 void
        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 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 Retry_Queue_Receives_Initial_Failures()
        {
            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 PassThroughMessageFilter());

                bool failFirst     = false;
                bool deliverSecond = false;

                tester.StartAndStop(() =>
                {
                    CountdownLatch latch = new CountdownLatch(2 + 1);

                    serviceBusRuntime.MessageDelivered += (o, mdea) =>
                    {
                        int tick; if ((tick = latch.Tick()) == 0)
                        {
                            deliverSecond = true;
                        }
                        Console.WriteLine("Tick deliver " + tick);
                    };
                    serviceBusRuntime.MessageDeliveryFailed += (o, mdfea) =>
                    {
                        int tick; if ((tick = latch.Tick()) == 1)
                        {
                            failFirst = true;
                        }
                        Console.WriteLine("Tick fail " + tick);
                    };

                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));

                    // Wait for delivery
                    latch.Handle.WaitOne(TimeSpan.FromMinutes(1), false); // give it a minute
                });

                Assert.AreEqual(true, failFirst);
                Assert.AreEqual(true, deliverSecond);

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


                tester.VerifyQueuesEmpty();
            }
        }
예제 #4
0
        public void Heartbeat_Timeout_Causes_Failure_Request()
        {
            using (HeartbeatRuntimeService heartbeatService = new HeartbeatRuntimeService())
            {
                using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore(), new TimerRuntimeService(), heartbeatService))
                {
                    heartbeatService.RegisterHeartbeat(new Heartbeat(Guid.NewGuid(), TimeSpan.FromSeconds(5), new PublishRequest(null, null, "BeatRequest"),
                                                                     new PublishRequest(null, null, "Success"), new PublishRequest(null, null, "Failure"),
                                                                     new PredicateMessageFilter(pr => (string)pr.Message == "BeatResponse"), TimeSpan.FromSeconds(1)));

                    AutoResetEvent failEvt     = new AutoResetEvent(false);
                    AutoResetEvent successEvt  = new AutoResetEvent(false);
                    AutoResetEvent responseEvt = new AutoResetEvent(false);

                    /*runtime.Subscribe(new SubscriptionEndpoint("BeatResponse", null, null, null, new ActionDispatcher((se, md) => {
                     *  responseEvt.Set(); ThreadPool.QueueUserWorkItem(s => { Thread.Sleep(2000); runtime.PublishOneWay(new PublishRequest(null, null, "BeatResponse")); });
                     * }),
                     *  new PredicateMessageFilter(pr => (string)pr.Message == "BeatRequest")));*/

                    runtime.Subscribe(new SubscriptionEndpoint("Success", null, null, null, new ActionDispatcher((se, md) => successEvt.Set()), new PredicateMessageFilter(pr => (string)pr.Message == "Success")));
                    runtime.Subscribe(new SubscriptionEndpoint("Failure", null, null, null, new ActionDispatcher((se, md) => failEvt.Set()), new PredicateMessageFilter(pr => (string)pr.Message == "Failure")));

                    ServiceBusTest tester = new ServiceBusTest(runtime);

                    tester.StartAndStop(() =>
                    {
                        if (!failEvt.WaitOne(TimeSpan.FromSeconds(10)))
                        {
                            if (!responseEvt.WaitOne(0))
                            {
                                Assert.Fail("The heartbeat request was never published.");
                            }

                            if (successEvt.WaitOne(0))
                            {
                                Assert.Fail("The heartbeat success event was published instead of the failure event");
                            }
                            Assert.Fail("The heartbeat failure event was not published");
                        }
                    });
                }
            }
        }
예제 #5
0
        public void SmtpDispatcher_Can_Send_Messages()
        {
            if (Config.FromMailAddress != null && Config.ToMailAddress != null)
            {
                ServiceBusRuntime dispatchRuntime = new ServiceBusRuntime(new DirectDeliveryCore());
                var subscription = new SubscriptionEndpoint(Guid.NewGuid(), "Smtp Dispatcher", null, null, typeof(IContract), new SmtpDispatcher("this is a test", new MailAddress(Config.FromMailAddress), new MailAddress[] { new MailAddress(Config.ToMailAddress) }), new PassThroughMessageFilter());

                ServiceBusTest tester = new ServiceBusTest(dispatchRuntime);
                tester.StartAndStop(() =>
                {
                    dispatchRuntime.Subscribe(subscription);
                    dispatchRuntime.PublishOneWay(typeof(IContract), "PublishThis", "this is a test message");
                });
            }
            else
            {
                NUnit.Framework.Assert.Ignore("From and to email addresses must be configured to run smtp tests");
            }
        }
        public void Can_Add_And_Remove_Listeners()
        {
            using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore(), new WcfManagementService()))
            {
                ServiceBusTest tester = new ServiceBusTest(runtime);
                tester.StartAndStop(() =>
                {
                    Service.Use <IServiceBusManagementService>(managementService =>
                    {
                        SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "name of endpoint", "NamedPipeClient", "net.pipe://test/someservice/", typeof(IContract), new WcfProxyDispatcher(), null);
                        managementService.Subscribe(endpoint);

                        SubscriptionEndpoint added = managementService.ListSubscribers().First();
                        tester.AssertEqual(endpoint, added);

                        managementService.Unsubscribe(endpoint.Id);
                        Assert.IsEmpty(managementService.ListSubscribers());
                    });
                });
            }
        }
        public void Can_Add_And_Remove_Subscriptions()
        {
            using(ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore(), new WcfManagementService()))
            {
                ServiceBusTest tester = new ServiceBusTest(runtime);
                tester.StartAndStop(() =>
                {
                    Service.Use<IServiceBusManagementService>(managementService =>
                        {
                            ListenerEndpoint endpoint = new ListenerEndpoint(Guid.NewGuid(), "name of endpoint", "NamedPipeListener", "net.pipe://test/someservice/", typeof(IContract), new WcfServiceHostListener());
                            managementService.AddListener(endpoint);

                            ListenerEndpoint added = managementService.ListListeners().First();
                            tester.AssertEqual(endpoint, added);

                            managementService.RemoveListener(endpoint.Id);
                            Assert.IsEmpty(managementService.ListListeners());
                        });
                });
            }
        }
        public void Heartbeat_Response_Causes_Success_Request()
        {
            using (HeartbeatRuntimeService heartbeatService = new HeartbeatRuntimeService())
            {
                using (ServiceBusRuntime runtime = new ServiceBusRuntime(new DirectDeliveryCore(), new TimerRuntimeService(), heartbeatService))
                {
                    heartbeatService.RegisterHeartbeat(new Heartbeat(Guid.NewGuid(), TimeSpan.FromSeconds(5), new PublishRequest(null, null, "BeatRequest"),
                                                        new PublishRequest(null, null, "Success"), new PublishRequest(null, null, "Failure"),
                                                        new PredicateMessageFilter(pr => (string)pr.Message == "BeatResponse"), TimeSpan.FromSeconds(1)));

                    AutoResetEvent responseEvt = new AutoResetEvent(false);
                    AutoResetEvent failEvt = new AutoResetEvent(false);
                    AutoResetEvent successEvt = new AutoResetEvent(false);

                    runtime.Subscribe(new SubscriptionEndpoint("BeatResponse", null, null, null, new ActionDispatcher((se, md) => { responseEvt.Set(); runtime.PublishOneWay(new PublishRequest(null, null, "BeatResponse")); }), new PredicateMessageFilter(pr => (string)pr.Message == "BeatRequest")));
                    runtime.Subscribe(new SubscriptionEndpoint("Success", null, null, null, new ActionDispatcher((se, md) => successEvt.Set()), new PredicateMessageFilter(pr => (string)pr.Message == "Success")));
                    runtime.Subscribe(new SubscriptionEndpoint("Failure", null, null, null, new ActionDispatcher((se, md) => failEvt.Set()), new PredicateMessageFilter(pr => (string)pr.Message == "Failure")));

                    ServiceBusTest tester = new ServiceBusTest(runtime);

                    tester.StartAndStop(() =>
                    {
                        if (!successEvt.WaitOne(TimeSpan.FromSeconds(10)))
                        {
                            if (!responseEvt.WaitOne(0))
                            {
                                Assert.Fail("The heartbeat request was never published.");
                            }
                            if (failEvt.WaitOne(0))
                            {
                                Assert.Fail("The heartbeat fail event was published instead of the success event");
                            }
                            Assert.Fail("The heartbeat success event was not published");
                        }
                    });

                }
            }
        }
        public void Retry_Queue_Receives_Initial_Failures()
        {
            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 PassThroughMessageFilter());

                bool failFirst = false;
                bool deliverSecond = false;

                tester.StartAndStop(() =>
                {
                    CountdownLatch latch = new CountdownLatch(2+1);

                    serviceBusRuntime.MessageDelivered += (o, mdea) =>
                    {
                        int tick; if ((tick = latch.Tick()) == 0) deliverSecond = true; Console.WriteLine("Tick deliver " + tick);
                    };
                    serviceBusRuntime.MessageDeliveryFailed += (o, mdfea) =>
                    {
                        int tick; if ((tick = latch.Tick()) == 1) failFirst = true; Console.WriteLine("Tick fail " + tick);
                    };

                    serviceBusRuntime.PublishOneWay(new PublishRequest(typeof(IContract), "PublishThis", message));

                    // Wait for delivery
                    latch.Handle.WaitOne(TimeSpan.FromMinutes(1), false); // give it a minute

                });

                Assert.AreEqual(true, failFirst);
                Assert.AreEqual(true, deliverSecond);

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

                tester.VerifyQueuesEmpty();
            }
        }