Skip to content

Commit 5803ee3

Browse files
committed
Update backend to report no routing context as DriverError (neo4j#915)
1 parent 13c2dda commit 5803ee3

File tree

3 files changed

+61
-6
lines changed

3 files changed

+61
-6
lines changed

driver/src/main/java/org/neo4j/driver/internal/DriverFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@
6161

6262
public class DriverFactory
6363
{
64+
public static final String NO_ROUTING_CONTEXT_ERROR_MESSAGE = "Routing parameters are not supported with scheme 'bolt'. Given URI: ";
65+
6466
public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings routingSettings,
6567
RetrySettings retrySettings, Config config, SecurityPlan securityPlan )
6668
{
6769
return newInstance( uri, authToken, routingSettings, retrySettings, config, null, securityPlan );
6870
}
6971

70-
public final Driver newInstance ( URI uri, AuthToken authToken, RoutingSettings routingSettings,
71-
RetrySettings retrySettings, Config config, EventLoopGroup eventLoopGroup, SecurityPlan securityPlan )
72+
public final Driver newInstance( URI uri, AuthToken authToken, RoutingSettings routingSettings,
73+
RetrySettings retrySettings, Config config, EventLoopGroup eventLoopGroup, SecurityPlan securityPlan )
7274
{
7375
Bootstrap bootstrap;
7476
boolean ownsEventLoopGroup;
@@ -288,8 +290,7 @@ private static void assertNoRoutingContext( URI uri, RoutingSettings routingSett
288290
RoutingContext routingContext = routingSettings.routingContext();
289291
if ( routingContext.isDefined() )
290292
{
291-
throw new IllegalArgumentException(
292-
"Routing parameters are not supported with scheme 'bolt'. Given URI: '" + uri + "'" );
293+
throw new IllegalArgumentException( NO_ROUTING_CONTEXT_ERROR_MESSAGE + "'" + uri + "'" );
293294
}
294295
}
295296

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import neo4j.org.testkit.backend.TestkitState;
2626
import neo4j.org.testkit.backend.messages.responses.DomainNameResolutionRequired;
2727
import neo4j.org.testkit.backend.messages.responses.Driver;
28+
import neo4j.org.testkit.backend.messages.responses.DriverError;
2829
import neo4j.org.testkit.backend.messages.responses.ResolverResolutionRequired;
2930
import neo4j.org.testkit.backend.messages.responses.TestkitErrorResponse;
3031
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
@@ -82,7 +83,16 @@ public TestkitResponse process( TestkitState testkitState )
8283
}
8384
Optional.ofNullable( data.userAgent ).ifPresent( configBuilder::withUserAgent );
8485
Optional.ofNullable( data.connectionTimeoutMs ).ifPresent( timeout -> configBuilder.withConnectionTimeout( timeout, TimeUnit.MILLISECONDS ) );
85-
testkitState.getDrivers().putIfAbsent( id, driver( URI.create( data.uri ), authToken, configBuilder.build(), domainNameResolver ) );
86+
org.neo4j.driver.Driver driver;
87+
try
88+
{
89+
driver = driver( URI.create( data.uri ), authToken, configBuilder.build(), domainNameResolver );
90+
}
91+
catch ( RuntimeException e )
92+
{
93+
return handleExceptionAsErrorResponse( testkitState, e ).orElseThrow( () -> e );
94+
}
95+
testkitState.getDrivers().putIfAbsent( id, driver );
8696
return Driver.builder().data( Driver.DriverBody.builder().id( id ).build() ).build();
8797
}
8898

@@ -137,6 +147,20 @@ private org.neo4j.driver.Driver driver( URI uri, AuthToken authToken, Config con
137147
.newInstance( uri, authToken, routingSettings, retrySettings, config, securityPlan );
138148
}
139149

