Exemple #1
0
        public When_an_action_is_performed_on_a_closed_channel_that_then_opens()
        {
            persistentConnection = Substitute.For <IPersistentConnection>();
            channel = Substitute.For <IModel>();
            var eventBus      = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.CreateModel().Returns(x => { throw exception; },
                                                       x => channel,
                                                       x => channel);


            var logger = Substitute.For <IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent()), null, 10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Exemple #2
0
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub <IPersistentConnection>();
            channel = MockRepository.GenerateStub <IModel>();
            var eventBus      = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);
            var first     = true;

            persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x =>
            {
                if (first)
                {
                    first = false;
                    throw exception;
                }
                x.ReturnValue = channel;
            });

            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Exemple #3
0
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub <IPersistentConnection>();
            var eventBus = MockRepository.GenerateStub <IEventBus>();

            var configuration = new ConnectionConfiguration
            {
                Timeout = 1
            };

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x =>
            {
                throw exception;
            });

            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            channel = MockRepository.GenerateStub<IModel>();
            var eventBus = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer, 
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);
            var first = true;

            persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x =>
                {
                    if (first)
                    {
                        first = false;
                        throw exception;
                    }
                    x.ReturnValue = channel;
                });

            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Exemple #5
0
        public When_an_action_is_performed_on_a_closed_channel_that_doesnt_open_again()
        {
            persistentConnection = Substitute.For <IPersistentConnection>();
            var eventBus = Substitute.For <IEventBus>();

            var configuration = new ConnectionConfiguration
            {
                Timeout = 1
            };

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.When(x => x.CreateModel()).Do(x =>
            {
                throw exception;
            });

            var logger = Substitute.For <IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            var eventBus = MockRepository.GenerateStub<IEventBus>();

            var configuration = new ConnectionConfiguration
                {
                    Timeout = 1
                };

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.Stub(x => x.CreateModel()).WhenCalled(x =>
                {
                    throw exception;
                });

            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

        }
        public When_an_action_is_invoked()
        {
            actionWasInvoked = false;
            actionThreadName = "Not set";

            var parser         = new ConnectionStringParser();
            var configuration  = parser.Parse("host=localhost");
            var connection     = Substitute.For <IPersistentConnection>();
            var channelFactory = Substitute.For <IPersistentChannelFactory>();

            channel = Substitute.For <IPersistentChannel>();

            Action <IModel> action = x =>
            {
                actionWasInvoked = true;
                actionThreadName = Thread.CurrentThread.Name;
            };

            channelFactory.CreatePersistentChannel(connection).Returns(channel);
            channel.When(x => x.InvokeChannelAction(Arg.Any <Action <IModel> >()))
            .Do(x => ((Action <IModel>)x[0])(null));

            dispatcher = new ClientCommandDispatcher(configuration, connection, channelFactory);

            dispatcher.InvokeAsync(action).Wait();
        }
Exemple #8
0
        public void SetUp()
        {
            actionWasInvoked = false;
            actionThreadName = "Not set";

            var parser         = new ConnectionStringParser();
            var configuration  = parser.Parse("host=localhost");
            var connection     = MockRepository.GenerateStub <IPersistentConnection>();
            var channelFactory = MockRepository.GenerateStub <IPersistentChannelFactory>();

            channel = MockRepository.GenerateStub <IPersistentChannel>();

            Action <IModel> action = x =>
            {
                actionWasInvoked = true;
                actionThreadName = Thread.CurrentThread.Name;
            };

            channelFactory.Stub(x => x.CreatePersistentChannel(connection)).Return(channel);
            channel.Stub(x => x.InvokeChannelAction(null)).IgnoreArguments().WhenCalled(
                x => ((Action <IModel>)x.Arguments[0])(null));

            dispatcher = new ClientCommandDispatcher(configuration, connection, channelFactory);

            dispatcher.InvokeAsync(action).Wait();
        }
        public void SetUp()
        {
            actionWasInvoked = false;
            actionThreadName = "Not set";

            var parser = new ConnectionStringParser();
            var configuration = parser.Parse("host=localhost");
            var connection = MockRepository.GenerateStub<IPersistentConnection>();
            var channelFactory = MockRepository.GenerateStub<IPersistentChannelFactory>();
            channel = MockRepository.GenerateStub<IPersistentChannel>();

            Action<IModel> action = x =>
                {
                    actionWasInvoked = true;
                    actionThreadName = Thread.CurrentThread.Name;
                };

            channelFactory.Stub(x => x.CreatePersistentChannel(connection)).Return(channel);
            channel.Stub(x => x.InvokeChannelAction(null)).IgnoreArguments().WhenCalled(
                x => ((Action<IModel>)x.Arguments[0])(null));

            dispatcher = new ClientCommandDispatcher(configuration, connection, channelFactory);

            dispatcher.InvokeAsync(action).Wait();
        }
 public ClientCommandDispatcherSingleton(
     IRabbitMqConfiguration configuration,
     IPersistentConnection connection,
     IPersistentChannelFactory persistentChannelFactory)
 {
     persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection);
     StartDispatcherThread(configuration);
 }
 public static void InvokeChannelAction(
     this IPersistentChannel source, Action <IModel> channelAction, CancellationToken cancellationToken = default
     )
 {
     source.InvokeChannelActionAsync(channelAction, cancellationToken)
     .GetAwaiter()
     .GetResult();
 }
 public static Task InvokeChannelActionAsync(
     this IPersistentChannel source, Action <IModel> channelAction, CancellationToken cancellationToken = default
     )
 {
     return(source.InvokeChannelActionAsync <NoContentStruct>(model =>
     {
         channelAction(model);
         return default;
     }, cancellationToken));
 }
 public void SetUp()
 {
     var logger = new ConsoleLogger();
     var eventBus = new EventBus();
     var parser = new ConnectionStringParser();
     var configuration = parser.Parse("host=localhost");
     var hostSelectionStrategy = new RandomClusterHostSelectionStrategy<ConnectionFactoryInfo>();
     var connectionFactory = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy);
     connection = new PersistentConnection(connectionFactory, logger, eventBus);
     persistentChannel = new PersistentChannel(connection, logger, configuration, new EventBus());
 }
