예제 #1
0
        public void Should_support_send_as_well()
        {
            var pongReceived = new FutureMessage <PongMessage>();
            var pingReceived = new FutureMessage <PingMessage>();

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);
                x.Respond(new PongMessage {
                    TransactionId = x.Message.TransactionId
                });
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 8.Seconds();

            RemoteBus.Endpoint.SendRequest(ping, LocalBus, x =>
            {
                x.Handle <PongMessage>(message =>
                {
                    message.TransactionId.ShouldEqual(ping.TransactionId,
                                                      "The response correlationId did not match");
                    pongReceived.Set(message);
                });

                x.SetTimeout(timeout);
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
        }
예제 #2
0
        public void Should_throw_an_exception_if_a_fault_was_published()
        {
            var pongReceived  = new FutureMessage <PongMessage>();
            var faultReceived = new FutureMessage <Fault <PingMessage> >();
            var pingReceived  = new FutureMessage <PingMessage>();

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);

                throw new InvalidOperationException("This should carry over to the calling request");
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = Debugger.IsAttached ? 5.Minutes() : 24.Seconds();

            LocalBus.PublishRequest(ping, x =>
            {
                x.Handle <PongMessage>(pongReceived.Set);
                x.HandleFault(faultReceived.Set);

                x.SetTimeout(timeout);
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            faultReceived.IsAvailable(timeout).ShouldBeTrue("The fault was not received");
            pongReceived.IsAvailable(1.Seconds()).ShouldBeFalse("The pong was not received");
        }
예제 #3
0
        public void Should_use_a_clean_syntax_following_standard_conventions()
        {
            var pongReceived = new FutureMessage <PongMessage>();
            var pingReceived = new FutureMessage <PingMessage>();

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);
                x.Respond(new PongMessage {
                    TransactionId = x.Message.TransactionId
                });
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 8.Seconds();

            LocalBus.PublishRequest(ping, x =>
            {
                x.Handle <PongMessage>(message =>
                {
                    message.TransactionId.ShouldEqual(ping.TransactionId,
                                                      "The response correlationId did not match");
                    pongReceived.Set(message);
                });

                x.SetTimeout(timeout);
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
        }
예제 #4
0
        public void Should_ignore_a_response_that_was_not_for_us()
        {
            var pongReceived = new FutureMessage <PongMessage>();
            var pingReceived = new FutureMessage <PingMessage>();
            var badResponse  = new FutureMessage <PongMessage>();

            LocalBus.SubscribeHandler <PongMessage>(pongReceived.Set);

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);
                RemoteBus.Publish(new PongMessage {
                    TransactionId = x.Message.TransactionId
                });
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 8.Seconds();

            Assert.Throws <RequestTimeoutException>(() =>
            {
                RemoteBus.Endpoint.SendRequest(ping, LocalBus, x =>
                {
                    x.Handle <PongMessage>(badResponse.Set);

                    x.SetTimeout(timeout);
                });
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
            badResponse.IsAvailable(2.Seconds()).ShouldBeFalse("Should not have received a response");
        }
        public void SetUp()
        {
            RemoteBus.SubscribeContextHandler <Input>(Respond);

            _id = Guid.NewGuid();

            Messaging
            .With(new BusEnvironment(LocalBus))
            .SendRequest <Input, Output>(RemoteUri, new Input {
                Id = _id
            });
        }
예제 #6
0
        public void Should_throw_a_handler_exception_on_the_calling_thread_using_async()
        {
            var pongReceived   = new FutureMessage <PongMessage>();
            var pingReceived   = new FutureMessage <PingMessage>();
            var callbackCalled = new FutureMessage <IAsyncResult>();

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);
                x.Respond(new PongMessage {
                    TransactionId = x.Message.TransactionId
                });
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 18.Seconds();

            LocalBus.BeginPublishRequest(ping, callbackCalled.Set, null, x =>
            {
                x.Handle <PongMessage>(message =>
                {
                    pongReceived.Set(message);

                    throw new InvalidOperationException("I got it, but I am naughty with it.");
                });

                x.SetTimeout(timeout);
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");

            callbackCalled.IsAvailable(timeout).ShouldBeTrue("Called was not called");

            var exception =
                Assert.Throws <RequestException>(
                    () => { LocalBus.EndPublishRequest <PingMessage>(callbackCalled.Message); },
                    "A request exception should have been thrown");

            exception.Response.ShouldBeAnInstanceOf <PongMessage>();
            exception.InnerException.ShouldBeAnInstanceOf <InvalidOperationException>();
        }
예제 #7
0
        public void Should_support_the_asynchronous_programming_model()
        {
            var pongReceived   = new FutureMessage <PongMessage>();
            var pingReceived   = new FutureMessage <PingMessage>();
            var callbackCalled = new FutureMessage <IAsyncResult>();

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);
                x.Respond(new PongMessage {
                    TransactionId = x.Message.TransactionId
                });
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage();

            TimeSpan timeout = 18.Seconds();

            LocalBus.BeginPublishRequest(ping, callbackCalled.Set, null, x =>
            {
                x.Handle <PongMessage>(message =>
                {
                    message.TransactionId.ShouldEqual(ping.TransactionId,
                                                      "The response correlationId did not match");
                    pongReceived.Set(message);
                });

                x.SetTimeout(timeout);
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");

            callbackCalled.IsAvailable(timeout).ShouldBeTrue("The callback was not called");

            bool result = LocalBus.EndPublishRequest <PingMessage>(callbackCalled.Message);

            Assert.IsTrue(result, "EndRequest should be true");
        }
예제 #8
0
        public void Should_allow_publish_request_with_custom_headers()
        {
            var pongReceived = new FutureMessage <PongMessage>();
            var pingReceived = new FutureMessage <PingMessage>();

            RemoteBus.SubscribeContextHandler <PingMessage>(x =>
            {
                pingReceived.Set(x.Message);
                var transactionIdFromHeader = new Guid(x.Headers["PingTransactionId"]);
                x.Respond(new PongMessage {
                    TransactionId = transactionIdFromHeader
                });
            });
            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            var ping = new PingMessage {
                TransactionId = Guid.NewGuid()
            };

            TimeSpan timeout = 8.Seconds();

            LocalBus.PublishRequest(ping, x =>
            {
                x.Handle <PongMessage>(message =>
                {
                    message.TransactionId.ShouldEqual(ping.TransactionId,
                                                      "The response correlationId did not match");
                    pongReceived.Set(message);
                });

                x.SetTimeout(timeout);
            }, ctx =>
            {
                ctx.SetHeader("PingTransactionId", ping.TransactionId.ToString());
            });

            pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received");
            pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received");
        }
        public void The_message_should_be_delivered_to_a_remote_subscriber_with_a_reply()
        {
            var updated        = new Future <UpdateMessage>();
            var updateAccepted = new Future <UpdateAcceptedMessage>();

            RemoteBus.SubscribeContextHandler <UpdateMessage>(context =>
            {
                updated.Complete(context.Message);

                context.Respond(new UpdateAcceptedMessage());
            });

            LocalBus.HasSubscription <UpdateMessage>().Count().ShouldBeGreaterThan(0);

            LocalBus.SubscribeHandler <UpdateAcceptedMessage>(updateAccepted.Complete);
            RemoteBus.HasSubscription <UpdateAcceptedMessage>().Count().ShouldBeGreaterThan(0);

            var um = new UpdateMessage();

            LocalBus.Publish(um);

            updated.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update not received");
            updateAccepted.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update accepted not received");
        }
 public void SetUp()
 {
     RemoteBus.SubscribeContextHandler <Input>(Respond);
 }