150+
private Optional<TestkitResponse> handleExceptionAsErrorResponse( TestkitState testkitState, RuntimeException e )
151+
{
152+
Optional<TestkitResponse> response = Optional.empty();
153+
if ( e instanceof IllegalArgumentException && e.getMessage().startsWith( DriverFactory.NO_ROUTING_CONTEXT_ERROR_MESSAGE ) )
154+
{
155+
String id = testkitState.newId();
156+
String errorType = e.getClass().getName();
157+
response = Optional.of(
158+
DriverError.builder().data( DriverError.DriverErrorBody.builder().id( id ).errorType( errorType ).build() ).build()
159+
);
160+
}
161+
return response;
162+
}
163+
140164
@Setter
141165
@Getter
142166
@NoArgsConstructor

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class StartTest implements TestkitRequest
3636
{
3737
private static final Map<String,String> SKIP_PATTERN_TO_REASON = new LinkedHashMap<>();
3838

39+
private static final String SERVER_INFO_SKIP_REASON_MESSAGE =
40+
"The 4.2 driver backend does not provide server info and its properties were changed in 4.3 drivers";
41+
3942
static
4043
{
4144
SKIP_PATTERN_TO_REASON.put( "^.*retry.TestRetryClustering.test_retry_database_unavailable$", "The test is not applicable to 4.2 driver" );
@@ -44,10 +47,37 @@ public class StartTest implements TestkitRequest
4447
SKIP_PATTERN_TO_REASON.put( "^.*retry.TestRetryClustering.test_retry_NotALeader$", "The test is not applicable to 4.2 driver" );
4548
SKIP_PATTERN_TO_REASON
4649
.put( "^.*retry.TestRetryClustering.test_retry_ForbiddenOnReadOnlyDatabase_ChangingWriter$", "The test is not applicable to 4.2 driver" );
47-
SKIP_PATTERN_TO_REASON.put( "^.*routing.Routing\\..+$", "The tests are not applicable to 4.2 driver" );
50+
SKIP_PATTERN_TO_REASON.put( "^.*test_routing_v4x3.RoutingV4x3\\..+$", "The tests are not applicable to 4.2 driver" );
4851
SKIP_PATTERN_TO_REASON
4952
.put( "^.+routing.Routing.*\\.test_should_successfully_get_server_protocol_version$", "The test is not applicable to 4.2 driver" );
5053
SKIP_PATTERN_TO_REASON.put( "^.+routing.Routing.*\\.test_should_successfully_get_server_agent$", "The test is not applicable to 4.2 driver" );
54+
SKIP_PATTERN_TO_REASON.put( "^.+disconnects.TestDisconnects.*\\.test_client_says_goodbye$", "This test uses 4.3 Bolt" );
55+
SKIP_PATTERN_TO_REASON.put( "^.+disconnects.TestDisconnects.*\\.test_disconnect_after_hello", "This test uses 4.3 Bolt" );
56+
SKIP_PATTERN_TO_REASON.put( "^.+disconnects.TestDisconnects.*\\.test_disconnect_on_tx_begin", "The 4.2 driver disconnects after first next" );
57+
SKIP_PATTERN_TO_REASON.put( "^.+test_no_routing.NoRouting.test_should_read_successfully_using_session_run", SERVER_INFO_SKIP_REASON_MESSAGE );
58+
SKIP_PATTERN_TO_REASON
59+
.put( "^.+test_routing_v3.RoutingV3.test_should_read_successfully_from_reader_using_session_run", SERVER_INFO_SKIP_REASON_MESSAGE );
60+
SKIP_PATTERN_TO_REASON.put( "^.+test_routing_v3.RoutingV3.test_should_read_successfully_from_reader_using_session_run_with_default_db_driver",
61+
SERVER_INFO_SKIP_REASON_MESSAGE );
62+
SKIP_PATTERN_TO_REASON
63+
.put( "^.+test_routing_v3.RoutingV3.test_should_read_successfully_from_reader_using_tx_function", SERVER_INFO_SKIP_REASON_MESSAGE );
64+
SKIP_PATTERN_TO_REASON.put( "^.+test_routing_v3.RoutingV3.test_should_read_successfully_from_reader_using_tx_run", SERVER_INFO_SKIP_REASON_MESSAGE );
65+
SKIP_PATTERN_TO_REASON
66+
.put( "^.+test_routing_v3.RoutingV3.test_should_write_successfully_on_writer_using_session_run", SERVER_INFO_SKIP_REASON_MESSAGE );
67+
SKIP_PATTERN_TO_REASON
68+
.put( "^.+test_routing_v3.RoutingV3.test_should_write_successfully_on_writer_using_tx_function", SERVER_INFO_SKIP_REASON_MESSAGE );
69+
SKIP_PATTERN_TO_REASON.put( "^.+test_routing_v3.RoutingV3.test_should_write_successfully_on_writer_using_tx_run", SERVER_INFO_SKIP_REASON_MESSAGE );
70+
SKIP_PATTERN_TO_REASON
71+
.put( "^.+test_routing_v4x1.RoutingV4x1.test_should_read_successfully_from_reader_using_session_run", SERVER_INFO_SKIP_REASON_MESSAGE );
72+
SKIP_PATTERN_TO_REASON
73+
.put( "^.+test_routing_v4x1.RoutingV4x1.test_should_read_successfully_from_reader_using_tx_function", SERVER_INFO_SKIP_REASON_MESSAGE );
74+
SKIP_PATTERN_TO_REASON
75+
.put( "^.+test_routing_v4x1.RoutingV4x1.test_should_read_successfully_from_reader_using_tx_run", SERVER_INFO_SKIP_REASON_MESSAGE );
76+
SKIP_PATTERN_TO_REASON
77+
.put( "^.+test_routing_v4x1.RoutingV4x1.test_should_write_successfully_on_writer_using_session_run", SERVER_INFO_SKIP_REASON_MESSAGE );
78+
SKIP_PATTERN_TO_REASON
79+
.put( "^.+test_routing_v4x1.RoutingV4x1.test_should_write_successfully_on_writer_using_tx_function", SERVER_INFO_SKIP_REASON_MESSAGE );
80+
SKIP_PATTERN_TO_REASON.put( "^.+test_routing_v4x1.RoutingV4x1.test_should_write_successfully_on_writer_using_tx_run", SERVER_INFO_SKIP_REASON_MESSAGE );
5181
}
5282

5383
private StartTestBody data;

0 commit comments

Comments
 (0)