Skip to content

Commit 1de4b2d

Browse files
authored
Migrating tests to testkit part 3 (#840)
Adding support for supportsMultiDB call. And exporting the following tests to testkit: - shouldServerWithBoltV4SupportMultiDb -> test_should_successfully_check_if_support_for_multi_db_is_available - shouldServerWithBoltV3NotSupportMultiDb -> test_should_successfully_check_if_support_for_multi_db_is_available Removing redundant scripts
1 parent 0c7c3c5 commit 1de4b2d

File tree

9 files changed

+100
-143
lines changed

9 files changed

+100
-143
lines changed

driver/src/test/java/org/neo4j/driver/integration/RoutingDriverBoltKitIT.java

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.io.IOException;
2929
import java.net.URI;
30-
import java.util.ArrayList;
3130
import java.util.Comparator;
3231
import java.util.List;
3332
import java.util.concurrent.TimeUnit;
@@ -48,10 +47,8 @@
4847
import org.neo4j.driver.internal.cluster.RoutingSettings;
4948
import org.neo4j.driver.internal.retry.RetrySettings;
5049
import org.neo4j.driver.internal.security.SecurityPlanImpl;
51-
import org.neo4j.driver.internal.util.DriverFactoryWithClock;
5250
import org.neo4j.driver.internal.util.DriverFactoryWithFixedRetryLogic;
5351
import org.neo4j.driver.internal.util.Futures;
54-
import org.neo4j.driver.internal.util.SleeplessClock;
5552
import org.neo4j.driver.net.ServerAddress;
5653
import org.neo4j.driver.net.ServerAddressResolver;
5754
import org.neo4j.driver.reactive.RxResult;
@@ -63,9 +60,7 @@
6360
import static org.hamcrest.core.IsEqual.equalTo;
6461
import static org.hamcrest.junit.MatcherAssert.assertThat;
6562
import static org.junit.jupiter.api.Assertions.assertEquals;
66-
import static org.junit.jupiter.api.Assertions.assertFalse;
6763
import static org.junit.jupiter.api.Assertions.assertThrows;
68-
import static org.junit.jupiter.api.Assertions.assertTrue;
6964
import static org.mockito.ArgumentMatchers.any;
7065
import static org.mockito.Mockito.mock;
7166
import static org.mockito.Mockito.verify;
@@ -229,6 +224,8 @@ void shouldFailInitialDiscoveryWhenConfiguredResolverThrows()
229224
verify( resolver ).resolve( ServerAddress.of( "my.server.com", 9001 ) );
230225
}
231226

227+
// general error reporting and handling should be improved before this can be moved to testkit
228+
// also, backend closes socket on general errors and it negatively impacts testkit's teardown process
232229
@Test
233230
void useSessionAfterDriverIsClosed() throws Exception
234231
{
@@ -256,45 +253,6 @@ void useSessionAfterDriverIsClosed() throws Exception
256253
}
257254
}
258255

259-
@Test
260-
void shouldServerWithBoltV4SupportMultiDb() throws Throwable
261-
{
262-
StubServer server = stubController.startStub( "support_multidb_v4.script", 9001 );
263-
try ( Driver driver = GraphDatabase.driver( "neo4j://localhost:9001", INSECURE_CONFIG ) )
264-
{
265-
assertTrue( driver.supportsMultiDb() );
266-
}
267-
finally
268-
{
269-
assertEquals( 0, server.exitStatus() );
270-
}
271-
}
272-
273-
@Test
274-
void shouldServerWithBoltV3NotSupportMultiDb() throws Throwable
275-
{
276-
StubServer server = stubController.startStub( "support_multidb_v3.script", 9001 );
277-
try ( Driver driver = GraphDatabase.driver( "neo4j://localhost:9001", INSECURE_CONFIG ) )
278-
{
279-
assertFalse( driver.supportsMultiDb() );
280-
}
281-
finally
282-
{
283-
assertEquals( 0, server.exitStatus() );
284-
}
285-
}
286-
287-
private static Driver newDriverWithSleeplessClock( String uriString, Config config )
288-
{
289-
DriverFactory driverFactory = new DriverFactoryWithClock( new SleeplessClock() );
290-
return newDriver( uriString, driverFactory, config );
291-
}
292-
293-
private static Driver newDriverWithSleeplessClock( String uriString )
294-
{
295-
return newDriverWithSleeplessClock( uriString, INSECURE_CONFIG );
296-
}
297-
298256
private static Driver newDriverWithFixedRetries( String uriString, int retries )
299257
{
300258
DriverFactory driverFactory = new DriverFactoryWithFixedRetryLogic( retries );
@@ -318,20 +276,6 @@ private static TransactionWork<List<Record>> queryWork( final String query, fina
318276
};
319277
}
320278

321-
private static List<String> readStrings( final String query, Session session )
322-
{
323-
return session.readTransaction( tx ->
324-
{
325-
List<Record> records = tx.run( query ).list();
326-
List<String> names = new ArrayList<>( records.size() );
327-
for ( Record record : records )
328-
{
329-
names.add( record.get( 0 ).asString() );
330-
}
331-
return names;
332-
} );
333-
}
334-
335279
static class PortBasedServerAddressComparator implements Comparator<ServerAddress>
336280
{
337281
@Override

driver/src/test/resources/acquire_endpoints_v3_leader_killed.script

Lines changed: 0 additions & 25 deletions
This file was deleted.

driver/src/test/resources/get_routing_table_with_context.script

Lines changed: 0 additions & 16 deletions
This file was deleted.

driver/src/test/resources/routing_context_in_hello_neo4j.script

Lines changed: 0 additions & 17 deletions
This file was deleted.

driver/src/test/resources/write_server_v3_write_tx.script

Lines changed: 0 additions & 13 deletions
This file was deleted.

driver/src/test/resources/write_tx_with_bookmarks.script

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.requests;
20+
21+
import lombok.Getter;
22+
import lombok.NoArgsConstructor;
23+
import lombok.Setter;
24+
import neo4j.org.testkit.backend.TestkitState;
25+
import neo4j.org.testkit.backend.messages.responses.MultiDBSupport;
26+
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
27+
28+
@Setter
29+
@Getter
30+
@NoArgsConstructor
31+
public class CheckMultiDBSupport implements TestkitRequest
32+
{
33+
private CheckMultiDBSupportBody data;
34+
35+
@Override
36+
public TestkitResponse process( TestkitState testkitState )
37+
{
38+
String driverId = data.getDriverId();
39+
boolean available = testkitState.getDrivers().get( driverId ).supportsMultiDb();
40+
return MultiDBSupport.builder().data( MultiDBSupport.MultiDBSupportBody.builder().available( available ).build() ).build();
41+
}
42+
43+
@Setter
44+
@Getter
45+
@NoArgsConstructor
46+
public static class CheckMultiDBSupportBody
47+
{
48+
private String driverId;
49+
}
50+
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
@JsonSubTypes.Type( TransactionRun.class ), @JsonSubTypes.Type( RetryablePositive.class ),
3434
@JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ),
3535
@JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class ),
36-
@JsonSubTypes.Type( ResolverResolutionCompleted.class )
36+
@JsonSubTypes.Type( ResolverResolutionCompleted.class ), @JsonSubTypes.Type( CheckMultiDBSupport.class )
3737
} )
3838
public interface TestkitRequest
3939
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.responses;
20+
21+
import lombok.Builder;
22+
import lombok.Getter;
23+
import lombok.Setter;
24+
25+
@Setter
26+
@Getter
27+
@Builder
28+
public class MultiDBSupport implements TestkitResponse
29+
{
30+
private final MultiDBSupportBody data;
31+
32+
@Override
33+
public String testkitName()
34+
{
35+
return "MultiDBSupport";
36+
}
37+
38+
@Setter
39+
@Getter
40+
@Builder
41+
public static class MultiDBSupportBody
42+
{
43+
private final String id;
44+
45+
private final boolean available;
46+
}
47+
}

0 commit comments

Comments
 (0)