This repository has been archived by the owner on Aug 7, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw ClosedChannelException when FastJ8SocketChannel.read() fails du…
…e to underlying being closed. Fixes #214
- Loading branch information
1 parent
fa05549
commit 22ee0a2
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/net/openhft/chronicle/network/tcp/FastJ8SocketChannelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package net.openhft.chronicle.network.tcp; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ClosedChannelException; | ||
import java.nio.channels.ServerSocketChannel; | ||
import java.nio.channels.SocketChannel; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
|
||
public class FastJ8SocketChannelTest { | ||
|
||
@Test | ||
public void closedChannelExceptionIsThrownWhenAttemptIsMadeToReadFromClosedChannel() throws IOException { | ||
try (final ServerSocketChannel local = ServerSocketChannel.open().bind(new InetSocketAddress("localhost", 0))) { | ||
local.configureBlocking(false); | ||
try (final SocketChannel remote = SocketChannel.open(local.socket().getLocalSocketAddress())) { | ||
remote.configureBlocking(false); | ||
final FastJ8SocketChannel fastJ8SocketChannel = new FastJ8SocketChannel(remote); | ||
remote.close(); | ||
assertThrows(ClosedChannelException.class, () -> fastJ8SocketChannel.read(ByteBuffer.allocateDirect(100))); | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
public void closedChannelExceptionIsThrownWhenAttemptIsMadeToWriteToClosedChannel() throws IOException { | ||
try (final ServerSocketChannel local = ServerSocketChannel.open().bind(new InetSocketAddress("localhost", 0))) { | ||
local.configureBlocking(false); | ||
try (final SocketChannel remote = SocketChannel.open(local.socket().getLocalSocketAddress())) { | ||
remote.configureBlocking(false); | ||
final FastJ8SocketChannel fastJ8SocketChannel = new FastJ8SocketChannel(remote); | ||
remote.close(); | ||
assertThrows(ClosedChannelException.class, () -> fastJ8SocketChannel.write(ByteBuffer.allocateDirect(100))); | ||
} | ||
} | ||
} | ||
} |