Skip to content

Commit c5e56fd

Browse files
authored
Merge pull request #257 from neo4j/1.1-deprecate-connection-failure-exception
Remove ConnectionFailureException
2 parents b282660 + d16377c commit c5e56fd

18 files changed

+59
-100
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.neo4j.driver.v1.Value;
3535
import org.neo4j.driver.v1.Values;
3636
import org.neo4j.driver.v1.exceptions.ClientException;
37-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
37+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3838
import org.neo4j.driver.v1.types.TypeSystem;
3939

4040
import static org.neo4j.driver.v1.Values.value;
@@ -306,9 +306,9 @@ private void ensureConnectionIsOpen()
306306
{
307307
if ( !connection.isOpen() )
308308
{
309-
throw new ConnectionFailureException( "The current session cannot be reused as the underlying connection with the " +
310-
"server has been closed due to unrecoverable errors. " +
311-
"Please close this session and retry your statement in another new session." );
309+
throw new ServiceUnavailableException( "The current session cannot be reused as the underlying connection with the " +
310+
"server has been closed due to unrecoverable errors. " +
311+
"Please close this session and retry your statement in another new session." );
312312
}
313313
}
314314

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import org.neo4j.driver.v1.StatementResult;
3434
import org.neo4j.driver.v1.Value;
3535
import org.neo4j.driver.v1.exceptions.ClientException;
36-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
3736
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3837
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
3938
import org.neo4j.driver.v1.util.Function;
@@ -287,7 +286,7 @@ private Connection acquireReadConnection()
287286
{
288287
return connections.acquire( address );
289288
}
290-
catch ( ConnectionFailureException e )
289+
catch ( ServiceUnavailableException e )
291290
{
292291
forget( address );
293292
}
@@ -306,7 +305,7 @@ private Connection acquireWriteConnection()
306305
{
307306
return connections.acquire( address );
308307
}
309-
catch ( ConnectionFailureException e )
308+
catch ( ServiceUnavailableException e )
310309
{
311310
forget( address );
312311
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import org.neo4j.driver.v1.Value;
3232
import org.neo4j.driver.v1.Values;
3333
import org.neo4j.driver.v1.exceptions.ClientException;
34-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
3534
import org.neo4j.driver.v1.exceptions.Neo4jException;
35+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3636
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
3737
import org.neo4j.driver.v1.types.TypeSystem;
3838

@@ -91,7 +91,7 @@ public StatementResult run( Statement statement )
9191
{
9292
return new RoutingStatementResult( delegate.run( statement ), mode, address, onError );
9393
}
94-
catch ( ConnectionFailureException e )
94+
catch ( ServiceUnavailableException e )
9595
{
9696
throw sessionExpired( e, onError, address );
9797
}
@@ -144,7 +144,7 @@ public void close()
144144
{
145145
delegate.close();
146146
}
147-
catch ( ConnectionFailureException e )
147+
catch ( ServiceUnavailableException e )
148148
{
149149
throw sessionExpired(e, onError, address);
150150
}
@@ -189,7 +189,7 @@ static Neo4jException filterFailureToWrite( ClientException e, AccessMode mode,
189189
}
190190
}
191191

