@@ -127,20 +127,13 @@ public void shouldHandleFailureToWrite()
127
127
@ Test
128
128
public void shouldPropagateThrowable ()
129
129
{
130
- RuntimeException error = new RuntimeException ( "Random error" );
131
- Connector connector = newConnectorWithThrowingConnections ( error );
132
- RoutingTable routingTable = newRoutingTable ( ADDRESS1 , ADDRESS2 , ADDRESS3 );
133
- ConnectionPool connectionPool = newConnectionPool ( connector , ADDRESS1 , ADDRESS2 , ADDRESS3 );
134
- LoadBalancer loadBalancer = newLoadBalancer ( routingTable , connectionPool );
135
-
136
- Connection readConnection = loadBalancer .acquireReadConnection ();
137
- verifyThrowablePropagation ( readConnection , method , routingTable , connectionPool );
138
-
139
- Connection writeConnection = loadBalancer .acquireWriteConnection ();
140
- verifyThrowablePropagation ( writeConnection , method , routingTable , connectionPool );
130
+ testThrowablePropagation ( new RuntimeException ( "Random error" ) );
131
+ }
141
132
142
- assertThat ( routingTable , containsRouter ( ADDRESS3 ) );
143
- assertTrue ( connectionPool .hasAddress ( ADDRESS3 ) );
133
+ @ Test
134
+ public void shouldPropagateClientExceptionWithoutErrorCode ()
135
+ {
136
+ testThrowablePropagation ( new ClientException ( null , "Message" ) );
144
137
}
145
138
146
139
private void testHandleFailureToWriteWithWriteConnection ( ClientException error )
@@ -199,6 +192,23 @@ private void testHandleFailureToWrite( ClientException error )
199
192
assertTrue ( connectionPool .hasAddress ( ADDRESS3 ) );
200
193
}
201
194
195
+ private void testThrowablePropagation ( Throwable error )
196
+ {
197
+ Connector connector = newConnectorWithThrowingConnections ( error );
198
+ RoutingTable routingTable = newRoutingTable ( ADDRESS1 , ADDRESS2 , ADDRESS3 );
199
+ ConnectionPool connectionPool = newConnectionPool ( connector , ADDRESS1 , ADDRESS2 , ADDRESS3 );
200
+ LoadBalancer loadBalancer = newLoadBalancer ( routingTable , connectionPool );
201
+
202
+ Connection readConnection = loadBalancer .acquireReadConnection ();
203
+ verifyThrowablePropagation ( readConnection , routingTable , connectionPool , error .getClass () );
204
+
205
+ Connection writeConnection = loadBalancer .acquireWriteConnection ();
206
+ verifyThrowablePropagation ( writeConnection , routingTable , connectionPool , error .getClass () );
207
+
208
+ assertThat ( routingTable , containsRouter ( ADDRESS3 ) );
209
+ assertTrue ( connectionPool .hasAddress ( ADDRESS3 ) );
210
+ }
211
+
202
212
private void verifyServiceUnavailableHandling ( Connection connection , RoutingTable routingTable ,
203
213
ConnectionPool connectionPool )
204
214
{
@@ -220,8 +230,8 @@ private void verifyServiceUnavailableHandling( Connection connection, RoutingTab
220
230
}
221
231
}
222
232
223
- private void verifyThrowablePropagation ( Connection connection , ConnectionMethod method , RoutingTable routingTable ,
224
- ConnectionPool connectionPool )
233
+ private < T extends Throwable > void verifyThrowablePropagation ( Connection connection , RoutingTable routingTable ,
234
+ ConnectionPool connectionPool , Class < T > expectedClass )
225
235
{
226
236
try
227
237
{
@@ -230,7 +240,7 @@ private void verifyThrowablePropagation( Connection connection, ConnectionMethod
230
240
}
231
241
catch ( Exception e )
232
242
{
233
- assertThat ( e , instanceOf ( RuntimeException . class ) );
243
+ assertThat ( e , instanceOf ( expectedClass ) );
234
244
235
245
BoltServerAddress address = connection .boltServerAddress ();
236
246
assertThat ( routingTable , containsRouter ( address ) );
0 commit comments