Skip to content

Commit a015866

Browse files
author
Zhen Li
authored
Merge pull request #233 from pontusmelke/1.1-service-available-on-all-get-servers-failures
Handle all failures from getServers
2 parents 28dc4cb + 23a0483 commit a015866

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

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

+8-14
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,15 @@ public void accept( Record record )
180180
connections.purge( remove );
181181
}
182182
}
183-
catch ( ClientException ex )
183+
catch ( Exception ex )
184184
{
185-
if ( ex.code().equals( "Neo.ClientError.Procedure.ProcedureNotFound" ) )
186-
{
187-
//no procedure there, not much to do, stick with what we've got
188-
//this may happen because server is running in standalone mode
189-
this.close();
190-
throw new ServiceUnavailableException(
191-
String.format( "Server %s couldn't perform discovery",
192-
address == null ? "`UNKNOWN`" : address.toString() ), ex );
193-
}
194-
else
195-
{
196-
throw ex;
197-
}
185+
//discovery failed, not much to do, stick with what we've got
186+
//this may happen because server is running in standalone mode
187+
this.close();
188+
throw new ServiceUnavailableException(
189+
String.format( "Server %s couldn't perform discovery",
190+
address == null ? "`UNKNOWN`" : address.toString() ), ex );
191+
198192
}
199193
}
200194

driver/src/test/java/org/neo4j/driver/internal/ClusterDriverStubTest.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,29 @@ public void run()
406406
@Test
407407
public void shouldFailOnNonDiscoverableServer() throws IOException, InterruptedException, StubServer.ForceKilled
408408
{
409+
//Expect
410+
exception.expect( ServiceUnavailableException.class );
411+
412+
// Given
413+
StubServer.start( resource( "non_discovery_server.script" ), 9001 );
414+
URI uri = URI.create( "bolt+routing://127.0.0.1:9001" );
415+
409416
// When
410-
StubServer server = StubServer.start( resource( "non_discovery_server.script" ), 9001 );
417+
GraphDatabase.driver( uri, config );
418+
}
411419

420+
@Test
421+
public void shouldFailRandomFailureInGetServers() throws IOException, InterruptedException, StubServer.ForceKilled
422+
{
423+
//Expect
424+
exception.expect( ServiceUnavailableException.class );
425+
426+
// Given
427+
StubServer.start( resource( "failed_discovery.script" ), 9001 );
412428
URI uri = URI.create( "bolt+routing://127.0.0.1:9001" );
413-
boolean failed = false;
414-
//noinspection EmptyTryBlock
415-
try
416-
{
417-
GraphDatabase.driver( uri, config );
418-
}
419-
catch ( ServiceUnavailableException e )
420-
{
421-
failed = true;
422-
}
423-
assertTrue( failed );
424429

425-
// Finally
426-
assertThat( server.exitStatus(), equalTo( 0 ) );
430+
// When
431+
GraphDatabase.driver( uri, config );
427432
}
428433

429434
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
!: AUTO INIT
2+
!: AUTO RESET
3+
!: AUTO RUN "RETURN 1 // JavaDriver poll to test connection" {}
4+
!: AUTO PULL_ALL
5+
6+
C: RUN "CALL dbms.cluster.routing.getServers" {}
7+
PULL_ALL
8+
S: FAILURE {"code": "Neo.ClientError.General.Unknown", "message": "wut!"}
9+
S: IGNORED
10+
C: ACK_FAILURE
11+
S: SUCCESS {}

0 commit comments

Comments
 (0)