Skip to content

Commit

Permalink
Refactoring to pull RoutingTable and Rediscovery in to RoutingTableMa…
Browse files Browse the repository at this point in the history
…nager to simplify the logic in LoadBalancer.
  • Loading branch information
Zhen Li committed Jul 13, 2017
1 parent 71bce90 commit 2496a81
Show file tree
Hide file tree
Showing 13 changed files with 990 additions and 848 deletions.
1 change: 1 addition & 0 deletions Neo4j.Driver/Neo4j.Driver.Tests/Neo4j.Driver.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<Compile Include="Connector\PooledConnectionTests.cs" />
<Compile Include="Result\ResultReaderBuilderTests.cs" />
<Compile Include="Result\StatementResultReaderTests.cs" />
<Compile Include="Routing\RoutingTableManagerTests.cs" />
<Compile Include="TestUtil\NetworkExtensionsTests.cs" />
<Compile Include="Result\SummaryBuilderTests.cs" />
<Compile Include="RetryLogicTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Moq;
Expand All @@ -32,6 +33,23 @@ public class ClusterConnectionPoolTests
{
private static Uri ServerUri { get; } = new Uri("bolt+routing://1234:5678");

public class Constructor
{
[Fact]
public void ShouldEnsureInitialRouter()
{
var uris = new HashSet<Uri>{new Uri("bolt://123:456")};
var config = Config.DefaultConfig;
var connSettings = new ConnectionSettings(ServerUri, new Mock<IAuthToken>().Object, config);
var poolSettings = new ConnectionPoolSettings(config);

var pool = new ClusterConnectionPool(connSettings, poolSettings, uris, null);

pool.ToString().Should().Be(
"[{bolt://123:456/ : _availableConnections: {[]}, _inUseConnections: {[]}}]");
}
}

public class TryAcquireMethod
{
[Fact]
Expand Down
737 changes: 131 additions & 606 deletions Neo4j.Driver/Neo4j.Driver.Tests/Routing/LoadBalancerTests.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using FluentAssertions;
using Moq;
using Neo4j.Driver.Internal;
using Neo4j.Driver.Internal.Routing;
using Neo4j.Driver.V1;
using Xunit;
Expand All @@ -36,6 +39,23 @@ private static IEnumerable<Uri> CreateUriArray(int count)
return uris;
}

public class Constructor
{
[Fact]
public void ShouldEnsureInitialRouter()
{
var initUri = new Uri("bolt://123:456");
var routers = new HashSet<Uri>{initUri};
var table = new RoundRobinRoutingTable(routers);

Uri uri;
table.TryNextRouter(out uri).Should().BeTrue();
uri.Should().Be(initUri);

table.All().Single().Should().Be(initUri);
}
}

public class IsStatleMethod
{
[Theory] [InlineData(1, 2, 1, 5 * 60, false)] // 1 router, 2 reader, 1 writer
Expand All @@ -49,7 +69,6 @@ public void ShouldBeStaleInReadModeIfOnlyHaveOneRouter(int routerCount, int read
CreateUriArray(routerCount),
CreateUriArray(readerCount),
CreateUriArray(writerCount),
new Stopwatch(),
expireAfterSeconds);
table.IsStale(AccessMode.Read).Should().Be(isStale);
}
Expand All @@ -66,7 +85,6 @@ public void ShouldBeStaleInWriteModeIfOnlyHaveOneRouter(int routerCount, int rea
CreateUriArray(routerCount),
CreateUriArray(readerCount),
CreateUriArray(writerCount),
new Stopwatch(),
expireAfterSeconds);
table.IsStale(AccessMode.Write).Should().Be(isStale);
}
Expand All @@ -82,7 +100,7 @@ public void ShouldInjectInFront()
CreateUriArray(3),
CreateUriArray(0),
CreateUriArray(0),
new Stopwatch(), 5 * 60);
5 * 60);
Uri router;
table.TryNextRouter(out router);
var head = new Uri("http://neo4j:10");
Expand All @@ -102,6 +120,5 @@ public void ShouldInjectInFront()
router.Should().Be(head);
}
}

}
}
Loading

0 comments on commit 2496a81

Please sign in to comment.