Skip to content

Commit 0383f30

Browse files
committed
Migrating tests to testkit
Short summary of this update: - removed migrated tests - verifyConnectivity support - resolver support - consume support Test mapping (dest: stub/routing.py): - shouldHandleAcquireReadSession -> test_should_read_successfully_from_reader_using_session_run - shouldHandleAcquireReadTransaction -> test_should_read_successfully_from_reader_using_tx_function - shouldHandleAcquireReadSessionAndTransaction -> test_should_read_successfully_from_reader_using_tx_run - shouldRoundRobinReadServers -> test_should_round_robin_readers_when_reading_using_session_run - shouldRoundRobinReadServersWhenUsingTransaction -> test_should_round_robin_readers_when_reading_using_tx_run - shouldThrowSessionExpiredIfReadServerDisappears -> test_should_fail_when_reading_from_unexpectedly_interrupting_reader_using_session_run - shouldThrowSessionExpiredIfReadServerDisappearsWhenUsingTransaction -> test_should_fail_when_reading_from_unexpectedly_interrupting_reader_using_tx_run - shouldThrowSessionExpiredIfWriteServerDisappears -> test_should_fail_when_writing_on_unexpectedly_interrupting_writer_using_session_run - shouldThrowSessionExpiredIfWriteServerDisappearsWhenUsingTransaction -> test_should_fail_when_writing_on_unexpectedly_interrupting_writer_using_tx_run - shouldHandleAcquireWriteSession -> test_should_write_successfully_on_writer_using_session_run - shouldHandleAcquireWriteTransaction -> test_should_write_successfully_on_writer_using_tx_function - shouldHandleAcquireWriteSessionAndTransaction -> test_should_write_successfully_on_writer_using_tx_run - shouldRoundRobinWriteSessions -> test_should_round_robin_writers_when_writing_using_session_run - shouldRoundRobinWriteSessionsInTransaction -> test_should_round_robin_writers_when_writing_using_tx_run - shouldFailOnNonDiscoverableServer -> test_should_fail_discovery_when_router_fails_with_procedure_not_found_code - shouldFailRandomFailureInGetServers -> test_should_fail_discovery_when_router_fails_with_unknown_code - shouldHandleLeaderSwitchWhenWriting -> test_should_fail_when_writing_on_writer_that_returns_not_a_leader_code - shouldHandleLeaderSwitchWhenWritingWithoutConsuming -> test_should_fail_when_writing_without_explicit_consumption_on_writer_that_returns_not_a_leader_code - shouldHandleLeaderSwitchWhenWritingInTransaction -> test_should_fail_when_writing_on_writer_that_returns_not_a_leader_code_using_tx_run - shouldUseWriteSessionModeAndInitialBookmark -> test_should_use_write_session_mode_and_initial_bookmark_when_writing_using_tx_run - shouldUseReadSessionModeAndInitialBookmark -> test_should_use_read_session_mode_and_initial_bookmark_when_reading_using_tx_run - shouldPassBookmarkFromTransactionToTransaction -> test_should_pass_bookmark_from_tx_to_tx_using_tx_run - shouldRetryReadTransactionUntilSuccess -> test_should_retry_read_tx_until_success - shouldRetryWriteTransactionUntilSuccess -> test_should_retry_write_tx_until_success - shouldRetryReadTransactionAndPerformRediscoveryUntilSuccess -> test_should_retry_read_tx_and_rediscovery_until_success - shouldRetryWriteTransactionAndPerformRediscoveryUntilSuccess -> test_should_retry_write_tx_and_rediscovery_until_success - shouldUseInitialRouterForRediscoveryWhenAllOtherRoutersAreDead -> test_should_use_initial_router_for_discovery_when_others_unavailable - shouldInvokeProcedureGetRoutingTableWhenServerVersionPermits -> test_should_successfully_read_from_readable_router_using_tx_function - shouldSendEmptyRoutingContextInHelloMessage -> test_should_send_empty_hello - shouldServeReadsButFailWritesWhenNoWritersAvailable -> test_should_serve_reads_and_fail_writes_when_no_writers_available - shouldAcceptRoutingTableWithoutWritersAndThenRediscover -> test_should_accept_routing_table_without_writers_and_then_rediscover - shouldTreatRoutingTableWithSingleRouterAsValid -> test_should_accept_routing_table_with_single_router - shouldSendMultipleBookmarks -> test_should_successfully_send_multiple_bookmarks - shouldForgetAddressOnDatabaseUnavailableError -> test_should_forget_address_on_database_unavailable_error - shouldUseResolverDuringRediscoveryWhenExistingRoutersFail -> test_should_use_resolver_during_rediscovery_when_existing_routers_fail - shouldRevertToInitialRouterIfKnownRouterThrowsProtocolErrors -> test_should_revert_to_initial_router_if_known_router_throws_protocol_errors
1 parent a19d468 commit 0383f30

