diff --git a/transport/src/test/java/io/netty/channel/nio/NioSocketChannelTest.java b/transport/src/test/java/io/netty/channel/nio/NioSocketChannelTest.java index 04195e9c45..69b601a757 100644 --- a/transport/src/test/java/io/netty/channel/nio/NioSocketChannelTest.java +++ b/transport/src/test/java/io/netty/channel/nio/NioSocketChannelTest.java @@ -30,6 +30,7 @@ import io.netty.channel.ChannelPipeline; import io.netty.channel.EventLoop; import io.netty.channel.EventLoopGroup; import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.util.CharsetUtil; @@ -39,8 +40,10 @@ import org.junit.Test; import java.io.DataInput; import java.io.DataInputStream; +import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; import java.nio.channels.ClosedChannelException; @@ -240,4 +243,39 @@ public class NioSocketChannelTest { group.shutdownGracefully(); } } + + @Test(timeout = 3000) + public void testShutdownOutputAndClose() throws IOException { + NioEventLoopGroup group = new NioEventLoopGroup(1); + ServerSocket socket = new ServerSocket(); + socket.bind(new InetSocketAddress(0)); + Socket accepted = null; + try { + Bootstrap sb = new Bootstrap(); + sb.group(group).channel(NioSocketChannel.class); + sb.handler(new ChannelInboundHandlerAdapter()); + + SocketChannel channel = (SocketChannel) sb.connect(socket.getLocalSocketAddress()) + .syncUninterruptibly().channel(); + + accepted = socket.accept(); + channel.shutdownOutput().syncUninterruptibly(); + + channel.close().syncUninterruptibly(); + } finally { + if (accepted != null) { + try { + accepted.close(); + } catch (IOException ignore) { + // ignore + } + } + try { + socket.close(); + } catch (IOException ignore) { + // ignore + } + group.shutdownGracefully(); + } + } }