Skip to content

Commit 4b99a13

Browse files
author
Zhen
committed
Fix the failing test due to unreliable error type on different platforms
1 parent a88c87f commit 4b99a13

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ public void start()
119119
try
120120
{
121121
logger.debug( "~~ [CONNECT] %s", address );
122-
setChannel( ChannelFactory.create( address, securityPlan, timeoutMillis, logger ) );
122+
if( channel == null )
123+
{
124+
setChannel( ChannelFactory.create( address, securityPlan, timeoutMillis, logger ) );
125+
}
123126
protocol = negotiateProtocol();
124127
reader = protocol.reader();
125128
writer = protocol.writer();

driver/src/test/java/org/neo4j/driver/internal/net/SocketClientTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import static org.hamcrest.CoreMatchers.equalTo;
4444
import static org.hamcrest.MatcherAssert.assertThat;
4545
import static org.junit.runners.Parameterized.Parameters;
46+
import static org.mockito.Matchers.any;
4647
import static org.mockito.Mockito.mock;
4748
import static org.mockito.Mockito.when;
4849
import static org.neo4j.driver.internal.logging.DevNullLogger.DEV_NULL_LOGGER;
@@ -123,14 +124,20 @@ public void testConnectionTimeout() throws Throwable
123124
@Test
124125
public void testIOExceptionWhenFailedToEstablishConnection() throws Throwable
125126
{
126-
BoltServerAddress address = new BoltServerAddress( "localhost", 0 ); // an illegal port
127+
BoltServerAddress address = new BoltServerAddress( "localhost", 1234 ); // an random address
127128

128129
SecurityPlan securityPlan = SecurityPlan.insecure();
129130
SocketClient client = new SocketClient( address, securityPlan, CONNECTION_TIMEOUT, DEV_NULL_LOGGER );
130131

132+
ByteChannel mockedChannel = mock( ByteChannel.class );
133+
when( mockedChannel.write( any( ByteBuffer.class ) ) )
134+
.thenThrow( new IOException( "Failed to connect to server due to IOException"
135+
) );
136+
client.setChannel( mockedChannel );
137+
131138
// Expect
132139
exception.expect( ServiceUnavailableException.class );
133-
exception.expectMessage( "Unable to process request: Can't assign requested address" );
140+
exception.expectMessage( "Unable to process request: Failed to connect to server due to IOException" );
134141

135142
// When
136143
client.start();

0 commit comments

Comments
 (0)