File tree

12 files changed

+302
-934
lines changed

12 files changed

+302
-934
lines changed

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

Lines changed: 14 additions & 928 deletions
Large diffs are not rendered by default.

testkit-backend/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>org.projectlombok</groupId>
3737
<artifactId>lombok</artifactId>
38-
<version>1.18.12</version>
38+
<version>1.18.16</version>
3939
<scope>provided</scope>
4040
</dependency>
4141

testkit-backend/src/main/java/neo4j/org/testkit/backend/CommandProcessor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.fasterxml.jackson.core.JsonProcessingException;
2222
import com.fasterxml.jackson.databind.DeserializationFeature;
23-
import com.fasterxml.jackson.databind.JsonNode;
2423
import com.fasterxml.jackson.databind.ObjectMapper;
2524
import neo4j.org.testkit.backend.messages.TestkitModule;
2625
import neo4j.org.testkit.backend.messages.requests.TestkitRequest;
@@ -147,7 +146,7 @@ else if ( currentLine.equals( "#request end" ) )
147146
// Error to track
148147
String id = testkitState.newId();
149148
testkitState.getErrors().put( id, (Neo4jException) e );
150-
writeResponse( driverError( id ) );
149+
writeResponse( driverError( id, (Neo4jException) e ) );
151150
System.out.println( "Neo4jException: " + e );
152151
}
153152
else
@@ -174,9 +173,9 @@ else if ( currentLine.equals( "#request end" ) )
174173
}
175174
}
176175

177-
private DriverError driverError( String id )
176+
private DriverError driverError( String id, Neo4jException e )
178177
{
179-
return DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).build() ).build();
178+
return DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).errorType( e.getClass().getName() ).build() ).build();
180179
}
181180

182181
public void processRequest( String request )

testkit-backend/src/main/java/neo4j/org/testkit/backend/TestkitState.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323

2424
import java.util.HashMap;
2525
import java.util.Map;
26+
import java.util.Set;
2627
import java.util.function.Consumer;
2728
import java.util.function.Supplier;
2829

2930
import org.neo4j.driver.Driver;
3031
import org.neo4j.driver.Result;
3132
import org.neo4j.driver.Transaction;
3233
import org.neo4j.driver.exceptions.Neo4jException;
34+
import org.neo4j.driver.net.ServerAddress;
3335

3436
@Getter
3537
public class TestkitState
@@ -42,6 +44,7 @@ public class TestkitState
4244
private int idGenerator = 0;
4345
private final Consumer<TestkitResponse> responseWriter;
4446
private final Supplier<Boolean> processor;
47+
private final Map<String,Set<ServerAddress>> idToServerAddresses = new HashMap<>();
4548

4649
public TestkitState( Consumer<TestkitResponse> responseWriter, Supplier<Boolean> processor )
4750
{

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import lombok.Setter;
2424
import neo4j.org.testkit.backend.TestkitState;
2525
import neo4j.org.testkit.backend.messages.responses.Driver;
26+
import neo4j.org.testkit.backend.messages.responses.ResolverResolutionRequired;
2627
import neo4j.org.testkit.backend.messages.responses.TestkitErrorResponse;
2728
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
2829

@@ -32,6 +33,7 @@
3233
import org.neo4j.driver.AuthTokens;
3334
import org.neo4j.driver.Config;
3435
import org.neo4j.driver.GraphDatabase;
36+
import org.neo4j.driver.net.ServerAddressResolver;
3537

3638
@Setter
3739
@Getter
@@ -59,11 +61,35 @@ public TestkitResponse process( TestkitState testkitState )
5961
}
6062

6163
Config.ConfigBuilder configBuilder = Config.builder();
64+
if ( data.isResolverRegistered() )
65+
{
66+
configBuilder.withResolver( callbackResolver( testkitState ) );
67+
}
6268
Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
6369
testkitState.getDrivers().putIfAbsent( id, GraphDatabase.driver( data.uri, authToken, configBuilder.build() ) );
6470
return Driver.builder().data( Driver.DriverBody.builder().id( id ).build() ).build();
6571
}
6672