192-
static SessionExpiredException sessionExpired( ConnectionFailureException e, RoutingErrorHandler onError,
192+
static SessionExpiredException sessionExpired( ServiceUnavailableException e, RoutingErrorHandler onError,
193193
BoltServerAddress address )
194194
{
195195
onError.onConnectionFailure( address );

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import org.neo4j.driver.v1.Record;
2626
import org.neo4j.driver.v1.StatementResult;
2727
import org.neo4j.driver.v1.exceptions.ClientException;
28-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
28+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
2929
import org.neo4j.driver.v1.exceptions.NoSuchRecordException;
3030
import org.neo4j.driver.v1.summary.ResultSummary;
3131
import org.neo4j.driver.v1.util.Function;
@@ -56,7 +56,7 @@ public List<String> keys()
5656
{
5757
return delegate.keys();
5858
}
59-
catch ( ConnectionFailureException e )
59+
catch ( ServiceUnavailableException e )
6060
{
6161
throw sessionExpired( e, onError, address );
6262
}
@@ -73,7 +73,7 @@ public boolean hasNext()
7373
{
7474
return delegate.hasNext();
7575
}
76-
catch ( ConnectionFailureException e )
76+
catch ( ServiceUnavailableException e )
7777
{
7878
throw sessionExpired( e, onError, address );
7979
}
@@ -90,7 +90,7 @@ public Record next()
9090
{
9191
return delegate.next();
9292
}
93-
catch ( ConnectionFailureException e )
93+
catch ( ServiceUnavailableException e )
9494
{
9595
throw sessionExpired( e, onError, address );
9696
}
@@ -108,7 +108,7 @@ public Record single() throws NoSuchRecordException
108108
{
109109
return delegate.single();
110110
}
111-
catch ( ConnectionFailureException e )
111+
catch ( ServiceUnavailableException e )
112112
{
113113
throw sessionExpired( e, onError, address );
114114
}
@@ -125,7 +125,7 @@ public Record peek()
125125
{
126126
return delegate.peek();
127127
}
128-
catch ( ConnectionFailureException e )
128+
catch ( ServiceUnavailableException e )
129129
{
130130
throw sessionExpired( e, onError, address );
131131
}
@@ -142,7 +142,7 @@ public List<Record> list()
142142
{
143143
return delegate.list();
144144
}
145-
catch ( ConnectionFailureException e )
145+
catch ( ServiceUnavailableException e )
146146
{
147147
throw sessionExpired( e, onError, address );
148148
}
@@ -159,7 +159,7 @@ public <T> List<T> list( Function<Record, T> mapFunction )
159159
{
160160
return delegate.list( mapFunction );
161161
}
162-
catch ( ConnectionFailureException e )
162+
catch ( ServiceUnavailableException e )
163163
{
164164
throw sessionExpired( e, onError, address );
165165
}
@@ -182,7 +182,7 @@ public ResultSummary consume()
182182
{
183183
return delegate.consume();
184184
}
185-
catch ( ConnectionFailureException e )
185+
catch ( ServiceUnavailableException e )
186186
{
187187
throw sessionExpired( e, onError, address );
188188
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.neo4j.driver.v1.Value;
3131
import org.neo4j.driver.v1.Values;
3232
import org.neo4j.driver.v1.exceptions.ClientException;
33-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
33+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3434
import org.neo4j.driver.v1.types.TypeSystem;
3535

3636
import static org.neo4j.driver.internal.RoutingNetworkSession.filterFailureToWrite;
@@ -89,7 +89,7 @@ public StatementResult run( Statement statement )
8989
{
9090
return new RoutingStatementResult( delegate.run( statement ), mode, address, onError );
9191
}
92-
catch ( ConnectionFailureException e )
92+
catch ( ServiceUnavailableException e )
9393
{
9494
throw sessionExpired( e, onError, address );
9595
}
@@ -131,7 +131,7 @@ public void close()
131131
{
132132
delegate.close();
133133
}
134-
catch ( ConnectionFailureException e )
134+
catch ( ServiceUnavailableException e )
135135
{
136136
throw sessionExpired(e, onError, address);
137137
}

driver/src/main/java/org/neo4j/driver/internal/net/BufferingChunkedInput.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.neo4j.driver.internal.packstream.PackInput;
2828
import org.neo4j.driver.internal.util.BytePrinter;
2929
import org.neo4j.driver.v1.exceptions.ClientException;
30-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
30+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3131

3232
import static java.lang.Math.min;
3333

@@ -417,14 +417,14 @@ static void readNextPacket( ReadableByteChannel channel, ByteBuffer buffer ) thr
417417
{
418418
// best effort
419419
}
420-
throw new ConnectionFailureException(
420+
throw new ServiceUnavailableException(
421421
"Connection terminated while receiving data. This can happen due to network " +
422422
"instabilities, or due to restarts of the database." );
423423
}
424424
}
425425
catch ( ClosedByInterruptException e )
426426
{
427-
throw new ConnectionFailureException(
427+
throw new ServiceUnavailableException(
428428
"Connection to the database was lost because someone called `interrupt()` on the driver " +
429429
"thread waiting for a reply. " +
430430
"This normally happens because the JVM is shutting down, but it can also happen because your " +
@@ -434,7 +434,7 @@ static void readNextPacket( ReadableByteChannel channel, ByteBuffer buffer ) thr
434434
catch ( IOException e )
435435
{
436436
String message = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
437-
throw new ConnectionFailureException(
437+
throw new ServiceUnavailableException(
438438
"Unable to process request: " + message + " buffer: \n" + BytePrinter.hex( buffer ), e );
439439
}
440440
finally

driver/src/main/java/org/neo4j/driver/internal/net/SocketClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.neo4j.driver.internal.util.BytePrinter;
3535
import org.neo4j.driver.v1.Logger;
3636
import org.neo4j.driver.v1.exceptions.ClientException;
37-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
37+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3838

3939
import static java.lang.String.format;
4040
import static java.nio.ByteOrder.BIG_ENDIAN;
@@ -85,7 +85,7 @@ void blockingRead( ByteBuffer buf ) throws IOException
8585
// best effort
8686
}
8787
String bufStr = BytePrinter.hex( buf ).trim();
88-
throw new ConnectionFailureException( format(
88+
throw new ServiceUnavailableException( format(
8989
"Connection terminated while receiving data. This can happen due to network " +
9090
"instabilities, or due to restarts of the database. Expected %s bytes, received %s.",
9191
buf.limit(), bufStr.isEmpty() ? "none" : bufStr ) );
@@ -108,7 +108,7 @@ void blockingWrite( ByteBuffer buf ) throws IOException
108108
// best effort
109109
}
110110
String bufStr = BytePrinter.hex( buf ).trim();
111-
throw new ConnectionFailureException( format(
111+
throw new ServiceUnavailableException( format(
112112
"Connection terminated while sending data. This can happen due to network " +
113113
"instabilities, or due to restarts of the database. Expected %s bytes, wrote %s.",
114114
buf.limit(), bufStr.isEmpty() ? "none" :bufStr ) );
@@ -128,7 +128,7 @@ public void start()
128128
}
129129
catch ( ConnectException e )
130130
{
131-
throw new ConnectionFailureException( format(
131+
throw new ServiceUnavailableException( format(
132132
"Unable to connect to %s, ensure the database is running and that there is a " +
133133
"working network connection to it.", address ) );
134134
}

driver/src/main/java/org/neo4j/driver/v1/exceptions/ConnectionFailureException.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
import org.junit.Test;
2323
import org.junit.rules.ExpectedException;
2424

25-
import org.neo4j.driver.internal.logging.DevNullLogger;
2625
import org.neo4j.driver.internal.spi.Connection;
27-
import org.neo4j.driver.v1.Logger;
2826
import org.neo4j.driver.v1.Transaction;
2927
import org.neo4j.driver.v1.exceptions.ClientException;
30-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
28+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3129

3230
import static junit.framework.Assert.fail;
3331
import static junit.framework.TestCase.assertNotNull;
@@ -122,7 +120,7 @@ public void shouldNotAllowMoreStatementsInSessionWhileConnectionClosed() throws
122120
when( mock.isOpen() ).thenReturn( false );
123121

124122
// Expect
125-
exception.expect( ConnectionFailureException.class );
123+
exception.expect( ServiceUnavailableException.class );
126124

127125
// When
128126
sess.run( "whatever" );
@@ -135,7 +133,7 @@ public void shouldNotAllowMoreTransactionsInSessionWhileConnectionClosed() throw
135133
when( mock.isOpen() ).thenReturn( false );
136134

137135
// Expect
138-
exception.expect( ConnectionFailureException.class );
136+
exception.expect( ServiceUnavailableException.class );
139137

140138
// When
141139
sess.beginTransaction();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import org.neo4j.driver.v1.Record;
4646
import org.neo4j.driver.v1.Session;
4747
import org.neo4j.driver.v1.Transaction;
48-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
4948
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
5049
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
5150
import org.neo4j.driver.v1.util.Function;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.neo4j.driver.v1.AccessMode;
3030
import org.neo4j.driver.v1.Session;
3131
import org.neo4j.driver.v1.exceptions.ClientException;
32-
import org.neo4j.driver.v1.exceptions.ConnectionFailureException;
32+
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3333
import org.neo4j.driver.v1.exceptions.SessionExpiredException;
3434

3535
import static org.hamcrest.MatcherAssert.assertThat;
@@ -64,7 +64,7 @@ public void setUp()
6464
public void shouldHandleConnectionFailures()
6565
{
6666
// Given
67-
doThrow( new ConnectionFailureException( "oh no" ) ).
67+
doThrow( new ServiceUnavailableException( "oh no" ) ).
6868
when( connection ).run( anyString(), any( Map.class ), any( Collector.class ) );
6969

7070
RoutingNetworkSession result =
@@ -167,7 +167,7 @@ public void shouldRethrowNonWriteFailures()
167167
public void shouldHandleConnectionFailuresOnClose()
168168
{
169169
// Given
170-
doThrow( new ConnectionFailureException( "oh no" ) ).
170+
doThrow( new ServiceUnavailableException( "oh no" ) ).
171171
when( connection ).sync();
172172

173173
RoutingNetworkSession session =

0 commit comments

Comments
 (0)