From 2b5ca73d4e525f8c57e23dc8dd1812a9a20232f4 Mon Sep 17 00:00:00 2001 From: Dmitriy Tverdiakov Date: Wed, 11 Aug 2021 15:14:21 +0100 Subject: [PATCH] Migrate tests from Java Driver to Testkit Migrated tests: - shouldAllowPullAll -> test_should_pull_all_when_fetch_is_minus_one_using_driver_configuration (Bolt bump from v4 to v4.1) - shouldThrowCommitErrorWhenTransactionCommit -> test_should_error_on_commit_failure_using_tx_commit - shouldServerWithBoltV4SupportMultiDb -> test_should_check_multi_db_support - shouldServerWithBoltV3NotSupportMultiDb -> test_should_check_multi_db_support - shouldBeAbleHandleNOOPsDuringRunCypher -> test_should_accept_noop_during_records_streaming - shouldThrowCorrectErrorOnCommitFailure -> test_should_error_on_database_shutdown_using_tx_commit - shouldThrowCorrectErrorOnRunFailure -> test_should_error_on_database_shutdown_using_tx_run --- .../internal/DirectDriverBoltKitIT.java | 151 ------------------ driver/src/test/resources/commit_error.script | 17 -- .../test/resources/database_shutdown.script | 11 -- .../database_shutdown_at_commit.script | 14 -- driver/src/test/resources/noop.script | 16 -- .../resources/streaming_records_v4_all.script | 12 -- .../test/resources/support_multidb_v3.script | 4 - .../test/resources/support_multidb_v4.script | 4 - 8 files changed, 229 deletions(-) delete mode 100644 driver/src/test/resources/commit_error.script delete mode 100644 driver/src/test/resources/database_shutdown.script delete mode 100644 driver/src/test/resources/database_shutdown_at_commit.script delete mode 100644 driver/src/test/resources/noop.script delete mode 100644 driver/src/test/resources/streaming_records_v4_all.script delete mode 100644 driver/src/test/resources/support_multidb_v3.script delete mode 100644 driver/src/test/resources/support_multidb_v4.script diff --git a/driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitIT.java b/driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitIT.java index 2cc84e5dc6..24ccf58845 100644 --- a/driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitIT.java +++ b/driver/src/test/java/org/neo4j/driver/internal/DirectDriverBoltKitIT.java @@ -29,20 +29,16 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; -import java.util.function.Consumer; import org.neo4j.driver.AccessMode; import org.neo4j.driver.AuthTokens; -import org.neo4j.driver.Bookmark; import org.neo4j.driver.Config; import org.neo4j.driver.Driver; import org.neo4j.driver.GraphDatabase; import org.neo4j.driver.Result; import org.neo4j.driver.Session; -import org.neo4j.driver.Transaction; import org.neo4j.driver.async.AsyncSession; import org.neo4j.driver.async.ResultCursor; -import org.neo4j.driver.exceptions.TransientException; import org.neo4j.driver.internal.cluster.RoutingSettings; import org.neo4j.driver.internal.retry.RetrySettings; import org.neo4j.driver.internal.security.SecurityPlanImpl; @@ -56,18 +52,12 @@ import static java.util.Arrays.asList; import static java.util.Collections.singletonList; import static java.util.concurrent.TimeUnit.SECONDS; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.neo4j.driver.SessionConfig.builder; import static org.neo4j.driver.SessionConfig.forDatabase; 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.TestUtil.await; class DirectDriverBoltKitIT @@ -206,76 +196,6 @@ void shouldPullAllRecordsOnListAsyncWhenOverWatermark() throws Exception } } - @Test - void shouldAllowPullAll() throws Exception - { - StubServer server = stubController.startStub( "streaming_records_v4_all.script", 9001 ); - try - { - try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", insecureBuilder().withFetchSize( -1 ).build() ) ) - { - Session session = driver.session(); - Result result = session.run( "MATCH (n) RETURN n.name" ); - List list = result.list( record -> record.get( "n.name" ).asString() ); - assertEquals( list, asList( "Bob", "Alice", "Tina" ) ); - } - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } - - @Test - void shouldThrowCommitErrorWhenTransactionCommit() throws Exception - { - testTxCloseErrorPropagation( "commit_error.script", Transaction::commit, "Unable to commit" ); - } - - @Test - void shouldThrowCorrectErrorOnRunFailure() throws Throwable - { - 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 ); - Session session = driver.session( builder().withBookmarks( bookmark ).build() ); - // has to enforce to flush BEGIN to have tx started. - Transaction transaction = session.beginTransaction() ) - { - TransientException error = assertThrows( TransientException.class, () -> { - Result result = transaction.run( "RETURN 1" ); - result.consume(); - } ); - assertThat( error.code(), equalTo( "Neo.TransientError.General.DatabaseUnavailable" ) ); - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } - - @Test - void shouldThrowCorrectErrorOnCommitFailure() throws Throwable - { - StubServer server = stubController.startStub( "database_shutdown_at_commit.script", 9001 ); - - try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ); - Session session = driver.session() ) - { - Transaction transaction = session.beginTransaction(); - Result result = transaction.run( "CREATE (n {name:'Bob'})" ); - result.consume(); - - TransientException error = assertThrows( TransientException.class, transaction::commit ); - assertThat( error.code(), equalTo( "Neo.TransientError.General.DatabaseUnavailable" ) ); - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } - @Test void shouldAllowDatabaseNameInSessionRun() throws Throwable { @@ -327,75 +247,4 @@ void shouldDiscardIfPullNotFinished() throws Throwable assertEquals( 0, server.exitStatus() ); } } - - @Test - void shouldServerWithBoltV4SupportMultiDb() throws Throwable - { - StubServer server = stubController.startStub( "support_multidb_v4.script", 9001 ); - try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) ) - { - assertTrue( driver.supportsMultiDb() ); - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } - - @Test - void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable - { - StubServer server = stubController.startStub( "support_multidb_v3.script", 9001 ); - try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ) ) - { - assertFalse( driver.supportsMultiDb() ); - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } - - @Test - void shouldBeAbleHandleNOOPsDuringRunCypher() throws Exception - { - 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 ) ) - { - try ( Session session = driver.session() ) - { - List names = session.run( "MATCH (n) RETURN n.name" ).list( rec -> rec.get( 0 ).asString() ); - assertEquals( asList( "Foo", "Bar", "Baz" ), names ); - } - } - - assertThat( server.exitStatus(), equalTo( 0 ) ); - } - - private static void testTxCloseErrorPropagation( String script, Consumer txAction, String expectedErrorMessage ) - throws Exception - { - StubServer server = stubController.startStub( script, 9001 ); - try - { - try ( Driver driver = GraphDatabase.driver( "bolt://localhost:9001", INSECURE_CONFIG ); - Session session = driver.session() ) - { - Transaction tx = session.beginTransaction(); - Result result = tx.run( "CREATE (n {name:'Alice'}) RETURN n.name AS name" ); - assertEquals( "Alice", result.single().get( "name" ).asString() ); - - TransientException e = assertThrows( TransientException.class, () -> txAction.accept( tx ) ); - - assertEquals( "Neo.TransientError.General.DatabaseUnavailable", e.code() ); - assertEquals( expectedErrorMessage, e.getMessage() ); - } - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } } diff --git a/driver/src/test/resources/commit_error.script b/driver/src/test/resources/commit_error.script deleted file mode 100644 index 493e37b10b..0000000000 --- a/driver/src/test/resources/commit_error.script +++ /dev/null @@ -1,17 +0,0 @@ -!: BOLT 3 -!: AUTO HELLO -!: AUTO GOODBYE - -C: BEGIN {} -S: SUCCESS {} -C: RUN "CREATE (n {name:'Alice'}) RETURN n.name AS name" {} {} - PULL_ALL -S: SUCCESS {"fields": ["name"]} - RECORD ["Alice"] - SUCCESS {} -C: COMMIT -S: FAILURE {"code": "Neo.TransientError.General.DatabaseUnavailable", "message": "Unable to commit"} -C: RESET -S: SUCCESS {} -C: RESET -S: SUCCESS {} diff --git a/driver/src/test/resources/database_shutdown.script b/driver/src/test/resources/database_shutdown.script deleted file mode 100644 index 9d315be683..0000000000 --- a/driver/src/test/resources/database_shutdown.script +++ /dev/null @@ -1,11 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: BEGIN {"bookmarks": ["neo4j:bookmark:v1:tx0"]} -S: SUCCESS {} -C: RUN "RETURN 1" {} {} - PULL_ALL -S: FAILURE {"code": "Neo.TransientError.General.DatabaseUnavailable", "message": "Database shut down."} -S: diff --git a/driver/src/test/resources/database_shutdown_at_commit.script b/driver/src/test/resources/database_shutdown_at_commit.script deleted file mode 100644 index 42c4465be6..0000000000 --- a/driver/src/test/resources/database_shutdown_at_commit.script +++ /dev/null @@ -1,14 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: BEGIN {} -S: SUCCESS {} -C: RUN "CREATE (n {name:'Bob'})" {} {} - PULL_ALL -S: SUCCESS {} - SUCCESS {} -C: COMMIT -S: FAILURE {"code": "Neo.TransientError.General.DatabaseUnavailable", "message": "Database shut down."} -S: diff --git a/driver/src/test/resources/noop.script b/driver/src/test/resources/noop.script deleted file mode 100644 index 6f9560fc04..0000000000 --- a/driver/src/test/resources/noop.script +++ /dev/null @@ -1,16 +0,0 @@ -!: BOLT 4.1 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "MATCH (n) RETURN n.name" {} {} - PULL { "n": 1000 } -S: SUCCESS {"fields": ["n.name"]} - - RECORD ["Foo"] - - RECORD ["Bar"] - - - RECORD ["Baz"] - SUCCESS {} diff --git a/driver/src/test/resources/streaming_records_v4_all.script b/driver/src/test/resources/streaming_records_v4_all.script deleted file mode 100644 index f9e0386b5a..0000000000 --- a/driver/src/test/resources/streaming_records_v4_all.script +++ /dev/null @@ -1,12 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "MATCH (n) RETURN n.name" {} {} - PULL { "n": -1 } -S: SUCCESS {"fields": ["n.name"]} - RECORD ["Bob"] - RECORD ["Alice"] - RECORD ["Tina"] - SUCCESS {} diff --git a/driver/src/test/resources/support_multidb_v3.script b/driver/src/test/resources/support_multidb_v3.script deleted file mode 100644 index 0dbb929280..0000000000 --- a/driver/src/test/resources/support_multidb_v3.script +++ /dev/null @@ -1,4 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE diff --git a/driver/src/test/resources/support_multidb_v4.script b/driver/src/test/resources/support_multidb_v4.script deleted file mode 100644 index 2797dfaf9d..0000000000 --- a/driver/src/test/resources/support_multidb_v4.script +++ /dev/null @@ -1,4 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE