Skip to content

Commit 004f47a

Browse files
authored
Adapt bolkit tests for boltkit 4.1 (#721)
Refactor `DirectDriverBoltKitTest` to ensure boltstub is restarted freshly for each run. Fix scripts that are broken with boltkit 4.1.
1 parent be49698 commit 004f47a

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitTest.java

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
package org.neo4j.driver.internal;
2020

2121
import io.netty.channel.Channel;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeAll;
2224
import org.junit.jupiter.api.Test;
2325
import org.mockito.ArgumentCaptor;
2426
import reactor.core.publisher.Flux;
@@ -53,6 +55,7 @@
5355
import org.neo4j.driver.reactive.RxResult;
5456
import org.neo4j.driver.reactive.RxSession;
5557
import org.neo4j.driver.util.StubServer;
58+
import org.neo4j.driver.util.StubServerController;
5659

5760
import static java.util.Arrays.asList;
5861
import static java.util.Collections.singletonList;
@@ -75,15 +78,30 @@
7578
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
7679
import static org.neo4j.driver.util.StubServer.INSECURE_CONFIG;
7780
import static org.neo4j.driver.util.StubServer.insecureBuilder;
81+
import static org.neo4j.driver.util.StubServer.start;
7882
import static org.neo4j.driver.util.TestUtil.asOrderedSet;
7983
import static org.neo4j.driver.util.TestUtil.await;
8084

8185
class DirectDriverBoltKitTest
8286
{
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+
83101
@Test
84102
void shouldBeAbleRunCypher() throws Exception
85103
{
86-
StubServer server = StubServer.start( "return_x.script", 9001 );
104+
StubServer server = stubController.startStub( "return_x.script", 9001 );
87105
URI uri = URI.create( "bolt://127.0.0.1:9001" );
88106
int x;
89107

@@ -103,7 +121,7 @@ void shouldBeAbleRunCypher() throws Exception
103121
@Test
104122
void shouldSendMultipleBookmarks() throws Exception
105123
{
106-
StubServer server = StubServer.start( "multiple_bookmarks.script", 9001 );
124+
StubServer server = stubController.startStub( "multiple_bookmarks.script", 9001 );
107125

108126
Bookmark bookmarks = InternalBookmark.parse( asOrderedSet( "neo4j:bookmark:v1:tx5", "neo4j:bookmark:v1:tx29",
109127
"neo4j:bookmark:v1:tx94", "neo4j:bookmark:v1:tx56", "neo4j:bookmark:v1:tx16", "neo4j:bookmark:v1:tx68" ) );
@@ -128,7 +146,7 @@ void shouldSendMultipleBookmarks() throws Exception
128146
@Test
129147
void shouldLogConnectionIdInDebugMode() throws Exception
130148
{
131-
StubServer server = StubServer.start( "hello_run_exit.script", 9001 );
149+
StubServer server = stubController.startStub( "hello_run_exit.script", 9001 );
132150

133151
Logger logger = mock( Logger.class );
134152
when( logger.isDebugEnabled() ).thenReturn( true );
@@ -164,7 +182,7 @@ void shouldLogConnectionIdInDebugMode() throws Exception
164182
@Test
165183
void shouldSendReadAccessModeInQueryMetadata() throws Exception
166184
{
167-
StubServer server = StubServer.start( "hello_run_exit_read.script", 9001 );
185+
StubServer server = stubController.startStub( "hello_run_exit_read.script", 9001 );
168186

169187

170188
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
@@ -182,7 +200,7 @@ void shouldSendReadAccessModeInQueryMetadata() throws Exception
182200
@Test
183201
void shouldNotSendWriteAccessModeInQueryMetadata() throws Exception
184202
{
185-
StubServer server = StubServer.start( "hello_run_exit.script", 9001 );
203+
StubServer server = stubController.startStub( "hello_run_exit.script", 9001 );
186204

187205
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
188206
Session session = driver.session( builder().withDefaultAccessMode( AccessMode.WRITE ).build() ) )
@@ -199,7 +217,7 @@ void shouldNotSendWriteAccessModeInQueryMetadata() throws Exception
199217
@Test
200218
void shouldCloseChannelWhenResetFails() throws Exception
201219
{
202-
StubServer server = StubServer.start( "reset_error.script", 9001 );
220+
StubServer server = stubController.startStub( "reset_error.script", 9001 );
203221
try
204222
{
205223
URI uri = URI.create( "bolt://localhost:9001" );
@@ -230,7 +248,7 @@ void shouldCloseChannelWhenResetFails() throws Exception
230248
@Test
231249
void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
232250
{
233-
StubServer server = StubServer.start( "rollback_error.script", 9001 );
251+
StubServer server = stubController.startStub( "rollback_error.script", 9001 );
234252
try
235253
{
236254
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
@@ -255,7 +273,7 @@ void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
255273
@Test
256274
void shouldStreamingRecordsInBatchesRx() throws Exception
257275
{
258-
StubServer server = StubServer.start( "streaming_records_v4_rx.script", 9001 );
276+
StubServer server = stubController.startStub( "streaming_records_v4_rx.script", 9001 );
259277
try
260278
{
261279
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
@@ -275,7 +293,7 @@ void shouldStreamingRecordsInBatchesRx() throws Exception
275293
@Test
276294
void shouldStreamingRecordsInBatches() throws Exception
277295
{
278-
StubServer server = StubServer.start( "streaming_records_v4.script", 9001 );
296+
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
279297
try
280298
{
281299
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( 2 ).build() ) )
@@ -295,7 +313,7 @@ void shouldStreamingRecordsInBatches() throws Exception
295313
@Test
296314
void shouldChangeFetchSize() throws Exception
297315
{
298-
StubServer server = StubServer.start( "streaming_records_v4.script", 9001 );
316+
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
299317
try
300318
{
301319
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
@@ -315,7 +333,7 @@ void shouldChangeFetchSize() throws Exception
315333
@Test
316334
void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
317335
{
318-
StubServer server = StubServer.start( "streaming_records_v4_buffering.script", 9001 );
336+
StubServer server = stubController.startStub( "streaming_records_v4_buffering.script", 9001 );
319337
try
320338
{
321339
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
@@ -337,7 +355,7 @@ void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
337355
@Test
338356
void shouldOnlyPullRecordsWhenNeededAsyncSession() throws Exception
339357
{
340-
StubServer server = StubServer.start( "streaming_records_v4_buffering.script", 9001 );
358+
StubServer server = stubController.startStub( "streaming_records_v4_buffering.script", 9001 );
341359
try
342360
{
343361
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
@@ -362,7 +380,7 @@ void shouldOnlyPullRecordsWhenNeededAsyncSession() throws Exception
362380
@Test
363381
void shouldPullAllRecordsOnListAsyncWhenOverWatermark() throws Exception
364382
{
365-
StubServer server = StubServer.start( "streaming_records_v4_list_async.script", 9001 );
383+
StubServer server = stubController.startStub( "streaming_records_v4_list_async.script", 9001 );
366384
try
367385
{
368386
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
@@ -384,7 +402,7 @@ void shouldPullAllRecordsOnListAsyncWhenOverWatermark() throws Exception
384402
@Test
385403
void shouldAllowPullAll() throws Exception
386404
{
387-
StubServer server = StubServer.start( "streaming_records_v4_all.script", 9001 );
405+
StubServer server = stubController.startStub( "streaming_records_v4_all.script", 9001 );
388406
try
389407
{
390408
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( -1 ).build() ) )
@@ -423,7 +441,7 @@ void shouldThrowRollbackErrorWhenTransactionClose() throws Exception
423441
@Test
424442
void shouldThrowCorrectErrorOnRunFailure() throws Throwable
425443
{
426-
StubServer server = StubServer.start( "database_shutdown.script", 9001 );
444+
StubServer server = stubController.startStub( "database_shutdown.script", 9001 );
427445

428446
Bookmark bookmark = InternalBookmark.parse( "neo4j:bookmark:v1:tx0" );
429447
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
@@ -446,7 +464,7 @@ void shouldThrowCorrectErrorOnRunFailure() throws Throwable
446464
@Test
447465
void shouldThrowCorrectErrorOnCommitFailure() throws Throwable
448466
{
449-
StubServer server = StubServer.start( "database_shutdown_at_commit.script", 9001 );
467+
StubServer server = stubController.startStub( "database_shutdown_at_commit.script", 9001 );
450468

451469
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
452470
Session session = driver.session() )
@@ -467,7 +485,7 @@ void shouldThrowCorrectErrorOnCommitFailure() throws Throwable
467485
@Test
468486
void shouldAllowDatabaseNameInSessionRun() throws Throwable
469487
{
470-
StubServer server = StubServer.start( "read_server_v4_read.script", 9001 );
488+
StubServer server = stubController.startStub( "read_server_v4_read.script", 9001 );
471489

472490
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
473491
Session session = driver.session( builder().withDatabase( "mydatabase" ).withDefaultAccessMode( AccessMode.READ ).build() ) )
@@ -484,7 +502,7 @@ void shouldAllowDatabaseNameInSessionRun() throws Throwable
484502
@Test
485503
void shouldAllowDatabaseNameInBeginTransaction() throws Throwable
486504
{
487-
StubServer server = StubServer.start( "read_server_v4_read_tx.script", 9001 );
505+
StubServer server = stubController.startStub( "read_server_v4_read_tx.script", 9001 );
488506

489507
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
490508
Session session = driver.session( forDatabase( "mydatabase" ) ) )
@@ -500,7 +518,7 @@ void shouldAllowDatabaseNameInBeginTransaction() throws Throwable
500518
@Test
501519
void shouldDiscardIfPullNotFinished() throws Throwable
502520
{
503-
StubServer server = StubServer.start( "read_tx_v4_discard.script", 9001 );
521+
StubServer server = stubController.startStub( "read_tx_v4_discard.script", 9001 );
504522

505523
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
506524
{
@@ -519,7 +537,7 @@ void shouldDiscardIfPullNotFinished() throws Throwable
519537
@Test
520538
void shouldServerWithBoltV4SupportMultiDb() throws Throwable
521539
{
522-
StubServer server = StubServer.start( "support_multidb_v4.script", 9001 );
540+
StubServer server = stubController.startStub( "support_multidb_v4.script", 9001 );
523541
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
524542
{
525543
assertTrue( driver.supportsMultiDb() );
@@ -533,7 +551,7 @@ void shouldServerWithBoltV4SupportMultiDb() throws Throwable
533551
@Test
534552
void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
535553
{
536-
StubServer server = StubServer.start( "support_multidb_v3.script", 9001 );
554+
StubServer server = stubController.startStub( "support_multidb_v3.script", 9001 );
537555
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
538556
{
539557
assertFalse( driver.supportsMultiDb() );
@@ -547,7 +565,7 @@ void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
547565
@Test
548566
void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
549567
{
550-
StubServer server = StubServer.start( "noop.script", 9001 );
568+
StubServer server = stubController.startStub( "noop.script", 9001 );
551569
URI uri = URI.create( "bolt://127.0.0.1:9001" );
552570

553571
try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) )
@@ -565,7 +583,7 @@ void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
565583
private static void testTxCloseErrorPropagation( String script, Consumer<Transaction> txAction, String expectedErrorMessage )
566584
throws Exception
567585
{
568-
StubServer server = StubServer.start( script, 9001 );
586+
StubServer server = stubController.startStub( script, 9001 );
569587
try
570588
{
571589
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );

driver/src/test/java/org/neo4j/driver/util/Neo4jRunner.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,10 @@ public static void debug( String text, Object... args )
366366
{
367367
System.out.println( String.format( text, args ) );
368368
}
369+
370+
public static void debug( String text )
371+
{
372+
System.out.println( text );
373+
}
369374
}
370375

driver/src/test/java/org/neo4j/driver/util/StubServer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333

3434
import static java.lang.Thread.sleep;
3535
import static java.util.Arrays.asList;
36-
import static java.util.Collections.singletonList;
3736
import static java.util.concurrent.Executors.newCachedThreadPool;
3837
import static org.junit.jupiter.api.Assertions.fail;
3938
import static org.junit.jupiter.api.Assumptions.assumeTrue;

driver/src/test/resources/commit_error.script

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
!: BOLT 3
2-
!: AUTO RESET
32
!: AUTO HELLO
43
!: AUTO GOODBYE
54

@@ -14,3 +13,5 @@ C: COMMIT
1413
S: FAILURE {"code": "Neo.TransientError.General.DatabaseUnavailable", "message": "Unable to commit"}
1514
C: RESET
1615
S: SUCCESS {}
16+
C: RESET
17+
S: SUCCESS {}

driver/src/test/resources/rollback_error.script

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
!: BOLT 3
2-
!: AUTO RESET
32
!: AUTO HELLO
43
!: AUTO GOODBYE
54

@@ -14,3 +13,5 @@ C: ROLLBACK
1413
S: FAILURE {"code": "Neo.TransientError.General.DatabaseUnavailable", "message": "Unable to rollback"}
1514
C: RESET
1615
S: SUCCESS {}
16+
C: RESET
17+
S: SUCCESS {}

0 commit comments

Comments
 (0)