diff --git a/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverMultidatabaseBoltKitIT.java b/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverMultidatabaseBoltKitIT.java deleted file mode 100644 index be71b344eb..0000000000 --- a/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverMultidatabaseBoltKitIT.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright (c) "Neo4j" - * Neo4j Sweden AB [http://neo4j.com] - * - * This file is part of Neo4j. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.neo4j.driver.integration; - -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.net.URI; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import org.neo4j.driver.AccessMode; -import org.neo4j.driver.Config; -import org.neo4j.driver.Driver; -import org.neo4j.driver.GraphDatabase; -import org.neo4j.driver.Record; -import org.neo4j.driver.Session; -import org.neo4j.driver.exceptions.FatalDiscoveryException; -import org.neo4j.driver.exceptions.ServiceUnavailableException; -import org.neo4j.driver.integration.RoutingDriverBoltKitIT.PortBasedServerAddressComparator; -import org.neo4j.driver.Bookmark; -import org.neo4j.driver.net.ServerAddress; -import org.neo4j.driver.net.ServerAddressResolver; -import org.neo4j.driver.util.StubServer; - -import static java.util.Arrays.asList; -import static org.hamcrest.Matchers.containsString; -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.assertThrows; -import static org.neo4j.driver.SessionConfig.builder; -import static org.neo4j.driver.internal.InternalBookmark.parse; -import static org.neo4j.driver.util.StubServer.INSECURE_CONFIG; -import static org.neo4j.driver.util.StubServer.insecureBuilder; - -class RoutingDriverMultidatabaseBoltKitIT -{ - @Test - void shouldDiscoverForDatabase() throws IOException, InterruptedException, StubServer.ForceKilled - { - // Given - StubServer router = StubServer.start( "acquire_endpoints_v4.script", 9001 ); - //START a read server - StubServer reader = StubServer.start( "read_server_v4_read.script", 9005 ); - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); - try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ); - Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withDatabase( "mydatabase" ).build() ) ) - { - List result = session.run( "MATCH (n) RETURN n.name" ).list( record -> record.get( "n.name" ).asString() ); - - assertThat( result, equalTo( asList( "Bob", "Alice", "Tina" ) ) ); - } - // Finally - assertThat( router.exitStatus(), equalTo( 0 ) ); - assertThat( reader.exitStatus(), equalTo( 0 ) ); - } - - @Test - void shouldRetryOnEmptyDiscoveryResult() throws IOException, InterruptedException, StubServer.ForceKilled - { - ServerAddressResolver resolver = a -> { - SortedSet addresses = new TreeSet<>( new PortBasedServerAddressComparator() ); - addresses.add( ServerAddress.of( "127.0.0.1", 9001 ) ); - addresses.add( ServerAddress.of( "127.0.0.1", 9002 ) ); - return addresses; - }; - - StubServer emptyRouter = StubServer.start( "acquire_endpoints_v4_empty.script", 9001 ); - StubServer realRouter = StubServer.start( "acquire_endpoints_v4_virtual_host.script", 9002 ); - StubServer reader = StubServer.start( "read_server_v4_read.script", 9005 ); - - Config config = insecureBuilder().withResolver( resolver ).build(); - try ( Driver driver = GraphDatabase.driver( "neo4j://my.virtual.host:8080", config ); - Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withDatabase( "mydatabase" ).build() ) ) - { - List result = session.run( "MATCH (n) RETURN n.name" ).list( record -> record.get( "n.name" ).asString() ); - - assertThat( result, equalTo( asList( "Bob", "Alice", "Tina" ) ) ); - } - // Finally - assertThat( emptyRouter.exitStatus(), equalTo( 0 ) ); - assertThat( realRouter.exitStatus(), equalTo( 0 ) ); - assertThat( reader.exitStatus(), equalTo( 0 ) ); - } - - @Test - void shouldThrowRoutingErrorIfDatabaseNotFound() throws IOException, InterruptedException, StubServer.ForceKilled - { - // Given - StubServer server = StubServer.start( "acquire_endpoints_v4_database_not_found.script", 9001 ); - - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); - try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ); - Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withDatabase( "mydatabase" ).build() ) ) - { - final FatalDiscoveryException error = assertThrows( FatalDiscoveryException.class, () -> { - session.run( "MATCH (n) RETURN n.name" ); - } ); - - assertThat( error.code(), equalTo( "Neo.ClientError.Database.DatabaseNotFound" ) ); - } - // Finally - assertThat( server.exitStatus(), equalTo( 0 ) ); - } - - @Test - void shouldBeAbleToServeReachableDatabase() throws IOException, InterruptedException, StubServer.ForceKilled - { - // Given - StubServer router = StubServer.start( "acquire_endpoints_v4_multi_db.script", 9001 ); - StubServer readServer = StubServer.start( "read_server_v4_read.script", 9005 ); - - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); - - try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) ) - { - try( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withDatabase( "unreachable" ).build() ) ) - { - final ServiceUnavailableException error = assertThrows( ServiceUnavailableException.class, () -> { - session.run( "MATCH (n) RETURN n.name" ); - } ); - - assertThat( error.getMessage(), containsString( "Could not perform discovery for database 'unreachable'" ) ); - } - - try ( Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).withDatabase( "mydatabase" ).build() ) ) - { - List result = session.run( "MATCH (n) RETURN n.name" ).list( record -> record.get( "n.name" ).asString() ); - - assertThat( result, equalTo( asList( "Bob", "Alice", "Tina" ) ) ); - } - } - // Finally - assertThat( router.exitStatus(), equalTo( 0 ) ); - assertThat( readServer.exitStatus(), equalTo( 0 ) ); - } - - - @Test - void shouldDriverVerifyConnectivity() throws Throwable - { - StubServer router = StubServer.start( "acquire_endpoints_v4_verify_connectivity.script", 9001 ); - StubServer readServer = StubServer.start( "read_server_v4_read.script", 9005 ); - - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); - try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) ) - { - driver.verifyConnectivity(); - try ( Session session = driver.session( builder().withDatabase( "mydatabase" ).withDefaultAccessMode( AccessMode.READ ).build() ) ) - { - List records = session.run( "MATCH (n) RETURN n.name" ).list(); - assertEquals( 3, records.size() ); - } - - Session session = driver.session( builder().withDefaultAccessMode( AccessMode.READ ).build() ); - - driver.close(); - - assertThrows( IllegalStateException.class, () -> session.run( "MATCH (n) RETURN n.name" ) ); - } - finally - { - assertEquals( 0, readServer.exitStatus() ); - assertEquals( 0, router.exitStatus() ); - } - } - - @Test - void shouldPassSystemBookmarkWhenGettingRoutingTableForMultiDB() throws Throwable - { - Bookmark sysBookmark = parse( "sys:1234" ); - Bookmark fooBookmark = parse( "foo:5678" ); - StubServer router = StubServer.start( "acquire_endpoints_v4_with_bookmark.script", 9001 ); - StubServer readServer = StubServer.start( "read_server_v4_read_with_bookmark.script", 9005 ); - - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); - try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) ) - { - try ( Session session = driver.session( builder() - .withDatabase( "foo" ) - .withDefaultAccessMode( AccessMode.READ ) - .withBookmarks( sysBookmark, fooBookmark ) - .build() ) ) - { - List records = session.run( "MATCH (n) RETURN n.name" ).list(); - assertEquals( 3, records.size() ); - assertThat( session.lastBookmark(), equalTo( parse( "foo:6678" ) ) ); - } - } - finally - { - assertEquals( 0, readServer.exitStatus() ); - assertEquals( 0, router.exitStatus() ); - } - } - - @Test - void shouldIgnoreSystemBookmarkWhenGettingRoutingTable() throws Throwable - { - Bookmark sysBookmark = parse( "sys:1234" ); - Bookmark fooBookmark = parse( "foo:5678" ); - StubServer router = StubServer.start( "acquire_endpoints_v3.script", 9001 ); - StubServer readServer = StubServer.start( "read_server_v3_read_with_bookmark.script", 9005 ); - - URI uri = URI.create( "neo4j://127.0.0.1:9001" ); - try ( Driver driver = GraphDatabase.driver( uri, INSECURE_CONFIG ) ) - { - try ( Session session = driver.session( builder() - .withDefaultAccessMode( AccessMode.READ ) - .withBookmarks( sysBookmark, fooBookmark ) // you can still send, the real server will reject in session run of course. - .build() ) ) - { - List records = session.run( "MATCH (n) RETURN n.name" ).list(); - assertEquals( 3, records.size() ); - assertThat( session.lastBookmark(), equalTo( parse( "foo:6678" ) ) ); - } - } - finally - { - assertEquals( 0, readServer.exitStatus() ); - assertEquals( 0, router.exitStatus() ); - } - } -} diff --git a/driver/src/test/resources/acquire_endpoints_v4.script b/driver/src/test/resources/acquire_endpoints_v4.script deleted file mode 100644 index bff325a385..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4.script +++ /dev/null @@ -1,10 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": { "address": "127.0.0.1:9001"}, "database": "mydatabase"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007","127.0.0.1:9008"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]] - SUCCESS {} diff --git a/driver/src/test/resources/acquire_endpoints_v4_database_not_found.script b/driver/src/test/resources/acquire_endpoints_v4_database_not_found.script deleted file mode 100644 index 2067c0be07..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4_database_not_found.script +++ /dev/null @@ -1,9 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": {"address": "127.0.0.1:9001" }, "database": "mydatabase"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: FAILURE {"code": "Neo.ClientError.Database.DatabaseNotFound", "message": "wut!"} - IGNORED diff --git a/driver/src/test/resources/acquire_endpoints_v4_empty.script b/driver/src/test/resources/acquire_endpoints_v4_empty.script deleted file mode 100644 index 8a7d6e3b70..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4_empty.script +++ /dev/null @@ -1,10 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": { "address": "my.virtual.host:8080" }, "database": "mydatabase"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, []] - SUCCESS {} diff --git a/driver/src/test/resources/acquire_endpoints_v4_multi_db.script b/driver/src/test/resources/acquire_endpoints_v4_multi_db.script deleted file mode 100644 index 8b1f4ce589..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4_multi_db.script +++ /dev/null @@ -1,15 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": { "address": "127.0.0.1:9001" }, "database": "unreachable"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, []] - SUCCESS {} -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": { "address": "127.0.0.1:9001" }, "database": "mydatabase"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007","127.0.0.1:9008"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]] - SUCCESS {} diff --git a/driver/src/test/resources/acquire_endpoints_v4_verify_connectivity.script b/driver/src/test/resources/acquire_endpoints_v4_verify_connectivity.script deleted file mode 100644 index 83ccc11f00..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4_verify_connectivity.script +++ /dev/null @@ -1,15 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": {"address": "127.0.0.1:9001"}, "database": "system"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007","127.0.0.1:9008"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]] - SUCCESS {} -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": {"address": "127.0.0.1:9001"}, "database": "mydatabase"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007","127.0.0.1:9008"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]] - SUCCESS {} diff --git a/driver/src/test/resources/acquire_endpoints_v4_virtual_host.script b/driver/src/test/resources/acquire_endpoints_v4_virtual_host.script deleted file mode 100644 index 8d7da13a5d..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4_virtual_host.script +++ /dev/null @@ -1,10 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": { "address": "my.virtual.host:8080" }, "database": "mydatabase"} {"mode": "r", "db": "system"} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007","127.0.0.1:9008"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]] - SUCCESS {} diff --git a/driver/src/test/resources/acquire_endpoints_v4_with_bookmark.script b/driver/src/test/resources/acquire_endpoints_v4_with_bookmark.script deleted file mode 100644 index 004908f278..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v4_with_bookmark.script +++ /dev/null @@ -1,10 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.routing.getRoutingTable($context, $database)" {"context": {"address": "127.0.0.1:9001"}, "database": "foo"} {"mode": "r", "db": "system", "bookmarks": ["sys:1234", "foo:5678"]} - PULL {"n": -1} -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9007","127.0.0.1:9008"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001","127.0.0.1:9002","127.0.0.1:9003"], "role": "ROUTE"}]] - SUCCESS {"bookmark": "sys:2234"} diff --git a/driver/src/test/resources/read_server_v3_read_with_bookmark.script b/driver/src/test/resources/read_server_v3_read_with_bookmark.script deleted file mode 100644 index c44e456e02..0000000000 --- a/driver/src/test/resources/read_server_v3_read_with_bookmark.script +++ /dev/null @@ -1,12 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "MATCH (n) RETURN n.name" {} { "mode": "r", "bookmarks": ["sys:1234", "foo:5678"] } - PULL_ALL -S: SUCCESS {"fields": ["n.name"]} - RECORD ["Bob"] - RECORD ["Alice"] - RECORD ["Tina"] - SUCCESS { "bookmark": "foo:6678" } diff --git a/driver/src/test/resources/read_server_v4_read_with_bookmark.script b/driver/src/test/resources/read_server_v4_read_with_bookmark.script deleted file mode 100644 index 837b12b59e..0000000000 --- a/driver/src/test/resources/read_server_v4_read_with_bookmark.script +++ /dev/null @@ -1,12 +0,0 @@ -!: BOLT 4 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "MATCH (n) RETURN n.name" {} { "mode": "r", "db": "foo", "bookmarks": ["sys:1234", "foo:5678"] } - PULL { "n": 1000 } -S: SUCCESS {"fields": ["n.name"]} - RECORD ["Bob"] - RECORD ["Alice"] - RECORD ["Tina"] - SUCCESS { "bookmark": "foo:6678" } diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CommandProcessor.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CommandProcessor.java index 317fa8087b..5581006247 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/CommandProcessor.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/CommandProcessor.java @@ -175,7 +175,13 @@ else if ( currentLine.equals( "#request end" ) ) private DriverError driverError( String id, Neo4jException e ) { - return DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).errorType( e.getClass().getName() ).build() ).build(); + return DriverError.builder().data( + DriverError.DriverErrorBody.builder() + .id( id ) + .errorType( e.getClass().getName() ) + .code( e.code() ) + .build() ) + .build(); } public void processRequest( String request ) diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/DriverError.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/DriverError.java index 2e373e8e1d..d7379a7484 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/DriverError.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/DriverError.java @@ -43,5 +43,7 @@ public static class DriverErrorBody private String id; private String errorType; + + private String code; } }