Пример #1
0
        public void GetConnection_PreviousConnectionStillOpen_ReturnsPreviousConnection()
        {
            var subject = new RabbitMqConnectionService(ConnectionTestHelper.ValidConfiguration);

            var consecutiveConnections = subject.GetConnection(_noRetryOptions)
                                         .Bind(first => subject.GetConnection(_noRetryOptions).Map(second => (first, second)));

            ConnectionTestHelper.CloseConnections(consecutiveConnections);

            consecutiveConnections.ShouldBeSuccess(connections => ReferenceEquals(connections.first, connections.second).Should().BeTrue());
        }
Пример #2
0
        public void GetConnection_ValidConfiguration_Connects()
        {
            var subject = new RabbitMqConnectionService(ConnectionTestHelper.ValidConfiguration);

            var result = subject.GetConnection(_noRetryOptions);

            result.ShouldBeSuccess(x =>
            {
                x.IsOpen.Should().BeTrue();
                using (var model = x.CreateModel()) model.ExchangeDeclarePassive("amq.direct");
            });
            ConnectionTestHelper.CloseConnection(result);
        }
Пример #3
0
        public void GetConnection_InvalidConfiguration_Fails(string userName, string password, string hostName, string virtualHost)
        {
            var invalidConfig = new RabbitMqConnectionConfiguration
            {
                UserName    = userName,
                Password    = password,
                HostName    = hostName,
                VirtualHost = virtualHost
            };
            var subject = new RabbitMqConnectionService(invalidConfig);

            var result = subject.GetConnection(_noRetryOptions);

            result.ShouldBeFail(ex => ex.Should().BeOfType <BrokerUnreachableException>());
        }
Пример #4
0
        public void GetConnection_Fails_Retries()
        {
            var config = ConnectionTestHelper.ValidConfiguration;

            config.Password = "******";
            int       numberOfRetries   = 0;
            var       subject           = new RabbitMqConnectionService(config);
            var       cancelSource      = new CancellationTokenSource();
            const int connectionTimeout = 5;

            var connection = subject.GetConnection(new EstablishConnectionOptions(OnRetry, TimeSpan.FromMilliseconds(connectionTimeout), true, token: cancelSource.Token));

            cancelSource.CancelAfter(connectionTimeout * 10);
            connection.ShouldBeFail(ex => ex.Should().BeOfType <OperationCanceledException>());

            numberOfRetries.Should().BeGreaterThan(0);

            void OnRetry(int retryCounter) => numberOfRetries = retryCounter;
        }