2525
2626import java .io .IOException ;
2727import java .net .URI ;
28- import java .net .URL ;
2928import java .util .Arrays ;
3029import java .util .List ;
3130import java .util .Set ;
5857import static org .junit .Assert .assertTrue ;
5958import static org .junit .Assert .fail ;
6059
61- @ Ignore
6260public class RoutingDriverStubTest
6361{
6462 @ Rule
@@ -70,7 +68,7 @@ public class RoutingDriverStubTest
7068 public void shouldDiscoverServers () throws IOException , InterruptedException , StubServer .ForceKilled
7169 {
7270 // Given
73- StubServer server = StubServer .start ( resource ( "discover_servers.script" ) , 9001 );
71+ StubServer server = StubServer .start ( "discover_servers.script" , 9001 );
7472 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
7573
7674 // When
@@ -89,7 +87,7 @@ public void shouldDiscoverServers() throws IOException, InterruptedException, St
8987 public void shouldDiscoverNewServers () throws IOException , InterruptedException , StubServer .ForceKilled
9088 {
9189 // Given
92- StubServer server = StubServer .start ( resource ( "discover_new_servers.script" ) , 9001 );
90+ StubServer server = StubServer .start ( "discover_new_servers.script" , 9001 );
9391 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
9492 BoltServerAddress seed = address ( 9001 );
9593
@@ -110,7 +108,7 @@ public void shouldDiscoverNewServers() throws IOException, InterruptedException,
110108 public void shouldHandleEmptyResponse () throws IOException , InterruptedException , StubServer .ForceKilled
111109 {
112110 // Given
113- StubServer server = StubServer .start ( resource ( "handle_empty_response.script" ) , 9001 );
111+ StubServer server = StubServer .start ( "handle_empty_response.script" , 9001 );
114112 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
115113 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config ) )
116114 {
@@ -127,10 +125,10 @@ public void shouldHandleEmptyResponse() throws IOException, InterruptedException
127125 public void shouldHandleAcquireReadSession () throws IOException , InterruptedException , StubServer .ForceKilled
128126 {
129127 // Given
130- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
128+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
131129
132130 //START a read server
133- StubServer readServer = StubServer .start ( resource ( "read_server.script" ) , 9005 );
131+ StubServer readServer = StubServer .start ( "read_server.script" , 9005 );
134132 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
135133 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
136134 Session session = driver .session ( AccessMode .READ ) )
@@ -156,11 +154,11 @@ public String apply( Record record )
156154 public void shouldRoundRobinReadServers () throws IOException , InterruptedException , StubServer .ForceKilled
157155 {
158156 // Given
159- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
157+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
160158
161159 //START two read servers
162- StubServer readServer1 = StubServer .start ( resource ( "read_server.script" ) , 9005 );
163- StubServer readServer2 = StubServer .start ( resource ( "read_server.script" ) , 9006 );
160+ StubServer readServer1 = StubServer .start ( "read_server.script" , 9005 );
161+ StubServer readServer2 = StubServer .start ( "read_server.script" , 9006 );
164162 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
165163 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config ) )
166164 {
@@ -195,10 +193,10 @@ public void shouldThrowSessionExpiredIfReadServerDisappears()
195193 exception .expectMessage ( "Server at 127.0.0.1:9005 is no longer available" );
196194
197195 // Given
198- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
196+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
199197
200198 //START a read server
201- StubServer .start ( resource ( "dead_server.script" ) , 9005 );
199+ StubServer .start ( "dead_server.script" , 9005 );
202200 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
203201 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
204202 Session session = driver .session ( AccessMode .READ ) )
@@ -218,10 +216,10 @@ public void shouldThrowSessionExpiredIfWriteServerDisappears()
218216 //exception.expectMessage( "Server at 127.0.0.1:9006 is no longer available" );
219217
220218 // Given
221- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
219+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
222220
223221 //START a dead write servers
224- StubServer .start ( resource ( "dead_server.script" ) , 9007 );
222+ StubServer .start ( "dead_server.script" , 9007 );
225223 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
226224 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
227225 Session session = driver .session ( AccessMode .WRITE ) )
@@ -236,10 +234,10 @@ public void shouldThrowSessionExpiredIfWriteServerDisappears()
236234 public void shouldHandleAcquireWriteSession () throws IOException , InterruptedException , StubServer .ForceKilled
237235 {
238236 // Given
239- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
237+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
240238
241239 //START a write server
242- StubServer writeServer = StubServer .start ( resource ( "write_server.script" ) , 9007 );
240+ StubServer writeServer = StubServer .start ( "write_server.script" , 9007 );
243241 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
244242 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
245243 Session session = driver .session ( AccessMode .WRITE ) )
@@ -255,11 +253,11 @@ public void shouldHandleAcquireWriteSession() throws IOException, InterruptedExc
255253 public void shouldRoundRobinWriteSessions () throws IOException , InterruptedException , StubServer .ForceKilled
256254 {
257255 // Given
258- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
256+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
259257
260258 //START a write server
261- StubServer writeServer1 = StubServer .start ( resource ( "write_server.script" ) , 9007 );
262- StubServer writeServer2 = StubServer .start ( resource ( "write_server.script" ) , 9008 );
259+ StubServer writeServer1 = StubServer .start ( "write_server.script" , 9007 );
260+ StubServer writeServer2 = StubServer .start ( "write_server.script" , 9008 );
263261 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
264262 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config ) )
265263 {
@@ -281,10 +279,10 @@ public void shouldRoundRobinWriteSessions() throws IOException, InterruptedExcep
281279 public void shouldRememberEndpoints () throws IOException , InterruptedException , StubServer .ForceKilled
282280 {
283281 // Given
284- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
282+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
285283
286284 //START a read server
287- StubServer readServer = StubServer .start ( resource ( "read_server.script" ) , 9005 );
285+ StubServer readServer = StubServer .start ( "read_server.script" , 9005 );
288286 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
289287 try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
290288 Session session = driver .session ( AccessMode .READ ) )
@@ -304,10 +302,10 @@ public void shouldRememberEndpoints() throws IOException, InterruptedException,
304302 public void shouldForgetEndpointsOnFailure () throws IOException , InterruptedException , StubServer .ForceKilled
305303 {
306304 // Given
307- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
305+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
308306
309307 //START a read server
310- StubServer .start ( resource ( "dead_server.script" ) , 9005 );
308+ StubServer .start ( "dead_server.script" , 9005 );
311309 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
312310 RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
313311 try
@@ -336,11 +334,11 @@ public void shouldRediscoverIfNecessaryOnSessionAcquisition()
336334 throws IOException , InterruptedException , StubServer .ForceKilled
337335 {
338336 // Given
339- StubServer server = StubServer .start ( resource ( "rediscover.script" ) , 9001 );
337+ StubServer server = StubServer .start ( "rediscover.script" , 9001 );
340338
341339 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
342340 //START a read server
343- StubServer read = StubServer .start ( resource ( "empty.script" ) , 9005 );
341+ StubServer read = StubServer .start ( "empty.script" , 9005 );
344342
345343 //On creation we only find ourselves
346344 RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
@@ -365,11 +363,11 @@ public void shouldRediscoverIfNecessaryOnSessionAcquisition()
365363 public void shouldOnlyGetServersOnce () throws IOException , InterruptedException , StubServer .ForceKilled
366364 {
367365 // Given
368- StubServer server = StubServer .start ( resource ( "rediscover.script" ) , 9001 );
366+ StubServer server = StubServer .start ( "rediscover.script" , 9001 );
369367
370368 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
371369 //START a read server
372- StubServer read = StubServer .start ( resource ( "empty.script" ) , 9005 );
370+ StubServer read = StubServer .start ( "empty.script" , 9005 );
373371
374372 //On creation we only find ourselves
375373 final RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
@@ -410,7 +408,7 @@ public void shouldFailOnNonDiscoverableServer() throws IOException, InterruptedE
410408 exception .expect ( ServiceUnavailableException .class );
411409
412410 // Given
413- StubServer .start ( resource ( "non_discovery_server.script" ) , 9001 );
411+ StubServer .start ( "non_discovery_server.script" , 9001 );
414412 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
415413
416414 // When
@@ -424,7 +422,7 @@ public void shouldFailRandomFailureInGetServers() throws IOException, Interrupte
424422 exception .expect ( ServiceUnavailableException .class );
425423
426424 // Given
427- StubServer .start ( resource ( "failed_discovery.script" ) , 9001 );
425+ StubServer .start ( "failed_discovery.script" , 9001 );
428426 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
429427
430428 // When
@@ -436,10 +434,10 @@ public void shouldHandleLeaderSwitchWhenWriting()
436434 throws IOException , InterruptedException , StubServer .ForceKilled
437435 {
438436 // Given
439- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
437+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
440438
441439 //START a write server that doesn't accept writes
442- StubServer .start ( resource ( "not_able_to_write_server.script" ) , 9007 );
440+ StubServer .start ( "not_able_to_write_server.script" , 9007 );
443441 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
444442 RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
445443 boolean failed = false ;
@@ -468,10 +466,10 @@ public void shouldHandleLeaderSwitchWhenWriting()
468466 public void shouldRediscoverOnExpiry () throws IOException , InterruptedException , StubServer .ForceKilled
469467 {
470468 // Given
471- StubServer server = StubServer .start ( resource ( "expire.script" ) , 9001 );
469+ StubServer server = StubServer .start ( "expire.script" , 9001 );
472470
473471 //START a read server
474- StubServer readServer = StubServer .start ( resource ( "empty.script" ) , 9005 );
472+ StubServer readServer = StubServer .start ( "empty.script" , 9005 );
475473 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
476474 RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
477475 assertThat (driver .routingServers (), contains (address ( 9001 )));
@@ -494,12 +492,12 @@ public void shouldRediscoverOnExpiry() throws IOException, InterruptedException,
494492 public void shouldNotPutBackPurgedConnection () throws IOException , InterruptedException , StubServer .ForceKilled
495493 {
496494 // Given
497- StubServer server = StubServer .start ( resource ( "not_reuse_connection.script" ) , 9001 );
495+ StubServer server = StubServer .start ( "not_reuse_connection.script" , 9001 );
498496
499497 //START servers
500- StubServer readServer = StubServer .start ( resource ( "empty.script" ) , 9002 );
501- StubServer writeServer1 = StubServer .start ( resource ( "dead_server.script" ) , 9003 );
502- StubServer writeServer2 = StubServer .start ( resource ( "empty.script" ) , 9006 );
498+ StubServer readServer = StubServer .start ( "empty.script" , 9002 );
499+ StubServer writeServer1 = StubServer .start ( "dead_server.script" , 9003 );
500+ StubServer writeServer2 = StubServer .start ( "empty.script" , 9006 );
503501 URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
504502
505503 RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
@@ -548,16 +546,6 @@ public void shouldNotPutBackPurgedConnection() throws IOException, InterruptedEx
548546 assertThat ( writeServer2 .exitStatus (), equalTo ( 0 ) );
549547 }
550548
551- String resource ( String fileName )
552- {
553- URL resource = RoutingDriverStubTest .class .getClassLoader ().getResource ( fileName );
554- if ( resource == null )
555- {
556- fail ( fileName + " does not exists" );
557- }
558- return resource .getFile ();
559- }
560-
561549 private BoltServerAddress address ( int port )
562550 {
563551 return new BoltServerAddress ( "127.0.0.1" , port );
0 commit comments