19
19
package org .neo4j .driver .internal ;
20
20
21
21
import io .netty .channel .Channel ;
22
+ import org .junit .jupiter .api .AfterEach ;
23
+ import org .junit .jupiter .api .BeforeAll ;
22
24
import org .junit .jupiter .api .Test ;
23
25
import org .mockito .ArgumentCaptor ;
24
26
import reactor .core .publisher .Flux ;
53
55
import org .neo4j .driver .reactive .RxResult ;
54
56
import org .neo4j .driver .reactive .RxSession ;
55
57
import org .neo4j .driver .util .StubServer ;
58
+ import org .neo4j .driver .util .StubServerController ;
56
59
57
60
import static java .util .Arrays .asList ;
58
61
import static java .util .Collections .singletonList ;
75
78
import static org .neo4j .driver .internal .logging .DevNullLogging .DEV_NULL_LOGGING ;
76
79
import static org .neo4j .driver .util .StubServer .INSECURE_CONFIG ;
77
80
import static org .neo4j .driver .util .StubServer .insecureBuilder ;
81
+ import static org .neo4j .driver .util .StubServer .start ;
78
82
import static org .neo4j .driver .util .TestUtil .asOrderedSet ;
79
83
import static org .neo4j .driver .util .TestUtil .await ;
80
84
81
85
class DirectDriverBoltKitTest
82
86
{
87
+ private static StubServerController stubController ;
88
+
89
+ @ BeforeAll
90
+ public static void setup ()
91
+ {
92
+ stubController = new StubServerController ();
93
+ }
94
+
95
+ @ AfterEach
96
+ public void killServers ()
97
+ {
98
+ stubController .reset ();
99
+ }
100
+
83
101
@ Test
84
102
void shouldBeAbleRunCypher () throws Exception
85
103
{
86
- StubServer server = StubServer . start ( "return_x.script" , 9001 );
104
+ StubServer server = stubController . startStub ( "return_x.script" , 9001 );
87
105
URI uri = URI .create ( "bolt://127.0.0.1:9001" );
88
106
int x ;
89
107
@@ -103,7 +121,7 @@ void shouldBeAbleRunCypher() throws Exception
103
121
@ Test
104
122
void shouldSendMultipleBookmarks () throws Exception
105
123
{
106
- StubServer server = StubServer . start ( "multiple_bookmarks.script" , 9001 );
124
+ StubServer server = stubController . startStub ( "multiple_bookmarks.script" , 9001 );
107
125
108
126
Bookmark bookmarks = InternalBookmark .parse ( asOrderedSet ( "neo4j:bookmark:v1:tx5" , "neo4j:bookmark:v1:tx29" ,
109
127
"neo4j:bookmark:v1:tx94" , "neo4j:bookmark:v1:tx56" , "neo4j:bookmark:v1:tx16" , "neo4j:bookmark:v1:tx68" ) );
@@ -128,7 +146,7 @@ void shouldSendMultipleBookmarks() throws Exception
128
146
@ Test
129
147
void shouldLogConnectionIdInDebugMode () throws Exception
130
148
{
131
- StubServer server = StubServer . start ( "hello_run_exit.script" , 9001 );
149
+ StubServer server = stubController . startStub ( "hello_run_exit.script" , 9001 );
132
150
133
151
Logger logger = mock ( Logger .class );
134
152
when ( logger .isDebugEnabled () ).thenReturn ( true );
@@ -164,7 +182,7 @@ void shouldLogConnectionIdInDebugMode() throws Exception
164
182
@ Test
165
183
void shouldSendReadAccessModeInQueryMetadata () throws Exception
166
184
{
167
- StubServer server = StubServer . start ( "hello_run_exit_read.script" , 9001 );
185
+ StubServer server = stubController . startStub ( "hello_run_exit_read.script" , 9001 );
168
186
169
187
170
188
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
@@ -182,7 +200,7 @@ void shouldSendReadAccessModeInQueryMetadata() throws Exception
182
200
@ Test
183
201
void shouldNotSendWriteAccessModeInQueryMetadata () throws Exception
184
202
{
185
- StubServer server = StubServer . start ( "hello_run_exit.script" , 9001 );
203
+ StubServer server = stubController . startStub ( "hello_run_exit.script" , 9001 );
186
204
187
205
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
188
206
Session session = driver .session ( builder ().withDefaultAccessMode ( AccessMode .WRITE ).build () ) )
@@ -199,7 +217,7 @@ void shouldNotSendWriteAccessModeInQueryMetadata() throws Exception
199
217
@ Test
200
218
void shouldCloseChannelWhenResetFails () throws Exception
201
219
{
202
- StubServer server = StubServer . start ( "reset_error.script" , 9001 );
220
+ StubServer server = stubController . startStub ( "reset_error.script" , 9001 );
203
221
try
204
222
{
205
223
URI uri = URI .create ( "bolt://localhost:9001" );
@@ -230,7 +248,7 @@ void shouldCloseChannelWhenResetFails() throws Exception
230
248
@ Test
231
249
void shouldPropagateTransactionRollbackErrorWhenSessionClosed () throws Exception
232
250
{
233
- StubServer server = StubServer . start ( "rollback_error.script" , 9001 );
251
+ StubServer server = stubController . startStub ( "rollback_error.script" , 9001 );
234
252
try
235
253
{
236
254
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
@@ -255,7 +273,7 @@ void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
255
273
@ Test
256
274
void shouldStreamingRecordsInBatchesRx () throws Exception
257
275
{
258
- StubServer server = StubServer . start ( "streaming_records_v4_rx.script" , 9001 );
276
+ StubServer server = stubController . startStub ( "streaming_records_v4_rx.script" , 9001 );
259
277
try
260
278
{
261
279
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
@@ -275,7 +293,7 @@ void shouldStreamingRecordsInBatchesRx() throws Exception
275
293
@ Test
276
294
void shouldStreamingRecordsInBatches () throws Exception
277
295
{
278
- StubServer server = StubServer . start ( "streaming_records_v4.script" , 9001 );
296
+ StubServer server = stubController . startStub ( "streaming_records_v4.script" , 9001 );
279
297
try
280
298
{
281
299
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , insecureBuilder ().withFetchSize ( 2 ).build () ) )
@@ -295,7 +313,7 @@ void shouldStreamingRecordsInBatches() throws Exception
295
313
@ Test
296
314
void shouldChangeFetchSize () throws Exception
297
315
{
298
- StubServer server = StubServer . start ( "streaming_records_v4.script" , 9001 );
316
+ StubServer server = stubController . startStub ( "streaming_records_v4.script" , 9001 );
299
317
try
300
318
{
301
319
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
@@ -315,7 +333,7 @@ void shouldChangeFetchSize() throws Exception
315
333
@ Test
316
334
void shouldOnlyPullRecordsWhenNeededSimpleSession () throws Exception
317
335
{
318
- StubServer server = StubServer . start ( "streaming_records_v4_buffering.script" , 9001 );
336
+ StubServer server = stubController . startStub ( "streaming_records_v4_buffering.script" , 9001 );
319
337
try
320
338
{
321
339
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
@@ -337,7 +355,7 @@ void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
337
355
@ Test
338
356
void shouldOnlyPullRecordsWhenNeededAsyncSession () throws Exception
339
357
{
340
- StubServer server = StubServer . start ( "streaming_records_v4_buffering.script" , 9001 );
358
+ StubServer server = stubController . startStub ( "streaming_records_v4_buffering.script" , 9001 );
341
359
try
342
360
{
343
361
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
@@ -362,7 +380,7 @@ void shouldOnlyPullRecordsWhenNeededAsyncSession() throws Exception
362
380
@ Test
363
381
void shouldPullAllRecordsOnListAsyncWhenOverWatermark () throws Exception
364
382
{
365
- StubServer server = StubServer . start ( "streaming_records_v4_list_async.script" , 9001 );
383
+ StubServer server = stubController . startStub ( "streaming_records_v4_list_async.script" , 9001 );
366
384
try
367
385
{
368
386
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
@@ -384,7 +402,7 @@ void shouldPullAllRecordsOnListAsyncWhenOverWatermark() throws Exception
384
402
@ Test
385
403
void shouldAllowPullAll () throws Exception
386
404
{
387
- StubServer server = StubServer . start ( "streaming_records_v4_all.script" , 9001 );
405
+ StubServer server = stubController . startStub ( "streaming_records_v4_all.script" , 9001 );
388
406
try
389
407
{
390
408
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , insecureBuilder ().withFetchSize ( -1 ).build () ) )
@@ -423,7 +441,7 @@ void shouldThrowRollbackErrorWhenTransactionClose() throws Exception
423
441
@ Test
424
442
void shouldThrowCorrectErrorOnRunFailure () throws Throwable
425
443
{
426
- StubServer server = StubServer . start ( "database_shutdown.script" , 9001 );
444
+ StubServer server = stubController . startStub ( "database_shutdown.script" , 9001 );
427
445
428
446
Bookmark bookmark = InternalBookmark .parse ( "neo4j:bookmark:v1:tx0" );
429
447
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
@@ -446,7 +464,7 @@ void shouldThrowCorrectErrorOnRunFailure() throws Throwable
446
464
@ Test
447
465
void shouldThrowCorrectErrorOnCommitFailure () throws Throwable
448
466
{
449
- StubServer server = StubServer . start ( "database_shutdown_at_commit.script" , 9001 );
467
+ StubServer server = stubController . startStub ( "database_shutdown_at_commit.script" , 9001 );
450
468
451
469
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
452
470
Session session = driver .session () )
@@ -467,7 +485,7 @@ void shouldThrowCorrectErrorOnCommitFailure() throws Throwable
467
485
@ Test
468
486
void shouldAllowDatabaseNameInSessionRun () throws Throwable
469
487
{
470
- StubServer server = StubServer . start ( "read_server_v4_read.script" , 9001 );
488
+ StubServer server = stubController . startStub ( "read_server_v4_read.script" , 9001 );
471
489
472
490
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
473
491
Session session = driver .session ( builder ().withDatabase ( "mydatabase" ).withDefaultAccessMode ( AccessMode .READ ).build () ) )
@@ -484,7 +502,7 @@ void shouldAllowDatabaseNameInSessionRun() throws Throwable
484
502
@ Test
485
503
void shouldAllowDatabaseNameInBeginTransaction () throws Throwable
486
504
{
487
- StubServer server = StubServer . start ( "read_server_v4_read_tx.script" , 9001 );
505
+ StubServer server = stubController . startStub ( "read_server_v4_read_tx.script" , 9001 );
488
506
489
507
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
490
508
Session session = driver .session ( forDatabase ( "mydatabase" ) ) )
@@ -500,7 +518,7 @@ void shouldAllowDatabaseNameInBeginTransaction() throws Throwable
500
518
@ Test
501
519
void shouldDiscardIfPullNotFinished () throws Throwable
502
520
{
503
- StubServer server = StubServer . start ( "read_tx_v4_discard.script" , 9001 );
521
+ StubServer server = stubController . startStub ( "read_tx_v4_discard.script" , 9001 );
504
522
505
523
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
506
524
{
@@ -519,7 +537,7 @@ void shouldDiscardIfPullNotFinished() throws Throwable
519
537
@ Test
520
538
void shouldServerWithBoltV4SupportMultiDb () throws Throwable
521
539
{
522
- StubServer server = StubServer . start ( "support_multidb_v4.script" , 9001 );
540
+ StubServer server = stubController . startStub ( "support_multidb_v4.script" , 9001 );
523
541
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
524
542
{
525
543
assertTrue ( driver .supportsMultiDb () );
@@ -533,7 +551,7 @@ void shouldServerWithBoltV4SupportMultiDb() throws Throwable
533
551
@ Test
534
552
void shouldServerWithBoltV3NotSupportMultiDb () throws Throwable
535
553
{
536
- StubServer server = StubServer . start ( "support_multidb_v3.script" , 9001 );
554
+ StubServer server = stubController . startStub ( "support_multidb_v3.script" , 9001 );
537
555
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG ) )
538
556
{
539
557
assertFalse ( driver .supportsMultiDb () );
@@ -547,7 +565,7 @@ void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
547
565
@ Test
548
566
void shouldBeAbleHandleNOOPsDuringRunCypher () throws Exception
549
567
{
550
- StubServer server = StubServer . start ( "noop.script" , 9001 );
568
+ StubServer server = stubController . startStub ( "noop.script" , 9001 );
551
569
URI uri = URI .create ( "bolt://127.0.0.1:9001" );
552
570
553
571
try ( Driver driver = GraphDatabase .driver ( uri , INSECURE_CONFIG ) )
@@ -565,7 +583,7 @@ void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
565
583
private static void testTxCloseErrorPropagation ( String script , Consumer <Transaction > txAction , String expectedErrorMessage )
566
584
throws Exception
567
585
{
568
- StubServer server = StubServer . start ( script , 9001 );
586
+ StubServer server = stubController . startStub ( script , 9001 );
569
587
try
570
588
{
571
589
try ( Driver driver = GraphDatabase .driver ( "bolt://localhost:9001" , INSECURE_CONFIG );
0 commit comments