Exemple #1
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            _ping   = new PingMessage();
            _future = new FutureMessage <PingMessage, Guid>(_ping.CorrelationId);

            _unsubscribe = RemoteBus.SubscribeHandler <PingMessage>(message => { _future.Set(message); });


            RemoteBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            Trace.WriteLine("LocalBus");

            LocalBus.OutboundPipeline.Trace();

            Trace.WriteLine("RemoteBus");

            RemoteBus.OutboundPipeline.Trace();


            LocalBus.Publish(_ping);
        }
Exemple #2
0
        public void A_response_should_be_sent_directly_if_a_reply_address_is_specified()
        {
            var ping = new PingMessage();

            var otherConsumer = new TestMessageConsumer <PongMessage>();

            RemoteBus.SubscribeInstance(otherConsumer);

            var consumer = new TestCorrelatedConsumer <PongMessage, Guid>(ping.CorrelationId);

            LocalBus.SubscribeInstance(consumer);

            var pong = new FutureMessage <PongMessage>();

            RemoteBus.SubscribeHandler <PingMessage>(message =>
            {
                pong.Set(new PongMessage(message.CorrelationId));

                RemoteBus.Context().Respond(pong.Message);
            });

            RemoteBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            LocalBus.Publish(ping, context => context.SendResponseTo(LocalBus));

            Assert.IsTrue(pong.IsAvailable(8.Seconds()), "No pong generated");

            consumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
            otherConsumer.ShouldNotHaveReceivedMessage(pong.Message, 1.Seconds());
        }
Exemple #3
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            AddFirstCommandInstance("A", "loopback://localhost/a");
            AddFirstCommandInstance("B", "loopback://localhost/b");
            AddFirstCommandInstance("C", "loopback://localhost/c");

            RemoteBus.ShouldHaveRemoteSubscriptionFor <Distributed <FirstCommand> >();
        }
Exemple #4
0
        public void A_reply_should_be_received_by_the_requestor()
        {
            RemoteBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            var message = new PingMessage();

            var consumer = new TestCorrelatedConsumer <PongMessage, Guid>(message.CorrelationId);

            LocalBus.SubscribeInstance(consumer);

            RemoteBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();

            LocalBus.Publish(message);

            TestConsumerBase <PingMessage> .AnyShouldHaveReceivedMessage(message, _timeout);

            consumer.ShouldHaveReceivedMessage(new PongMessage(message.CorrelationId), _timeout);
        }
        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 =>
            {
                RemoteBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();

                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");
        }