Esempio n. 1
0
        internal static IConnection Setup32SocketConnection(IDictionary <string, string> routingContext,
                                                            object[] recordFields, Mock <ISocketClient> clientMock)
        {
            var pairs = new List <Tuple <IRequestMessage, IResponseMessage> >
            {
                MessagePair(InitMessage(), SuccessMessage()),
                MessagePair(new RunMessage("CALL dbms.cluster.routing.getRoutingTable({context})",
                                           new Dictionary <string, object> {
                    { "context", routingContext }
                }),
                            SuccessMessage(new List <object> {
                    "ttl", "servers"
                })),
                MessagePair(new RecordMessage(recordFields)),
                MessagePair(PullAllMessage(), SuccessMessage())
            };

            var mock       = new MockedMessagingClient(pairs, clientMock);
            var serverInfo = new ServerInfo(new Uri("bolt://123:456"));
            var conn       = SocketConnectionTests.NewSocketConnection(mock.Client, server: serverInfo);

            conn.Init();
            serverInfo.Version = "Neo4j/3.2.2";
            return(conn);
        }
Esempio n. 2
0
            public void ShouldServiceUnavailableWhenProcedureNotFound()
            {
                // Given
                var pairs = new List <Tuple <IRequestMessage, IResponseMessage> >
                {
                    MessagePair(InitMessage(), SuccessMessage()),
                    MessagePair(new RunMessage("CALL dbms.cluster.routing.getServers"),
                                new FailureMessage("Neo.ClientError.Procedure.ProcedureNotFound", "not found")),
                    MessagePair(PullAllMessage(), new IgnoredMessage())
                };

                var messagingClient = new MockedMessagingClient(pairs);
                var conn            = SocketConnectionTests.NewSocketConnection(messagingClient.Client);

                conn.Init();

                var manager = CreateDiscoveryManager(conn, null);

                // When
                var exception = Record.Exception(() => manager.Rediscovery());

                // Then
                exception.Should().BeOfType <ServiceUnavailableException>();
                exception.Message.Should().StartWith("Error when calling `getServers` procedure: ");
                messagingClient.ClientMock.Verify(x => x.Stop(), Times.Once);
            }
Esempio n. 3
0
            public void ShouldNotReportErrorIfIsOtherExceptions()
            {
                var mockResponseHandler = new Mock <IMessageResponseHandler>();
                var con = new PooledConnection(SocketConnectionTests.NewSocketConnection(handler: mockResponseHandler.Object));

                mockResponseHandler.Setup(x => x.Error).Returns(new ClientException("BLAH", "lalala"));
                con.HasUnrecoverableError.Should().BeFalse();
            }
Esempio n. 4
0
            public void ShouldBeFalseWhenConnectionHasUnrecoverableError()
            {
                var mockClient = new Mock <ISocketClient>();

                mockClient.Setup(x => x.IsOpen).Returns(false);
                var mockResponseHandler = new Mock <IMessageResponseHandler>();

                mockResponseHandler.Setup(x => x.Error).Returns(new DatabaseException());  // unrecoverable error

                var conn = new PooledConnection(SocketConnectionTests.NewSocketConnection(mockClient.Object, mockResponseHandler.Object));

                conn.IsOpen.Should().BeFalse();
            }
Esempio n. 5
0
            public void ShouldReturnTrueWhenIsHealthy()
            {
                var mockClient = new Mock <ISocketClient>();

                mockClient.Setup(x => x.IsOpen).Returns(true);
                var mockResponseHandler = new Mock <IMessageResponseHandler>();

                mockResponseHandler.Setup(x => x.Error).Returns(new ClientException());  // has no unrecoverable error

                var conn = new PooledConnection(SocketConnectionTests.NewSocketConnection(mockClient.Object, mockResponseHandler.Object));

                conn.IsOpen.Should().BeTrue();
            }
Esempio n. 6
0
            public void ShouldReportErrorIfIsDatabaseException()
            {
                var mockResponseHandler = new Mock <IMessageResponseHandler>();
                var con = new PooledConnection(SocketConnectionTests.NewSocketConnection(handler: mockResponseHandler.Object));

                mockResponseHandler.Setup(x => x.HasError).Returns(true);
                mockResponseHandler.Setup(x => x.Error).Returns(new DatabaseException("BLAH", "lalala"));

                var exception = Record.Exception(() => con.ReceiveOne());

                exception.Should().BeOfType <DatabaseException>();
                exception.Message.Should().Be("lalala");

                con.HasUnrecoverableError.Should().BeTrue();
                mockResponseHandler.VerifySet(x => x.Error = null, Times.Once);
            }
Esempio n. 7
0
        internal static IConnection SetupSocketConnection(List <object[]> recordFieldsList,
                                                          Mock <ISocketClient> clientMock)
        {
            var pairs = new List <Tuple <IRequestMessage, IResponseMessage> >
            {
                MessagePair(InitMessage(), SuccessMessage()),
                MessagePair(new RunMessage("CALL dbms.cluster.routing.getServers", new Dictionary <string, object>()),
                            SuccessMessage(new List <object> {
                    "ttl", "servers"
                }))
            };

            foreach (var recordFields in recordFieldsList)
            {
                pairs.Add(MessagePair(new RecordMessage(recordFields)));
            }
            pairs.Add(MessagePair(PullAllMessage(), SuccessMessage()));

            var mock = new MockedMessagingClient(pairs, clientMock);
            var conn = SocketConnectionTests.NewSocketConnection(mock.Client);

            conn.Init();
            return(conn);
        }