Add Unit test for [#7143]
This commit is contained in:
parent
c80fdc8241
commit
dd9ad15b12
@ -30,6 +30,7 @@ import io.netty.channel.ChannelPipeline;
|
|||||||
import io.netty.channel.EventLoop;
|
import io.netty.channel.EventLoop;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.util.CharsetUtil;
|
import io.netty.util.CharsetUtil;
|
||||||
@ -39,8 +40,10 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
@ -240,4 +243,39 @@ public class NioSocketChannelTest {
|
|||||||
group.shutdownGracefully();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user