25
25
26
26
import java .io .IOException ;
27
27
import java .net .URI ;
28
- import java .net .URL ;
29
28
import java .util .Arrays ;
30
29
import java .util .List ;
31
30
import java .util .Set ;
58
57
import static org .junit .Assert .assertTrue ;
59
58
import static org .junit .Assert .fail ;
60
59
61
- @ Ignore
62
60
public class RoutingDriverStubTest
63
61
{
64
62
@ Rule
@@ -70,7 +68,7 @@ public class RoutingDriverStubTest
70
68
public void shouldDiscoverServers () throws IOException , InterruptedException , StubServer .ForceKilled
71
69
{
72
70
// Given
73
- StubServer server = StubServer .start ( resource ( "discover_servers.script" ) , 9001 );
71
+ StubServer server = StubServer .start ( "discover_servers.script" , 9001 );
74
72
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
75
73
76
74
// When
@@ -89,7 +87,7 @@ public void shouldDiscoverServers() throws IOException, InterruptedException, St
89
87
public void shouldDiscoverNewServers () throws IOException , InterruptedException , StubServer .ForceKilled
90
88
{
91
89
// Given
92
- StubServer server = StubServer .start ( resource ( "discover_new_servers.script" ) , 9001 );
90
+ StubServer server = StubServer .start ( "discover_new_servers.script" , 9001 );
93
91
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
94
92
BoltServerAddress seed = address ( 9001 );
95
93
@@ -110,7 +108,7 @@ public void shouldDiscoverNewServers() throws IOException, InterruptedException,
110
108
public void shouldHandleEmptyResponse () throws IOException , InterruptedException , StubServer .ForceKilled
111
109
{
112
110
// Given
113
- StubServer server = StubServer .start ( resource ( "handle_empty_response.script" ) , 9001 );
111
+ StubServer server = StubServer .start ( "handle_empty_response.script" , 9001 );
114
112
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
115
113
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config ) )
116
114
{
@@ -127,10 +125,10 @@ public void shouldHandleEmptyResponse() throws IOException, InterruptedException
127
125
public void shouldHandleAcquireReadSession () throws IOException , InterruptedException , StubServer .ForceKilled
128
126
{
129
127
// Given
130
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
128
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
131
129
132
130
//START a read server
133
- StubServer readServer = StubServer .start ( resource ( "read_server.script" ) , 9005 );
131
+ StubServer readServer = StubServer .start ( "read_server.script" , 9005 );
134
132
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
135
133
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
136
134
Session session = driver .session ( AccessMode .READ ) )
@@ -156,11 +154,11 @@ public String apply( Record record )
156
154
public void shouldRoundRobinReadServers () throws IOException , InterruptedException , StubServer .ForceKilled
157
155
{
158
156
// Given
159
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
157
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
160
158
161
159
//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 );
164
162
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
165
163
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config ) )
166
164
{
@@ -195,10 +193,10 @@ public void shouldThrowSessionExpiredIfReadServerDisappears()
195
193
exception .expectMessage ( "Server at 127.0.0.1:9005 is no longer available" );
196
194
197
195
// Given
198
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
196
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
199
197
200
198
//START a read server
201
- StubServer .start ( resource ( "dead_server.script" ) , 9005 );
199
+ StubServer .start ( "dead_server.script" , 9005 );
202
200
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
203
201
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
204
202
Session session = driver .session ( AccessMode .READ ) )
@@ -218,10 +216,10 @@ public void shouldThrowSessionExpiredIfWriteServerDisappears()
218
216
//exception.expectMessage( "Server at 127.0.0.1:9006 is no longer available" );
219
217
220
218
// Given
221
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
219
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
222
220
223
221
//START a dead write servers
224
- StubServer .start ( resource ( "dead_server.script" ) , 9007 );
222
+ StubServer .start ( "dead_server.script" , 9007 );
225
223
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
226
224
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
227
225
Session session = driver .session ( AccessMode .WRITE ) )
@@ -236,10 +234,10 @@ public void shouldThrowSessionExpiredIfWriteServerDisappears()
236
234
public void shouldHandleAcquireWriteSession () throws IOException , InterruptedException , StubServer .ForceKilled
237
235
{
238
236
// Given
239
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
237
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
240
238
241
239
//START a write server
242
- StubServer writeServer = StubServer .start ( resource ( "write_server.script" ) , 9007 );
240
+ StubServer writeServer = StubServer .start ( "write_server.script" , 9007 );
243
241
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
244
242
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
245
243
Session session = driver .session ( AccessMode .WRITE ) )
@@ -255,11 +253,11 @@ public void shouldHandleAcquireWriteSession() throws IOException, InterruptedExc
255
253
public void shouldRoundRobinWriteSessions () throws IOException , InterruptedException , StubServer .ForceKilled
256
254
{
257
255
// Given
258
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
256
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
259
257
260
258
//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 );
263
261
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
264
262
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config ) )
265
263
{
@@ -281,10 +279,10 @@ public void shouldRoundRobinWriteSessions() throws IOException, InterruptedExcep
281
279
public void shouldRememberEndpoints () throws IOException , InterruptedException , StubServer .ForceKilled
282
280
{
283
281
// Given
284
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
282
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
285
283
286
284
//START a read server
287
- StubServer readServer = StubServer .start ( resource ( "read_server.script" ) , 9005 );
285
+ StubServer readServer = StubServer .start ( "read_server.script" , 9005 );
288
286
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
289
287
try ( RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
290
288
Session session = driver .session ( AccessMode .READ ) )
@@ -304,10 +302,10 @@ public void shouldRememberEndpoints() throws IOException, InterruptedException,
304
302
public void shouldForgetEndpointsOnFailure () throws IOException , InterruptedException , StubServer .ForceKilled
305
303
{
306
304
// Given
307
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
305
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
308
306
309
307
//START a read server
310
- StubServer .start ( resource ( "dead_server.script" ) , 9005 );
308
+ StubServer .start ( "dead_server.script" , 9005 );
311
309
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
312
310
RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
313
311
try
@@ -336,11 +334,11 @@ public void shouldRediscoverIfNecessaryOnSessionAcquisition()
336
334
throws IOException , InterruptedException , StubServer .ForceKilled
337
335
{
338
336
// Given
339
- StubServer server = StubServer .start ( resource ( "rediscover.script" ) , 9001 );
337
+ StubServer server = StubServer .start ( "rediscover.script" , 9001 );
340
338
341
339
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
342
340
//START a read server
343
- StubServer read = StubServer .start ( resource ( "empty.script" ) , 9005 );
341
+ StubServer read = StubServer .start ( "empty.script" , 9005 );
344
342
345
343
//On creation we only find ourselves
346
344
RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
@@ -365,11 +363,11 @@ public void shouldRediscoverIfNecessaryOnSessionAcquisition()
365
363
public void shouldOnlyGetServersOnce () throws IOException , InterruptedException , StubServer .ForceKilled
366
364
{
367
365
// Given
368
- StubServer server = StubServer .start ( resource ( "rediscover.script" ) , 9001 );
366
+ StubServer server = StubServer .start ( "rediscover.script" , 9001 );
369
367
370
368
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
371
369
//START a read server
372
- StubServer read = StubServer .start ( resource ( "empty.script" ) , 9005 );
370
+ StubServer read = StubServer .start ( "empty.script" , 9005 );
373
371
374
372
//On creation we only find ourselves
375
373
final RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
@@ -410,7 +408,7 @@ public void shouldFailOnNonDiscoverableServer() throws IOException, InterruptedE
410
408
exception .expect ( ServiceUnavailableException .class );
411
409
412
410
// Given
413
- StubServer .start ( resource ( "non_discovery_server.script" ) , 9001 );
411
+ StubServer .start ( "non_discovery_server.script" , 9001 );
414
412
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
415
413
416
414
// When
@@ -424,7 +422,7 @@ public void shouldFailRandomFailureInGetServers() throws IOException, Interrupte
424
422
exception .expect ( ServiceUnavailableException .class );
425
423
426
424
// Given
427
- StubServer .start ( resource ( "failed_discovery.script" ) , 9001 );
425
+ StubServer .start ( "failed_discovery.script" , 9001 );
428
426
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
429
427
430
428
// When
@@ -436,10 +434,10 @@ public void shouldHandleLeaderSwitchWhenWriting()
436
434
throws IOException , InterruptedException , StubServer .ForceKilled
437
435
{
438
436
// Given
439
- StubServer server = StubServer .start ( resource ( "acquire_endpoints.script" ) , 9001 );
437
+ StubServer server = StubServer .start ( "acquire_endpoints.script" , 9001 );
440
438
441
439
//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 );
443
441
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
444
442
RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
445
443
boolean failed = false ;
@@ -468,10 +466,10 @@ public void shouldHandleLeaderSwitchWhenWriting()
468
466
public void shouldRediscoverOnExpiry () throws IOException , InterruptedException , StubServer .ForceKilled
469
467
{
470
468
// Given
471
- StubServer server = StubServer .start ( resource ( "expire.script" ) , 9001 );
469
+ StubServer server = StubServer .start ( "expire.script" , 9001 );
472
470
473
471
//START a read server
474
- StubServer readServer = StubServer .start ( resource ( "empty.script" ) , 9005 );
472
+ StubServer readServer = StubServer .start ( "empty.script" , 9005 );
475
473
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
476
474
RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
477
475
assertThat (driver .routingServers (), contains (address ( 9001 )));
@@ -494,12 +492,12 @@ public void shouldRediscoverOnExpiry() throws IOException, InterruptedException,
494
492
public void shouldNotPutBackPurgedConnection () throws IOException , InterruptedException , StubServer .ForceKilled
495
493
{
496
494
// Given
497
- StubServer server = StubServer .start ( resource ( "not_reuse_connection.script" ) , 9001 );
495
+ StubServer server = StubServer .start ( "not_reuse_connection.script" , 9001 );
498
496
499
497
//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 );
503
501
URI uri = URI .create ( "bolt+routing://127.0.0.1:9001" );
504
502
505
503
RoutingDriver driver = (RoutingDriver ) GraphDatabase .driver ( uri , config );
@@ -548,16 +546,6 @@ public void shouldNotPutBackPurgedConnection() throws IOException, InterruptedEx
548
546
assertThat ( writeServer2 .exitStatus (), equalTo ( 0 ) );
549
547
}
550
548
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
-
561
549
private BoltServerAddress address ( int port )
562
550
{
563
551
return new BoltServerAddress ( "127.0.0.1" , port );
0 commit comments