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