Netty クライアントとサーバーを同じ jvm で実行しているときに問題が発生し、サーバーを停止しようとしました。これを例示する私のコードは次のとおりです。
@BeforeMethod
public void setUp() {
serverBootstrap = new ServerBootstrap(new DefaultLocalServerChannelFactory());
serverBootstrap.getPipeline().addLast("my-server-handler", new ServerHandler());
LocalAddress local = new LocalAddress("1");
serverChannel = serverBootstrap.bind(local);
clientBootstrap = new ClientBootstrap(new DefaultLocalClientChannelFactory());
clientBootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("my-client-handler", new ClientHandler());
return pipeline;
}
});
ChannelFuture future = clientBootstrap.connect(local);
if (future.isSuccess())
System.out.println("Client connected");
clientChannel = future.getChannel();
}
@AfterMethod
public void tearDown() {
closeServer();
clientChannel.close().awaitUninterruptibly();
clientBootstrap.releaseExternalResources();
}
@Test
public void shoulClose() {
sendData();
closeServer();
sendData();
}
private void closeServer() {
serverChannel.close().awaitUninterruptibly();
serverBootstrap.releaseExternalResources();
}
private void sendData() {
clientChannel.write(new byte[] { 1, 2, 3 });
}
これを Netty 3.4.0.Final と 3.4.4.Final でテストしましたが、何が間違っているのかわかりません。
サーバーがダウンした後でもクライアントがサーバーにデータを送信できるのはなぜですか?