73+
private ServerAddressResolver callbackResolver( TestkitState testkitState )
74+
{
75+
return address ->
76+
{
77+
String callbackId = testkitState.newId();
78+
ResolverResolutionRequired.ResolverResolutionRequiredBody body =
79+
ResolverResolutionRequired.ResolverResolutionRequiredBody.builder()
80+
.id( callbackId )
81+
.address( address.toString() )
82+
.build();
83+
ResolverResolutionRequired response =
84+
ResolverResolutionRequired.builder()
85+
.data( body )
86+
.build();
87+
testkitState.getResponseWriter().accept( response );
88+
testkitState.getProcessor().get();
89+
return testkitState.getIdToServerAddresses().remove( callbackId );
90+
};
91+
}
92+
6793
@Setter
6894
@Getter
6995
@NoArgsConstructor
@@ -72,5 +98,6 @@ public static class NewDriverBody
7298
private String uri;
7399
private AuthorizationToken authorizationToken;
74100
private String userAgent;
101+
private boolean resolverRegistered;
75102
}
76103
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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.TestkitResponse;
26+
27+
import java.util.LinkedHashSet;
28+
import java.util.List;
29+
import java.util.stream.Collectors;
30+
31+
import org.neo4j.driver.internal.BoltServerAddress;
32+
33+
@Setter
34+
@Getter
35+
@NoArgsConstructor
36+
public class ResolverResolutionCompleted implements TestkitRequest
37+
{
38+
private ResolverResolutionCompletedBody data;
39+
40+
@Override
41+
public TestkitResponse process( TestkitState testkitState )
42+
{
43+
testkitState.getIdToServerAddresses().put( data.getRequestId(), data.getAddresses().stream().map( BoltServerAddress::new )
44+
.collect( Collectors.toCollection( LinkedHashSet::new ) ) );
45+
return null;
46+
}
47+
48+
@Setter
49+
@Getter
50+
@NoArgsConstructor
51+
public static class ResolverResolutionCompletedBody
52+
{
53+
private String requestId;
54+
private List<String> addresses;
55+
}
56+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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.NullRecord;
26+
import neo4j.org.testkit.backend.messages.responses.ResultSummary;
27+
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
28+
29+
import org.neo4j.driver.Result;
30+
import org.neo4j.driver.exceptions.NoSuchRecordException;
31+
32+
@Setter
33+
@Getter
34+
@NoArgsConstructor
35+
public class ResultConsume implements TestkitRequest
36+
{
37+
private ResultConsumeBody data;
38+
39+
@Override
40+
public TestkitResponse process( TestkitState testkitState )
41+
{
42+
try
43+
{
44+
Result result = testkitState.getResults().get( data.getResultId() );
45+
result.consume();
46+
return ResultSummary.builder().build();
47+
}
48+
catch ( NoSuchRecordException ignored )
49+
{
50+
return NullRecord.builder().build();
51+
}
52+
}
53+
54+
@Setter
55+
@Getter
56+
@NoArgsConstructor
57+
public static class ResultConsumeBody
58+
{
59+
private String resultId;
60+
}
61+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
@JsonSubTypes( {
2828
@JsonSubTypes.Type( NewDriver.class ), @JsonSubTypes.Type( NewSession.class ),
2929
@JsonSubTypes.Type( SessionRun.class ), @JsonSubTypes.Type( ResultNext.class ),
30+
@JsonSubTypes.Type( ResultConsume.class ), @JsonSubTypes.Type( VerifyConnectivity.class ),
3031
@JsonSubTypes.Type( SessionClose.class ), @JsonSubTypes.Type( DriverClose.class ),
3132
@JsonSubTypes.Type( RetryableNegative.class ), @JsonSubTypes.Type( SessionReadTransaction.class ),
3233
@JsonSubTypes.Type( TransactionRun.class ), @JsonSubTypes.Type( RetryablePositive.class ),
3334
@JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ),
34-
@JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class )
35+
@JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class ),
36+
@JsonSubTypes.Type( ResolverResolutionCompleted.class )
3537
} )
3638
public interface TestkitRequest
3739
{
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.Driver;
26+
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
27+
28+
@Setter
29+
@Getter
30+
@NoArgsConstructor
31+
public class VerifyConnectivity implements TestkitRequest
32+
{
33+
private VerifyConnectivityBody data;
34+
35+
@Override
36+
public TestkitResponse process( TestkitState testkitState )
37+
{
38+
String id = data.getDriverId();
39+
testkitState.getDrivers().get( id ).verifyConnectivity();
40+
return Driver.builder().data( Driver.DriverBody.builder().id( id ).build() ).build();
41+
}
42+
43+
@Setter
44+
@Getter
45+
@NoArgsConstructor
46+
public static class VerifyConnectivityBody
47+
{
48+
private String driverId;
49+
}
50+
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/responses/DriverError.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,7 @@ public String testkitName()
4141
public static class DriverErrorBody
4242
{
4343
private String id;
44+
45+
private String errorType;
4446
}
4547
}
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 ResolverResolutionRequired implements TestkitResponse
29+
{
30+
private ResolverResolutionRequiredBody data;
31+
32+
@Override
33+
public String testkitName()
34+
{
35+
return "ResolverResolutionRequired";
36+
}
37+
38+
@Setter
39+
@Getter
40+
@Builder
41+
public static class ResolverResolutionRequiredBody
42+
{
43+
private String id;
44+
45+
private String address;
46+
}
47+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 ResultSummary implements TestkitResponse
29+
{
30+
@Override
31+
public String testkitName()
32+
{
33+
return "ResultSummary";
34+
}
35+
}

0 commit comments

Comments
 (0)