diff --git a/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitIT.java b/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitIT.java index f3dfd859c1..055056c1cc 100644 --- a/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitIT.java +++ b/driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitIT.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.net.URI; -import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.concurrent.TimeUnit; @@ -48,10 +47,8 @@ import org.neo4j.driver.internal.cluster.RoutingSettings; import org.neo4j.driver.internal.retry.RetrySettings; import org.neo4j.driver.internal.security.SecurityPlanImpl; -import org.neo4j.driver.internal.util.DriverFactoryWithClock; import org.neo4j.driver.internal.util.DriverFactoryWithFixedRetryLogic; import org.neo4j.driver.internal.util.Futures; -import org.neo4j.driver.internal.util.SleeplessClock; import org.neo4j.driver.net.ServerAddress; import org.neo4j.driver.net.ServerAddressResolver; import org.neo4j.driver.reactive.RxResult; @@ -63,9 +60,7 @@ 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.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -229,6 +224,8 @@ void shouldFailInitialDiscoveryWhenConfiguredResolverThrows() verify( resolver ).resolve( ServerAddress.of( "my.server.com", 9001 ) ); } + // general error reporting and handling should be improved before this can be moved to testkit + // also, backend closes socket on general errors and it negatively impacts testkit's teardown process @Test void useSessionAfterDriverIsClosed() throws Exception { @@ -256,45 +253,6 @@ void useSessionAfterDriverIsClosed() throws Exception } } - @Test - void shouldServerWithBoltV4SupportMultiDb() throws Throwable - { - StubServer server = stubController.startStub( "support_multidb_v4.script", 9001 ); - try ( Driver driver = GraphDatabase.driver( "neo4j://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( "neo4j://localhost:9001", INSECURE_CONFIG ) ) - { - assertFalse( driver.supportsMultiDb() ); - } - finally - { - assertEquals( 0, server.exitStatus() ); - } - } - - private static Driver newDriverWithSleeplessClock( String uriString, Config config ) - { - DriverFactory driverFactory = new DriverFactoryWithClock( new SleeplessClock() ); - return newDriver( uriString, driverFactory, config ); - } - - private static Driver newDriverWithSleeplessClock( String uriString ) - { - return newDriverWithSleeplessClock( uriString, INSECURE_CONFIG ); - } - private static Driver newDriverWithFixedRetries( String uriString, int retries ) { DriverFactory driverFactory = new DriverFactoryWithFixedRetryLogic( retries ); @@ -318,20 +276,6 @@ private static TransactionWork> queryWork( final String query, fina }; } - private static List readStrings( final String query, Session session ) - { - return session.readTransaction( tx -> - { - List records = tx.run( query ).list(); - List names = new ArrayList<>( records.size() ); - for ( Record record : records ) - { - names.add( record.get( 0 ).asString() ); - } - return names; - } ); - } - static class PortBasedServerAddressComparator implements Comparator { @Override diff --git a/driver/src/test/resources/acquire_endpoints_v3_leader_killed.script b/driver/src/test/resources/acquire_endpoints_v3_leader_killed.script deleted file mode 100644 index 1319603044..0000000000 --- a/driver/src/test/resources/acquire_endpoints_v3_leader_killed.script +++ /dev/null @@ -1,25 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "127.0.0.1:9001"}} {} - PULL_ALL -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9004"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001"], "role": "ROUTE"}]] - SUCCESS {} -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "127.0.0.1:9001"}} {} - PULL_ALL -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9004"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001"], "role": "ROUTE"}]] - SUCCESS {} -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "127.0.0.1:9001"}} {} - PULL_ALL -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": [],"role": "WRITE"}, {"addresses": ["127.0.0.1:9005","127.0.0.1:9006"], "role": "READ"},{"addresses": ["127.0.0.1:9001"], "role": "ROUTE"}]] - SUCCESS {} -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"address": "127.0.0.1:9001"}} {} - PULL_ALL -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["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"], "role": "ROUTE"}]] - SUCCESS {} diff --git a/driver/src/test/resources/get_routing_table_with_context.script b/driver/src/test/resources/get_routing_table_with_context.script deleted file mode 100644 index 803ce97f8a..0000000000 --- a/driver/src/test/resources/get_routing_table_with_context.script +++ /dev/null @@ -1,16 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": {"policy": "my_policy", "region": "china", "address": "127.0.0.1:9001"}} {} - PULL_ALL -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"], "role": "READ"},{"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"], "role": "ROUTE"}]] - SUCCESS {} -C: RUN "MATCH (n) RETURN n.name AS name" {} {} - PULL_ALL -S: SUCCESS {"fields": ["name"]} - RECORD ["Alice"] - RECORD ["Bob"] - SUCCESS {} diff --git a/driver/src/test/resources/routing_context_in_hello_neo4j.script b/driver/src/test/resources/routing_context_in_hello_neo4j.script deleted file mode 100644 index 57db70c3b7..0000000000 --- a/driver/src/test/resources/routing_context_in_hello_neo4j.script +++ /dev/null @@ -1,17 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO GOODBYE - -C: HELLO {"scheme": "none", "user_agent": "neo4j-java/dev", "routing": { "address": "127.0.0.1:9001", "region": "china", "policy": "my_policy"}} -S: SUCCESS {"server": "Neo4j/3.5.0", "connection_id": "bolt-123456789"} -C: RUN "CALL dbms.cluster.routing.getRoutingTable($context)" {"context": { "address": "127.0.0.1:9001", "policy": "my_policy", "region": "china"}} {} - PULL_ALL -S: SUCCESS {"fields": ["ttl", "servers"]} - RECORD [9223372036854775807, [{"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"],"role": "WRITE"}, {"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"], "role": "READ"},{"addresses": ["127.0.0.1:9001", "127.0.0.1:9002"], "role": "ROUTE"}]] - SUCCESS {} -C: RUN "MATCH (n) RETURN n.name AS name" {} {} - PULL_ALL -S: SUCCESS {"fields": ["name"]} - RECORD ["Alice"] - RECORD ["Bob"] - SUCCESS {} diff --git a/driver/src/test/resources/write_server_v3_write_tx.script b/driver/src/test/resources/write_server_v3_write_tx.script deleted file mode 100644 index a99222c641..0000000000 --- a/driver/src/test/resources/write_server_v3_write_tx.script +++ /dev/null @@ -1,13 +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: SUCCESS { "bookmark": "ABookmark" } diff --git a/driver/src/test/resources/write_tx_with_bookmarks.script b/driver/src/test/resources/write_tx_with_bookmarks.script deleted file mode 100644 index b5c178310a..0000000000 --- a/driver/src/test/resources/write_tx_with_bookmarks.script +++ /dev/null @@ -1,13 +0,0 @@ -!: BOLT 3 -!: AUTO RESET -!: AUTO HELLO -!: AUTO GOODBYE - -C: BEGIN {"bookmarks": ["OldBookmark"]} -S: SUCCESS {} -C: RUN "CREATE (n {name:'Bob'})" {} {} - PULL_ALL -S: SUCCESS {} - SUCCESS {} -C: COMMIT -S: SUCCESS {"bookmark": "NewBookmark"} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/CheckMultiDBSupport.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/CheckMultiDBSupport.java new file mode 100644 index 0000000000..e16baa9523 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/CheckMultiDBSupport.java @@ -0,0 +1,50 @@ +/* + * 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 neo4j.org.testkit.backend.messages.requests; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import neo4j.org.testkit.backend.TestkitState; +import neo4j.org.testkit.backend.messages.responses.MultiDBSupport; +import neo4j.org.testkit.backend.messages.responses.TestkitResponse; + +@Setter +@Getter +@NoArgsConstructor +public class CheckMultiDBSupport implements TestkitRequest +{ + private CheckMultiDBSupportBody data; + + @Override + public TestkitResponse process( TestkitState testkitState ) + { + String driverId = data.getDriverId(); + boolean available = testkitState.getDrivers().get( driverId ).supportsMultiDb(); + return MultiDBSupport.builder().data( MultiDBSupport.MultiDBSupportBody.builder().available( available ).build() ).build(); + } + + @Setter + @Getter + @NoArgsConstructor + public static class CheckMultiDBSupportBody + { + private String driverId; + } +} diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java index 8a50c459f7..7d74966fa5 100644 --- a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java @@ -33,7 +33,7 @@ @JsonSubTypes.Type( TransactionRun.class ), @JsonSubTypes.Type( RetryablePositive.class ), @JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ), @JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class ), - @JsonSubTypes.Type( ResolverResolutionCompleted.class ) + @JsonSubTypes.Type( ResolverResolutionCompleted.class ), @JsonSubTypes.Type( CheckMultiDBSupport.class ) } ) public interface TestkitRequest { diff --git a/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/MultiDBSupport.java b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/MultiDBSupport.java new file mode 100644 index 0000000000..67b9cc7b83 --- /dev/null +++ b/testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/MultiDBSupport.java @@ -0,0 +1,47 @@ +/* + * 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 neo4j.org.testkit.backend.messages.responses; + +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +@Builder +public class MultiDBSupport implements TestkitResponse +{ + private final MultiDBSupportBody data; + + @Override + public String testkitName() + { + return "MultiDBSupport"; + } + + @Setter + @Getter + @Builder + public static class MultiDBSupportBody + { + private final String id; + + private final boolean available; + } +}