Skip to content

Commit 1fdfe68

Browse files
committed
Migrate Java IT tests to Testkit
Migrated tests: - `CausalClusteringIT.shouldNotReuseReadConnectionForWriteTransaction` -> `TestBookmarks.test_does_not_use_read_connection_for_write` - `CausalClusteringIT.shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfLeader` -> `Routing.test_should_get_rt_from_leader_w_and_r_via_leader_using_session_run` - `CausalClusteringIT.shouldExecuteReadAndWritesWhenDriverSuppliedWithAddressOfFollower` -> `Routing.test_should_get_rt_from_follower_w_and_r_via_leader_using_session_run` - `CausalClusteringIT.shouldDropBrokenOldConnections` -> `Routing.test_should_drop_connections_failing_liveness_check` - `CausalClusteringIT.shouldRespectMaxConnectionPoolSizePerClusterMember` -> `Routing.test_should_enforce_pool_size_per_cluster_member` Converted tests: - `CausalClusteringIT.shouldExecuteReadAndWritesWhenRouterIsDiscovered` -> `GraphDatabaseTest.shouldNotFailRoutingDriverWhenThereIsWorkingUri` New Testkit features: - `Feature:API:Liveness.Check` - `Temporary:DriverMaxConnectionPoolSize` - `Temporary:ConnectionAcquisitionTimeout` - `Temporary:GetConnectionPoolMetrics` The `address` field has been added to `Summary` Testkit response.
1 parent bc95327 commit 1fdfe68

File tree

10 files changed

+201
-325
lines changed

10 files changed

+201
-325
lines changed

driver/src/main/java/org/neo4j/driver/internal/metrics/InternalConnectionPoolMetrics.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,20 @@ public long acquired()
219219
return this.acquired.get();
220220
}
221221

222-
223222
@Override
224223
public String toString()
225224
{
226225
return format( "%s=[created=%s, closed=%s, creating=%s, failedToCreate=%s, acquiring=%s, acquired=%s, " +
227-
"timedOutToAcquire=%s, inUse=%s, idle=%s, " +
228-
"totalAcquisitionTime=%s, totalConnectionTime=%s, totalInUseTime=%s, totalInUseCount=%s]",
229-
id(), created(), closed(), creating(), failedToCreate(), acquiring(), acquired(),
230-
timedOutToAcquire(), inUse(), idle(),
231-
totalAcquisitionTime(), totalConnectionTime(), totalInUseTime(), totalInUseCount() );
226+
"timedOutToAcquire=%s, inUse=%s, idle=%s, " +
227+
"totalAcquisitionTime=%s, totalConnectionTime=%s, totalInUseTime=%s, totalInUseCount=%s]",
228+
id(), created(), closed(), creating(), failedToCreate(), acquiring(), acquired(),
229+
timedOutToAcquire(), inUse(), idle(),
230+
totalAcquisitionTime(), totalConnectionTime(), totalInUseTime(), totalInUseCount() );
231+
}
232+
233+
// This method is for purposes testing only
234+
public BoltServerAddress getAddress()
235+
{
236+
return address;
232237
}
233238
}

driver/src/test/java/org/neo4j/driver/GraphDatabaseTest.java

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.io.IOException;
2525
import java.net.ServerSocket;
2626
import java.net.URI;
27+
import java.util.Arrays;
28+
import java.util.Iterator;
2729
import java.util.List;
2830

2931
import org.neo4j.driver.exceptions.ServiceUnavailableException;
@@ -73,7 +75,7 @@ void shouldLogWhenUnableToCreateRoutingDriver()
7375
when( logging.getLog( any( Class.class ) ) ).thenReturn( logger );
7476
InternalDriver driver = mock( InternalDriver.class );
7577
doThrow( ServiceUnavailableException.class ).when( driver ).verifyConnectivity();
76-
DriverFactory driverFactory = new MockSupplyingDriverFactory( driver );
78+
DriverFactory driverFactory = new MockSupplyingDriverFactory( Arrays.asList( driver, driver ) );
7779
Config config = Config.builder()
7880
.withLogging( logging )
7981
.build();
@@ -85,10 +87,35 @@ void shouldLogWhenUnableToCreateRoutingDriver()
8587
assertThrows( ServiceUnavailableException.class, () -> GraphDatabase.routingDriver( routingUris, AuthTokens.none(), config, driverFactory ) );
8688

8789
verify( logger ).warn( eq( "Unable to create routing driver for URI: neo4j://localhost:9001" ),
88-
any( Throwable.class ) );
90+
any( Throwable.class ) );
8991

9092
verify( logger ).warn( eq( "Unable to create routing driver for URI: neo4j://localhost:9002" ),
91-
any( Throwable.class ) );
93+
any( Throwable.class ) );
94+
}
95+
96+
@Test
97+
void shouldNotFailRoutingDriverWhenThereIsWorkingUri()
98+
{
99+
Logging logging = mock( Logging.class );
100+
Logger logger = mock( Logger.class );
101+
when( logging.getLog( any( Class.class ) ) ).thenReturn( logger );
102+
InternalDriver failingDriver = mock( InternalDriver.class );
103+
doThrow( ServiceUnavailableException.class ).when( failingDriver ).verifyConnectivity();
104+
InternalDriver workingDriver = mock( InternalDriver.class );
105+
DriverFactory driverFactory = new MockSupplyingDriverFactory( Arrays.asList( failingDriver, workingDriver ) );
106+
Config config = Config.builder()
107+
.withLogging( logging )
108+
.build();
109+
110+
List<URI> routingUris = asList(
111+
URI.create( "neo4j://localhost:9001" ),
112+
URI.create( "neo4j://localhost:9002" ) );
113+
114+
Driver driver = GraphDatabase.routingDriver( routingUris, AuthTokens.none(), config, driverFactory );
115+
116+
verify( logger ).warn( eq( "Unable to create routing driver for URI: neo4j://localhost:9001" ),
117+
any( Throwable.class ) );
118+
assertEquals( driver, workingDriver );
92119
}
93120

94121
@Test
@@ -184,19 +211,19 @@ private static Config createConfig( boolean encrypted, int timeoutMillis )
184211

185212
private static class MockSupplyingDriverFactory extends DriverFactory
186213
{
187-
private final InternalDriver driver;
214+
private final Iterator<InternalDriver> driverIterator;
188215

189-
private MockSupplyingDriverFactory( InternalDriver driver )
216+
private MockSupplyingDriverFactory( List<InternalDriver> drivers )
190217
{
191-
this.driver = driver;
218+
driverIterator = drivers.iterator();
192219
}
193220

194221
@Override
195222
protected InternalDriver createRoutingDriver( SecurityPlan securityPlan, BoltServerAddress address, ConnectionPool connectionPool,
196223
EventExecutorGroup eventExecutorGroup, RoutingSettings routingSettings, RetryLogic retryLogic,
197224
MetricsProvider metricsProvider, Config config )
198225
{
199-
return driver;
226+
return driverIterator.next();
200227
}
201228
}
202229
}

0 commit comments

Comments
 (0)