Skip to content

Commit

Permalink
Migrating tests to testkit (#832)
Browse files Browse the repository at this point in the history
* 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

* Removing redundant stub server scripts
  • Loading branch information
injectives authored Mar 1, 2021
1 parent a19d468 commit 2a6c6f1
Show file tree
Hide file tree
Showing 32 changed files with 302 additions and 1,183 deletions.

Large diffs are not rendered by default.

10 changes: 0 additions & 10 deletions driver/src/test/resources/acquire_endpoints_v3_9010.script

This file was deleted.

10 changes: 0 additions & 10 deletions driver/src/test/resources/acquire_endpoints_v3_empty.script

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions driver/src/test/resources/dead_read_server.script

This file was deleted.

12 changes: 0 additions & 12 deletions driver/src/test/resources/discover_failed.script

This file was deleted.

10 changes: 0 additions & 10 deletions driver/src/test/resources/discover_no_writers.script

This file was deleted.

10 changes: 0 additions & 10 deletions driver/src/test/resources/discover_no_writers_9010.script

This file was deleted.

10 changes: 0 additions & 10 deletions driver/src/test/resources/discover_one_router.script

This file was deleted.

10 changes: 0 additions & 10 deletions driver/src/test/resources/discover_servers_9010.script

This file was deleted.

This file was deleted.

18 changes: 0 additions & 18 deletions driver/src/test/resources/get_routing_table.script

This file was deleted.

13 changes: 0 additions & 13 deletions driver/src/test/resources/not_able_to_write_server.script

This file was deleted.

16 changes: 0 additions & 16 deletions driver/src/test/resources/read_server_v3_read_tx.script

This file was deleted.

15 changes: 0 additions & 15 deletions driver/src/test/resources/read_tx_with_bookmarks.script

This file was deleted.

18 changes: 0 additions & 18 deletions driver/src/test/resources/rediscover_using_initial_router.script

This file was deleted.

22 changes: 0 additions & 22 deletions driver/src/test/resources/write_read_tx_with_bookmarks.script

This file was deleted.

9 changes: 0 additions & 9 deletions driver/src/test/resources/write_server_v3_write.script

This file was deleted.

9 changes: 0 additions & 9 deletions driver/src/test/resources/write_with_bookmarks.script

This file was deleted.

10 changes: 0 additions & 10 deletions driver/src/test/resources/writer_unavailable.script

This file was deleted.

2 changes: 1 addition & 1 deletion testkit-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import neo4j.org.testkit.backend.messages.TestkitModule;
import neo4j.org.testkit.backend.messages.requests.TestkitRequest;
Expand Down Expand Up @@ -147,7 +146,7 @@ else if ( currentLine.equals( "#request end" ) )
// Error to track
String id = testkitState.newId();
testkitState.getErrors().put( id, (Neo4jException) e );
writeResponse( driverError( id ) );
writeResponse( driverError( id, (Neo4jException) e ) );
System.out.println( "Neo4jException: " + e );
}
else
Expand All @@ -174,9 +173,9 @@ else if ( currentLine.equals( "#request end" ) )
}
}

private DriverError driverError( String id )
private DriverError driverError( String id, Neo4jException e )
{
return DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).build() ).build();
return DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).errorType( e.getClass().getName() ).build() ).build();
}

public void processRequest( String request )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.neo4j.driver.Driver;
import org.neo4j.driver.Result;
import org.neo4j.driver.Transaction;
import org.neo4j.driver.exceptions.Neo4jException;
import org.neo4j.driver.net.ServerAddress;

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

public TestkitState( Consumer<TestkitResponse> responseWriter, Supplier<Boolean> processor )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import lombok.Setter;
import neo4j.org.testkit.backend.TestkitState;
import neo4j.org.testkit.backend.messages.responses.Driver;
import neo4j.org.testkit.backend.messages.responses.ResolverResolutionRequired;
import neo4j.org.testkit.backend.messages.responses.TestkitErrorResponse;
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;

Expand All @@ -32,6 +33,7 @@
import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Config;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.net.ServerAddressResolver;

@Setter
@Getter
Expand Down Expand Up @@ -59,11 +61,35 @@ public TestkitResponse process( TestkitState testkitState )
}

Config.ConfigBuilder configBuilder = Config.builder();
if ( data.isResolverRegistered() )
{
configBuilder.withResolver( callbackResolver( testkitState ) );
}
Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
testkitState.getDrivers().putIfAbsent( id, GraphDatabase.driver( data.uri, authToken, configBuilder.build() ) );
return Driver.builder().data( Driver.DriverBody.builder().id( id ).build() ).build();
}

private ServerAddressResolver callbackResolver( TestkitState testkitState )
{
return address ->
{
String callbackId = testkitState.newId();
ResolverResolutionRequired.ResolverResolutionRequiredBody body =
ResolverResolutionRequired.ResolverResolutionRequiredBody.builder()
.id( callbackId )
.address( address.toString() )
.build();
ResolverResolutionRequired response =
ResolverResolutionRequired.builder()
.data( body )
.build();
testkitState.getResponseWriter().accept( response );
testkitState.getProcessor().get();
return testkitState.getIdToServerAddresses().remove( callbackId );
};
}

@Setter
@Getter
@NoArgsConstructor
Expand All @@ -72,5 +98,6 @@ public static class NewDriverBody
private String uri;
private AuthorizationToken authorizationToken;
private String userAgent;
private boolean resolverRegistered;
}
}
Loading

0 comments on commit 2a6c6f1

Please sign in to comment.