Ejemplo n.º 1
0
        public void Should_fail_over_to_next_node_if_there_is_ConnectionFailureException()
        {
            // Arrange
            var retryPolicty = Substitute.For <IRetryPolicy>();
            var connection   = new HaConnection(retryPolicty,
                                                Substitute.For <IRabbitWatcher>(),
                                                new List <ManagedConnectionFactory> {
                new ManagedConnectionFactory()
            });

            connection.ConnectionFactories.ClearAll();
            var f1 = CreateManagedConnectionFactory(5671, new Exception());
            var f2 = CreateManagedConnectionFactory(5672, new Exception());
            var f3 = CreateManagedConnectionFactory(5673, new BrokerUnreachableException(new Dictionary <AmqpTcpEndpoint, int>(), new Dictionary <AmqpTcpEndpoint, Exception>(), new Exception()));

            connection.ConnectionFactories.Add(f1);
            connection.ConnectionFactories.Add(f2);
            connection.ConnectionFactories.Add(f3);

            // Action
            connection.Connect();

            // Assert
            f1.Received(1).CreateConnection();
            f2.Received(1).CreateConnection();
            f3.Received(1).CreateConnection();
            retryPolicty.Received(1).WaitForNextRetry(Arg.Any <Action>());
        }
Ejemplo n.º 2
0
        public void Should_fire_connected_event_when_connect_successfully()
        {
            // Arrange
            var are          = new AutoResetEvent(false);
            var retryPolicty = Substitute.For <IRetryPolicy>();
            var connection   = new HaConnection(retryPolicty,
                                                Substitute.For <IRabbitWatcher>(),
                                                new List <ManagedConnectionFactory> {
                new ManagedConnectionFactory()
            });

            connection.Connected += () => are.Set();
            connection.ConnectionFactories.ClearAll();
            var f1 = CreateManagedConnectionFactory(5671);
            var f2 = CreateManagedConnectionFactory(5672);

            connection.ConnectionFactories.Add(f1);
            connection.ConnectionFactories.Add(f2);

            // Action
            connection.Connect();
            are.WaitOne();

            // Assert
            retryPolicty.Received(1).Reset();
            f1.Received(1).CreateConnection();
        }