Skip to content

Commit

Permalink
Merge pull request #198 from zhenlineo/1.5-async-routing-driver
Browse files Browse the repository at this point in the history
Refactoring to prepare for async methods
  • Loading branch information
zhenlineo committed Jul 14, 2017
2 parents f05ae55 + cff5165 commit 745e22b
Show file tree
Hide file tree
Showing 13 changed files with 966 additions and 850 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 @@ -117,6 +117,7 @@
<Compile Include="Result\SummaryCollectorTests.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
721 changes: 115 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 745e22b

Please sign in to comment.