Hi all,
What's the expected state of a server socket channel once the close() or disconnect() is invoked ?
Below code reports that server socket channel is still active even after the close() future is sync'ed.
final EchoServerHandler serverHandler = new EchoServerHandler();
EventLoopGroup group = new NioEventLoopGroup();
ServerBootstrap serverBootstrap = new ServerBootstrap();
serverBootstrap.group(group)
.channel(NioServerSocketChannel.class)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>(){
@Override
public void initChannel(SocketChannel ch)
throws Exception {
ch.pipeline().addLast(serverHandler);
}
});
ChannelFuture channelFuture = serverBootstrap.bind().sync();
System.out.println("Server started");
Thread.sleep(5000);
Assert.assertTrue(channelFuture.channel().close().sync().isSuccess());
Assert.assertFalse(channelFuture.channel().isActive(), "Channel is active");
It fails on the last assertion with
Exception in thread "Thread-0" java.lang.AssertionError: Channel is active expected [false] but found [true]
at org.testng.Assert.fail(Assert.java:94)
at org.testng.Assert.failNotEquals(Assert.java:513)
at org.testng.Assert.assertFalse(Assert.java:63)
at EchoServer.start(EchoServer.java:43)
at ServerStarter.run(NettyTest.java:21)
at java.lang.Thread.run(Thread.java:748)
What's the rational behind it ?
Thanks
Priyanka