Skip to content

Adapt bolkit tests for boltkit 4.1 #721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
package org.neo4j.driver.internal;

import io.netty.channel.Channel;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import reactor.core.publisher.Flux;
Expand Down Expand Up @@ -53,6 +55,7 @@
import org.neo4j.driver.reactive.RxResult;
import org.neo4j.driver.reactive.RxSession;
import org.neo4j.driver.util.StubServer;
import org.neo4j.driver.util.StubServerController;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
Expand All @@ -75,15 +78,30 @@
import static org.neo4j.driver.internal.logging.DevNullLogging.DEV_NULL_LOGGING;
import static org.neo4j.driver.util.StubServer.INSECURE_CONFIG;
import static org.neo4j.driver.util.StubServer.insecureBuilder;
import static org.neo4j.driver.util.StubServer.start;
import static org.neo4j.driver.util.TestUtil.asOrderedSet;
import static org.neo4j.driver.util.TestUtil.await;

class DirectDriverBoltKitTest
{
private static StubServerController stubController;

@BeforeAll
public static void setup()
{
stubController = new StubServerController();
}

@AfterEach
public void killServers()
{
stubController.reset();
}

@Test
void shouldBeAbleRunCypher() throws Exception
{
StubServer server = StubServer.start( "return_x.script", 9001 );
StubServer server = stubController.startStub( "return_x.script", 9001 );
URI uri = URI.create( "bolt://127.0.0.1:9001" );
int x;

Expand All @@ -103,7 +121,7 @@ void shouldBeAbleRunCypher() throws Exception
@Test
void shouldSendMultipleBookmarks() throws Exception
{
StubServer server = StubServer.start( "multiple_bookmarks.script", 9001 );
StubServer server = stubController.startStub( "multiple_bookmarks.script", 9001 );

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

Logger logger = mock( Logger.class );
when( logger.isDebugEnabled() ).thenReturn( true );
Expand Down Expand Up @@ -164,7 +182,7 @@ void shouldLogConnectionIdInDebugMode() throws Exception
@Test
void shouldSendReadAccessModeInQueryMetadata() throws Exception
{
StubServer server = StubServer.start( "hello_run_exit_read.script", 9001 );
StubServer server = stubController.startStub( "hello_run_exit_read.script", 9001 );


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

try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
Session session = driver.session( builder().withDefaultAccessMode( AccessMode.WRITE ).build() ) )
Expand All @@ -199,7 +217,7 @@ void shouldNotSendWriteAccessModeInQueryMetadata() throws Exception
@Test
void shouldCloseChannelWhenResetFails() throws Exception
{
StubServer server = StubServer.start( "reset_error.script", 9001 );
StubServer server = stubController.startStub( "reset_error.script", 9001 );
try
{
URI uri = URI.create( "bolt://localhost:9001" );
Expand Down Expand Up @@ -230,7 +248,7 @@ void shouldCloseChannelWhenResetFails() throws Exception
@Test
void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
{
StubServer server = StubServer.start( "rollback_error.script", 9001 );
StubServer server = stubController.startStub( "rollback_error.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
Expand All @@ -255,7 +273,7 @@ void shouldPropagateTransactionRollbackErrorWhenSessionClosed() throws Exception
@Test
void shouldStreamingRecordsInBatchesRx() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4_rx.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4_rx.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
Expand All @@ -275,7 +293,7 @@ void shouldStreamingRecordsInBatchesRx() throws Exception
@Test
void shouldStreamingRecordsInBatches() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( 2 ).build() ) )
Expand All @@ -295,7 +313,7 @@ void shouldStreamingRecordsInBatches() throws Exception
@Test
void shouldChangeFetchSize() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
Expand All @@ -315,7 +333,7 @@ void shouldChangeFetchSize() throws Exception
@Test
void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4_buffering.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4_buffering.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
Expand All @@ -337,7 +355,7 @@ void shouldOnlyPullRecordsWhenNeededSimpleSession() throws Exception
@Test
void shouldOnlyPullRecordsWhenNeededAsyncSession() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4_buffering.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4_buffering.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
Expand All @@ -362,7 +380,7 @@ void shouldOnlyPullRecordsWhenNeededAsyncSession() throws Exception
@Test
void shouldPullAllRecordsOnListAsyncWhenOverWatermark() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4_list_async.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4_list_async.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
Expand All @@ -384,7 +402,7 @@ void shouldPullAllRecordsOnListAsyncWhenOverWatermark() throws Exception
@Test
void shouldAllowPullAll() throws Exception
{
StubServer server = StubServer.start( "streaming_records_v4_all.script", 9001 );
StubServer server = stubController.startStub( "streaming_records_v4_all.script", 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( -1 ).build() ) )
Expand Down Expand Up @@ -423,7 +441,7 @@ void shouldThrowRollbackErrorWhenTransactionClose() throws Exception
@Test
void shouldThrowCorrectErrorOnRunFailure() throws Throwable
{
StubServer server = StubServer.start( "database_shutdown.script", 9001 );
StubServer server = stubController.startStub( "database_shutdown.script", 9001 );

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

try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
Session session = driver.session() )
Expand All @@ -467,7 +485,7 @@ void shouldThrowCorrectErrorOnCommitFailure() throws Throwable
@Test
void shouldAllowDatabaseNameInSessionRun() throws Throwable
{
StubServer server = StubServer.start( "read_server_v4_read.script", 9001 );
StubServer server = stubController.startStub( "read_server_v4_read.script", 9001 );

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

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

try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
{
Expand All @@ -519,7 +537,7 @@ void shouldDiscardIfPullNotFinished() throws Throwable
@Test
void shouldServerWithBoltV4SupportMultiDb() throws Throwable
{
StubServer server = StubServer.start( "support_multidb_v4.script", 9001 );
StubServer server = stubController.startStub( "support_multidb_v4.script", 9001 );
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
{
assertTrue( driver.supportsMultiDb() );
Expand All @@ -533,7 +551,7 @@ void shouldServerWithBoltV4SupportMultiDb() throws Throwable
@Test
void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
{
StubServer server = StubServer.start( "support_multidb_v3.script", 9001 );
StubServer server = stubController.startStub( "support_multidb_v3.script", 9001 );
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) )
{
assertFalse( driver.supportsMultiDb() );
Expand All @@ -547,7 +565,7 @@ void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
@Test
void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
{
StubServer server = StubServer.start( "noop.script", 9001 );
StubServer server = stubController.startStub( "noop.script", 9001 );
URI uri = URI.create( "bolt://127.0.0.1:9001" );

try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) )
Expand All @@ -565,7 +583,7 @@ void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception
private static void testTxCloseErrorPropagation( String script, Consumer<Transaction> txAction, String expectedErrorMessage )
throws Exception
{
StubServer server = StubServer.start( script, 9001 );
StubServer server = stubController.startStub( script, 9001 );
try
{
try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG );
Expand Down
5 changes: 5 additions & 0 deletions driver/src/test/java/org/neo4j/driver/util/Neo4jRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -366,5 +366,10 @@ public static void debug( String text, Object... args )
{
System.out.println( String.format( text, args ) );
}

public static void debug( String text )
{
System.out.println( text );
}
}

1 change: 0 additions & 1 deletion driver/src/test/java/org/neo4j/driver/util/StubServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import static java.lang.Thread.sleep;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static java.util.concurrent.Executors.newCachedThreadPool;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
Expand Down
3 changes: 2 additions & 1 deletion driver/src/test/resources/commit_error.script
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
!: BOLT 3
!: AUTO RESET
!: AUTO HELLO
!: AUTO GOODBYE

Expand All @@ -14,3 +13,5 @@ C: COMMIT
S: FAILURE {"code": "Neo.TransientError.General.DatabaseUnavailable", "message": "Unable to commit"}
C: RESET
S: SUCCESS {}
C: RESET
S: SUCCESS {}
3 changes: 2 additions & 1 deletion driver/src/test/resources/rollback_error.script
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
!: BOLT 3
!: AUTO RESET
!: AUTO HELLO
!: AUTO GOODBYE

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