Exemple #14
0
        public ClientCommandDispatcherSingleton(
            IPersistentConnection connection,
            IPersistentChannelFactory persistentChannelFactory)
        {
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(persistentChannelFactory, "persistentChannelFactory");

            persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection);

            StartDispatcherThread();
        }
        public void SetUp()
        {
            var connection = MockRepository.GenerateStub<IPersistentConnection>();
            var channelFactory = MockRepository.GenerateStub<IPersistentChannelFactory>();
            channel = MockRepository.GenerateStub<IPersistentChannel>();

            channelFactory.Stub(x => x.CreatePersistentChannel(connection)).Return(channel);
            channel.Stub(x => x.InvokeChannelAction(null,DateTime.UtcNow)).IgnoreArguments().WhenCalled(
                x => ((Action<IModel>)x.Arguments[0])(null));

            dispatcher = new ClientCommandDispatcher(connection, channelFactory);
        }
        public void SetUp()
        {
            var logger                = new ConsoleLogger();
            var eventBus              = new EventBus();
            var parser                = new ConnectionStringParser();
            var configuration         = parser.Parse("host=localhost");
            var hostSelectionStrategy = new RandomClusterHostSelectionStrategy <ConnectionFactoryInfo>();
            var connectionFactory     = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy);

            connection        = new PersistentConnection(connectionFactory, logger, eventBus);
            persistentChannel = new PersistentChannel(connection, logger, configuration, new EventBus());
        }
        public PersistentChannelTests()
        {
            var eventBus              = new EventBus();
            var parser                = new ConnectionStringParser();
            var configuration         = parser.Parse("host=localhost");
            var hostSelectionStrategy = new RandomClusterHostSelectionStrategy <ConnectionFactoryInfo>();
            var connectionFactory     = new ConnectionFactoryWrapper(configuration, hostSelectionStrategy);

            connection        = new PersistentConnection(connectionFactory, eventBus);
            persistentChannel = new PersistentChannel(connection, configuration, new EventBus());
            connection.Initialize();
        }
Exemple #18
0
 /// <summary>
 ///     Creates PullingConsumer
 /// </summary>
 /// <param name="options">The options</param>
 /// <param name="queue">The queue</param>
 /// <param name="channel">The channel</param>
 /// <param name="interceptor">The produce-consumer interceptor</param>
 public PullingConsumer(
     PullingConsumerOptions options,
     IQueue queue,
     IPersistentChannel channel,
     IProduceConsumeInterceptor interceptor
     )
 {
     this.queue       = queue;
     this.options     = options;
     this.channel     = channel;
     this.interceptor = interceptor;
 }
Exemple #19
0
        public ClientCommandDispatcherSingleton(
            ConnectionConfiguration configuration,
            IPersistentConnection connection,
            IPersistentChannelFactory persistentChannelFactory)
        {
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(persistentChannelFactory, "persistentChannelFactory");

            persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection);
            channelSemaphore  = new SemaphoreSlim(queueSize, queueSize);
        }
