Skip to content

Commit 7f4d202

Browse files
author
Zhen
committed
Fix the failing test
1 parent 380e030 commit 7f4d202

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

driver/src/main/java/org/neo4j/driver/internal/security/TLSSocketChannel.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ void channelRead( ByteBuffer toBuffer ) throws IOException
181181
*/
182182
void channelWrite( ByteBuffer fromBuffer ) throws IOException
183183
{
184-
int written = channel.write( fromBuffer );
185-
if (written <= 0)
184+
if ( channel.write( fromBuffer ) < 0 )
186185
{
187186
try
188187
{
@@ -327,7 +326,7 @@ private HandshakeStatus wrap( ByteBuffer buffer ) throws IOException
327326
cipherOut.flip();
328327
while ( cipherOut.hasRemaining() )
329328
{
330-
channel.write( cipherOut );
329+
channelWrite( cipherOut );
331330
}
332331
cipherOut.clear();
333332
break;
@@ -455,12 +454,7 @@ public void close() throws IOException
455454
cipherOut.flip();
456455
while ( cipherOut.hasRemaining() )
457456
{
458-
int num = channel.write( cipherOut );
459-
if ( num == -1 )
460-
{
461-
// handle closed channel
462-
break;
463-
}
457+
channelWrite( cipherOut );
464458
}
465459
cipherOut.clear();
466460
}

driver/src/test/java/org/neo4j/driver/internal/security/TLSSocketChannelTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import javax.net.ssl.SSLHandshakeException;
2727
import javax.net.ssl.SSLSession;
2828

29-
import org.neo4j.driver.internal.logging.DevNullLogger;
3029
import org.neo4j.driver.v1.exceptions.ClientException;
3130
import org.neo4j.driver.v1.exceptions.ServiceUnavailableException;
3231

@@ -40,6 +39,7 @@
4039
import static org.mockito.Mockito.times;
4140
import static org.mockito.Mockito.verify;
4241
import static org.mockito.Mockito.when;
42+
import static org.neo4j.driver.internal.logging.DevNullLogger.DEV_NULL_LOGGER;
4343
import static org.neo4j.driver.internal.security.TLSSocketChannel.create;
4444

4545
public class TLSSocketChannelTest
@@ -59,7 +59,7 @@ public void shouldCloseConnectionIfFailedToRead() throws Throwable
5959
when( mockedSslSession.getPacketBufferSize() ).thenReturn( 10 );
6060

6161
// When
62-
TLSSocketChannel channel = new TLSSocketChannel( mockedChannel, new DevNullLogger(), mockedSslEngine );
62+
TLSSocketChannel channel = new TLSSocketChannel( mockedChannel, DEV_NULL_LOGGER, mockedSslEngine );
6363

6464
try
6565
{
@@ -89,7 +89,7 @@ public void shouldCloseConnectionIfFailedToWrite() throws Throwable
8989
when( mockedSslSession.getPacketBufferSize() ).thenReturn( 10 );
9090

9191
// When
92-
TLSSocketChannel channel = new TLSSocketChannel( mockedChannel, new DevNullLogger(), mockedSslEngine );
92+
TLSSocketChannel channel = new TLSSocketChannel( mockedChannel, DEV_NULL_LOGGER, mockedSslEngine );
9393

9494
try
9595
{
@@ -123,7 +123,7 @@ public void shouldThrowClientErrorIfFailedToHandshake() throws Throwable
123123
// When & Then
124124
try
125125
{
126-
create( mockedChannel, new DevNullLogger(), mockedSslEngine );
126+
create( mockedChannel, DEV_NULL_LOGGER, mockedSslEngine );
127127
fail( "Should fail to run handshake" );
128128
}
129129
catch( Exception e )

0 commit comments

Comments
 (0)