Skip to content

Commit 38aaa1a

Browse files
authored
Merge pull request #243 from mneedham/client-exception-on-close
Catch & translate NotALeader exception when session is closed
2 parents 137ea5e + 19abee6 commit 38aaa1a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public void close()
7272
{
7373
throw sessionExpired(e, onError, connection.address());
7474
}
75+
catch ( ClientException e )
76+
{
77+
throw filterFailureToWrite( e, mode, onError, connection.address() );
78+
}
7579
}
7680

7781
public BoltServerAddress address()

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,29 @@ public void shouldHandleConnectionFailuresOnClose()
186186
verify( onError ).onConnectionFailure( LOCALHOST );
187187
verifyNoMoreInteractions( onError );
188188
}
189+
190+
@Test
191+
public void shouldHandleWriteFailuresOnClose()
192+
{
193+
// Given
194+
doThrow( new ClientException( "Neo.ClientError.Cluster.NotALeader", "oh no!" ) ).when( connection ).sync();
195+
196+
RoutingNetworkSession session =
197+
new RoutingNetworkSession( AccessMode.WRITE, connection, onError );
198+
199+
// When
200+
try
201+
{
202+
session.close();
203+
fail();
204+
}
205+
catch ( SessionExpiredException e )
206+
{
207+
//ignore
208+
}
209+
210+
// Then
211+
verify( onError ).onWriteFailure( LOCALHOST );
212+
verifyNoMoreInteractions( onError );
213+
}
189214
}

0 commit comments

Comments
 (0)