Ejemplo n.º 1
0
            public void ShouldThrowErrorDirectlyIfProtocolError(AccessMode mode)
            {
                // Given
                var uri = new Uri("neo4j://123:456");
                var routingTableMock = NewMockedRoutingTable(mode, uri);
                var mock             = new Mock <IRoutingTableManager>();

                mock.Setup(x => x.EnsureRoutingTableForModeAsync(mode, null, Bookmark.Empty))
                .ReturnsAsync(routingTableMock.Object);

                var clusterConnPoolMock = new Mock <IClusterConnectionPool>();

                clusterConnPoolMock.Setup(x => x.AcquireAsync(uri, mode, null, Bookmark.Empty)).Returns(
                    Task.FromException <IConnection>(new ProtocolException("do not understand struct 0x01")));

                var balancer = new LoadBalancer(clusterConnPoolMock.Object, mock.Object);

                // When
                balancer.Awaiting(b => b.AcquireAsync(mode, null, Bookmark.Empty)).Should().Throw <ProtocolException>()
                .WithMessage("*do not understand struct 0x01*");

                // while the server is not removed
                routingTableMock.Verify(m => m.Remove(uri), Times.Never);
                clusterConnPoolMock.Verify(m => m.DeactivateAsync(uri), Times.Never);
            }
Ejemplo n.º 2
0
            public void ShouldForgetServerWhenFailedToEstablishConn(AccessMode mode)
            {
                // Given
                var uri = new Uri("neo4j://123:456");
                var routingTableMock = NewMockedRoutingTable(mode, uri);
                var mock             = new Mock <IRoutingTableManager>();

                mock.Setup(x => x.EnsureRoutingTableForModeAsync(mode, null, Bookmark.Empty))
                .ReturnsAsync(routingTableMock.Object);
                mock.Setup(x => x.ForgetServer(It.IsAny <Uri>(), null))
                .Callback((Uri u, string database) => routingTableMock.Object.Remove(u));
                mock.Setup(x => x.ForgetWriter(It.IsAny <Uri>(), null))
                .Callback((Uri u, string database) => routingTableMock.Object.RemoveWriter(u));

                var clusterConnPoolMock = new Mock <IClusterConnectionPool>();

                clusterConnPoolMock.Setup(x => x.AcquireAsync(uri, mode, null, Bookmark.Empty))
                .Returns(Task.FromException <IConnection>(new ServiceUnavailableException("failed init")));

                var balancer = new LoadBalancer(clusterConnPoolMock.Object, mock.Object);

                // When & Then
                balancer.Awaiting(b => b.AcquireAsync(mode, null, Bookmark.Empty)).Should()
                .Throw <SessionExpiredException>().WithMessage("Failed to connect to any*");

                // should be removed
                routingTableMock.Verify(m => m.Remove(uri), Times.Once);
                clusterConnPoolMock.Verify(m => m.DeactivateAsync(uri), Times.Once);
            }