CreateTunnel() публичный статический Метод

public static CreateTunnel ( IModel channel, IDurableConnection &durableConnection, bool isChannelOpen = true ) : RabbitTunnel
channel IModel
durableConnection IDurableConnection
isChannelOpen bool
Результат RabbitTunnel
Пример #1
0
        public void Should_be_able_to_subscribe_with_provided_options()
        {
            // Arrange
            var newChannel  = Substitute.For <IModel>();
            var routeFinder = Substitute.For <IRouteFinder>();

            routeFinder.FindQueueName <Customer>("subscriptionName").Returns("QueueByCustomRouteFinder");
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            // Action
            tunnel.Subscribe(new SubscriptionOption <Customer>
            {
                SubscriptionName  = "subscriptionName",
                MessageHandler    = x => { },
                QueuePrefetchSize = 100,
                BatchSize         = 100,
                RouteFinder       = routeFinder
            });

            // Assert
            routeFinder.Received(1).FindQueueName <Customer>("subscriptionName");
            newChannel.Received().BasicQos(0, 100, false);
            newChannel.Received().BasicConsume("QueueByCustomRouteFinder", false, Arg.Is <string>(x => x.StartsWith("subscriptionName-")), Arg.Any <IBasicConsumer>());
        }
Пример #2
0
        public void Should_throw_exception_if_dedicated_publish_channel_is_not_connected()
        {
            // Arrange
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(Substitute.For <IModel>(), out durableConnection, false);

            // Action
            tunnel.Publish("Muahaha");
        }
Пример #3
0
        public void Should_throw_exception_if_dedicated_publish_channel_is_not_created_properly()
        {
            // Arrange
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(null, out durableConnection);

            // Action
            tunnel.Publish("Muahaha");
        }
Пример #4
0
        public void Should_not_throw_any_other_exceptions()
        {
            // Arrange
            IDurableConnection durableConnection;
            var tunnel = (RabbitTunnelForTest)RabbitTunnelForTest.CreateTunnel(null, out durableConnection);

            // Action
            tunnel.TrySubscribeForTest(() => { throw new Exception("Test Exception"); });
        }
Пример #5
0
        public void Should_not_throw_OperationInterruptedException()
        {
            // Arrange
            IDurableConnection durableConnection;
            var tunnel = (RabbitTunnelForTest)RabbitTunnelForTest.CreateTunnel(null, out durableConnection);

            // Action
            tunnel.TrySubscribeForTest(() => { throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 3, "")); });
        }
Пример #6
0
        public void Should_create_subscriptions_to_queues()
        {
            // Arrange
            var newChannel = Substitute.For <IModel>();
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            // Action
            tunnel.Subscribe <Customer>("subscriptionName", x => { });

            // Assert
            newChannel.Received().BasicQos(0, (ushort)Global.PreFetchSize, false);
            newChannel.Received().BasicConsume("Queue", false, Arg.Is <string>(x => x.StartsWith("subscriptionName-")), Arg.Any <IBasicConsumer>());
        }
Пример #7
0
        public void Should_return_subscription()
        {
            // Arrange
            var newChannel = Substitute.For <IModel>();
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            // Action
            var subs = tunnel.Subscribe <Customer>("subscriptionName", (x, y) => { });

            // Assert
            newChannel.Received().BasicQos(0, (ushort)Global.PreFetchSize, false);
            newChannel.Received().BasicConsume("Queue", false, Arg.Is <string>(x => x.StartsWith("subscriptionName-")), Arg.Any <IBasicConsumer>());
            Assert.IsInstanceOfType(typeof(Subscription), subs);
        }
Пример #8
0
        public void Should_notify_all_registered_observers()
        {
            var newChannel = Substitute.For <IModel>();
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            var observer   = Substitute.For <IObserver <ISerializer> >();
            var serializer = Substitute.For <ISerializer>();

            tunnel.AddSerializerObserver(observer);

            // Action
            tunnel.SetSerializer(serializer);

            // Assert
            observer.Received(1).OnNext(serializer);
        }
Пример #9
0
        public void Should_do_nothing_if_disposed()
        {
            // Arrange
            var newChannel = Substitute.For <IModel>();
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            tunnel.Subscribe <Customer>("subscriptionName", x => { });
            tunnel.Dispose();

            // Action
            durableConnection.Disconnected += Raise.Event <Action>();

            // Assert
            newChannel.Received(2).Abort();   //1 for publishing channel, 1 for the above subscription
            newChannel.Received(2).Dispose(); //1 for publishing channel, 1 for the above subscription
        }
Пример #10
0
        public void Should_resubscribe_to_queues_after_reconnect_successfully()
        {
            // Arrange
            var newChannel = Substitute.For <IModel>();
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            tunnel.Subscribe <Customer>("subscriptionName", x => { });
            tunnel.Subscribe <Customer>("subscriptionName2", x => { });

            // Action
            durableConnection.Disconnected += Raise.Event <Action>();
            durableConnection.Connected    += Raise.Event <Action>();

            // Assert
            newChannel.Received(4).BasicConsume("Queue", false, Arg.Is <string>(x => x.StartsWith("subscriptionName")), Arg.Any <IBasicConsumer>());
        }
Пример #11
0
        public void Should_close_dedicatedPublishChannel()
        {
            // Arrange
            var newChannel = Substitute.For <IModel>();
            IDurableConnection durableConnection;
            var tunnel = (RabbitTunnelForTest)RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            tunnel.Publish(new Customer());

            // Action
            durableConnection.Disconnected += Raise.Event <Action>();
            newChannel.BasicAcks           += Raise.EventWith <BasicAckEventArgs>();
            newChannel.BasicNacks          += Raise.EventWith <BasicNackEventArgs>();
            newChannel.BasicReturn         += Raise.EventWith <BasicReturnEventArgs>();

            // Assert
            Assert.IsNull(tunnel.OnBrokerReceivedMessageIsCall);
            Assert.IsNull(tunnel.OnBrokerRejectedMessageIsCall);
            Assert.IsNull(tunnel.OnMessageIsUnroutedIsCall);
        }
Пример #12
0
        public void Should_not_throw_any_other_Exception()
        {
            // Arrange
            var countDownEvent = new CountdownEvent(2);
            var newChannel     = Substitute.For <IModel>();

            newChannel.When(x => x.Abort()).Do(callInfo =>
            {
                countDownEvent.Signal();
                throw new Exception();
            });
            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            tunnel.Subscribe <Customer>("subscriptionName", x => { });

            // Action
            tunnel.Dispose();
            Assert.IsTrue(countDownEvent.Wait(1000));

            // Assert
            durableConnection.Received(1).Dispose();
        }
Пример #13
0
        public void Should_dispose_everything()
        {
            // Arrange
            var countDownEvent = new CountdownEvent(4);
            var newChannel     = Substitute.For <IModel>();

            newChannel.When(x => x.Dispose()).Do(callInfo => countDownEvent.Signal());
            newChannel.When(x => x.Abort()).Do(callInfo => countDownEvent.Signal());

            IDurableConnection durableConnection;
            var tunnel = RabbitTunnelForTest.CreateTunnel(newChannel, out durableConnection);

            tunnel.Subscribe <Customer>("subscriptionName", x => { });

            // Action
            tunnel.Dispose();
            Assert.IsTrue(countDownEvent.Wait(1000));

            // Assert
            // One for the dedicated publish channel and the other for the above subcribe channel
            newChannel.Received(2).Dispose();
            newChannel.Received(2).Abort();
            durableConnection.Received(1).Dispose();
        }