public async Task ShouldCarryOutRediscoveryWith43Server(int routerCount, int writerCount, int readerCount,
                                                                    string database, params string[] bookmarks)
            {
                // Given
                var routingContext = new Dictionary <string, string>
                {
                    { "address", "127.0.0.1:9001" },
                    { "region", "china" },
                    { "policy", "myp_policy" }
                };
                var recordFields = CreateGetServersDictionary(routerCount, writerCount, readerCount);
                var mockConn     = Setup43SocketConnection(routingContext, database, Bookmark.From(bookmarks), recordFields);

                mockConn.Setup(m => m.RoutingContext).Returns(routingContext);
                var manager = new ClusterDiscovery(routingContext, null);

                // When
                var table = await manager.DiscoverAsync(mockConn.Object, database, Bookmark.From(bookmarks));

                // Then
                table.Database.Should().Be(database ?? "");
                table.Readers.Count().Should().Be(readerCount);
                table.Writers.Count().Should().Be(writerCount);
                table.Routers.Count().Should().Be(routerCount);
                table.ExpireAfterSeconds.Should().Be(15000L);
                mockConn.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #2
0
            public async Task ShouldCarryOutRediscoveryWith32Server(int routerCount, int writerCount, int readerCount)
            {
                // Given
                var routingContext = new Dictionary <string, string>
                {
                    { "name", "molly" },
                    { "age", "1" },
                    { "color", "white" }
                };
                var recordFields = CreateGetServersResponseRecordFields(routerCount, writerCount, readerCount);
                var mockConn     = Setup32SocketConnection(routingContext, recordFields);

                mockConn.Setup(m => m.RoutingContext).Returns(routingContext);
                var manager = new ClusterDiscovery(routingContext, null);

                // When
                var table = await manager.DiscoverAsync(mockConn.Object, null, null, Bookmark.Empty);

                // Then
                table.Readers.Count().Should().Be(readerCount);
                table.Writers.Count().Should().Be(writerCount);
                table.Routers.Count().Should().Be(routerCount);
                table.ExpireAfterSeconds.Should().Be(15000L);
                mockConn.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #3
0
            public async Task ShouldThrowWhenRecordUnparsable()
            {
                // Given
                var connMock = SetupSocketConnection(new object[] { 1 });
                var manager  = new ClusterDiscovery(null, null);

                // When
                var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object));

                // Then
                exception.Should().BeOfType <ProtocolException>().Which.Message.Should()
                .Be("keys (2) does not equal to values (1)");
                connMock.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #4
0
            public async Task ShouldThrowWhenNoRecord()
            {
                // Given
                var connMock = SetupSocketConnection(new List <object[]>());
                var manager  = new ClusterDiscovery(null, null);

                // When
                var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object));

                // Then
                exception.Should().BeOfType <InvalidOperationException>().Which.Message.Should()
                .Be("The result is empty.");
                connMock.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #5
0
            public async Task ShouldThrowExceptionIfReaderIsEmpty()
            {
                // Given
                var procedureReplyRecordFields = CreateGetServersResponseRecordFields(3, 1, 0);
                var connMock = SetupSocketConnection(procedureReplyRecordFields);
                var manager  = new ClusterDiscovery(null, null);

                // When
                var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object));

                // Then
                exception.Should().BeOfType <ProtocolException>().Which.Message.Should()
                .Contain("3 routers, 1 writers and 0 readers.");
                connMock.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #6
0
            public async Task ShouldCarryOutRediscovery(int routerCount, int writerCount, int readerCount)
            {
                // Given
                var recordFields = CreateGetServersResponseRecordFields(routerCount, writerCount, readerCount);
                var connMock     = SetupSocketConnection(recordFields);
                var manager      = new ClusterDiscovery(null, null);

                // When
                var table = await manager.DiscoverAsync(connMock.Object);

                // Then
                table.Readers.Count().Should().Be(readerCount);
                table.Writers.Count().Should().Be(writerCount);
                table.Routers.Count().Should().Be(routerCount);
                table.ExpireAfterSeconds.Should().Be(9223372036854775807);
                connMock.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #7
0
            public async Task ShouldProtocolErrorWhenMultipleRecord()
            {
                // Given
                var connMock = SetupSocketConnection(new List <object[]>
                {
                    CreateGetServersResponseRecordFields(3, 2, 1),
                    CreateGetServersResponseRecordFields(3, 2, 1)
                });
                var manager = new ClusterDiscovery(null, null);

                // When
                var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object));

                // Then
                exception.Should().BeOfType <InvalidOperationException>().Which.Message.Should()
                .Be("The result contains more than one element.");
                connMock.Verify(x => x.CloseAsync(), Times.Once);
            }
Beispiel #8
0
            public async Task ShouldThrowWhenProcedureNotFound()
            {
                // Given
                var pairs = new List <Tuple <IRequestMessage, IResponseMessage> >
                {
                    MessagePair(
                        new RunMessage("CALL dbms.cluster.routing.getServers", new Dictionary <string, object>()),
                        new FailureMessage("Neo.ClientError.Procedure.ProcedureNotFound", "not found")),
                    MessagePair(PullAll, Ignored)
                };

                var connMock = new MockedConnection(pairs).MockConn;
                var manager  = new ClusterDiscovery(null, null);

                // When
                var exception = await Record.ExceptionAsync(() => manager.DiscoverAsync(connMock.Object));

                // Then
                exception.Should().BeOfType <ClientException>().Which.Message.Should()
                .Contain("not found");
                connMock.Verify(x => x.CloseAsync(), Times.Once);
            }