Exemple #20
0
        public void SetUp()
        {
            var connection     = MockRepository.GenerateStub <IPersistentConnection>();
            var channelFactory = MockRepository.GenerateStub <IPersistentChannelFactory>();

            channel = MockRepository.GenerateStub <IPersistentChannel>();

            channelFactory.Stub(x => x.CreatePersistentChannel(connection)).Return(channel);
            channel.Stub(x => x.InvokeChannelAction(null)).IgnoreArguments().WhenCalled(
                x => ((Action <IModel>)x.Arguments[0])(null));

            dispatcher = new ClientCommandDispatcher(connection, channelFactory);
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            channel = MockRepository.GenerateStub<IModel>();
            var configuration = new ConnectionConfiguration();
            eventBus = MockRepository.GenerateStub<IEventBus>();

            persistentConnection.Stub(x => x.CreateModel()).Return(channel);
            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"),DateTime.UtcNow );
        }
Exemple #22
0
        public When_a_channel_action_is_invoked()
        {
            persistentConnection = Substitute.For <IPersistentConnection>();
            channel = Substitute.For <IModel>();
            var configuration = new ConnectionConfiguration();

            eventBus = Substitute.For <IEventBus>();

            persistentConnection.CreateModel().Returns(channel);

            persistentChannel = new PersistentChannel(persistentConnection, configuration, eventBus);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Exemple #23
0
        public ClientCommandDispatcherSingleton(
            ConnectionConfiguration configuration,
            IPersistentConnection connection,
            IPersistentChannelFactory persistentChannelFactory)
        {
            Preconditions.CheckNotNull(configuration, "configuration");
            Preconditions.CheckNotNull(connection, "connection");
            Preconditions.CheckNotNull(persistentChannelFactory, "persistentChannelFactory");

            queue             = new BlockingCollection <Action>(configuration.DispatcherQueueSize);
            persistentChannel = persistentChannelFactory.CreatePersistentChannel(connection);

            StartDispatcherThread(configuration);
        }
        public void SetUp()
        {
            var parser = new ConnectionStringParser();
            var configuration = parser.Parse("host=localhost");
            var connection = MockRepository.GenerateStub<IPersistentConnection>();
            var channelFactory = MockRepository.GenerateStub<IPersistentChannelFactory>();
            channel = MockRepository.GenerateStub<IPersistentChannel>();

            channelFactory.Stub(x => x.CreatePersistentChannel(connection)).Return(channel);
            channel.Stub(x => x.InvokeChannelAction(null)).IgnoreArguments().WhenCalled(
                x => ((Action<IModel>)x.Arguments[0])(null));

            dispatcher = new ClientCommandDispatcher(configuration, connection, channelFactory);

        }
Exemple #25
0
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub <IPersistentConnection>();
            channel = MockRepository.GenerateStub <IModel>();
            var configuration = new ConnectionConfiguration();

            eventBus = MockRepository.GenerateStub <IEventBus>();

            persistentConnection.Stub(x => x.CreateModel()).Return(channel);
            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"));
        }
Exemple #26
0
        public When_an_action_is_invoked_that_throws()
        {
            var parser         = new ConnectionStringParser();
            var configuration  = parser.Parse("host=localhost");
            var connection     = Substitute.For <IPersistentConnection>();
            var channelFactory = Substitute.For <IPersistentChannelFactory>();

            channel = Substitute.For <IPersistentChannel>();

            channelFactory.CreatePersistentChannel(connection).Returns(channel);
            channel.WhenForAnyArgs(x => x.InvokeChannelAction(null))
            .Do(x => ((Action <IModel>)x[0])(null));

            dispatcher = new ClientCommandDispatcher(configuration, connection, channelFactory);
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub<IPersistentConnection>();
            channel = MockRepository.GenerateStub<IModel>();
            var eventBus = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.Stub(x => x.CreateModel()).Throw(exception).Repeat.Once();
            persistentConnection.Stub(x => x.CreateModel()).Return(channel).Repeat.Any();

            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"),DateTime.UtcNow );
        }
        public void SetUp()
        {
            persistentConnection = MockRepository.GenerateStub <IPersistentConnection>();
            channel = MockRepository.GenerateStub <IModel>();
            var eventBus      = new EventBus();
            var configuration = new ConnectionConfiguration();

            var shutdownArgs = new ShutdownEventArgs(
                ShutdownInitiator.Peer,
                AmqpException.ConnectionClosed,
                "connection closed by peer");
            var exception = new OperationInterruptedException(shutdownArgs);

            persistentConnection.Stub(x => x.CreateModel()).Throw(exception).Repeat.Once();
            persistentConnection.Stub(x => x.CreateModel()).Return(channel).Repeat.Any();

            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();

            persistentChannel = new PersistentChannel(persistentConnection, logger, configuration, eventBus);

            new Timer(_ => eventBus.Publish(new ConnectionCreatedEvent())).Change(10, Timeout.Infinite);

            persistentChannel.InvokeChannelAction(x => x.ExchangeDeclare("MyExchange", "direct"), DateTime.UtcNow);
        }