Skip to content

Commit

Permalink
Add testcase to ensure NioEventLoop.rebuildSelector() works correctly.
Browse files Browse the repository at this point in the history
Motivation:

We had recently a report that the issue [netty#6607] is still not fixed.

Modifications:

Add a testcase to prove the issue is fixed.

Result:

More tests.
  • Loading branch information
normanmaurer authored and liuzhengyang committed Sep 10, 2017
1 parent 1da5f5d commit 6e98959
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions transport/src/test/java/io/netty/channel/nio/NioEventLoopTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@
package io.netty.channel.nio;

import io.netty.channel.AbstractEventLoopTest;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.ServerSocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import org.junit.Test;

import java.nio.channels.Selector;

import static org.junit.Assert.*;

public class NioEventLoopTest extends AbstractEventLoopTest {

Expand All @@ -31,4 +37,35 @@ protected EventLoopGroup newEventLoopGroup() {
protected Class<? extends ServerSocketChannel> newChannel() {
return NioServerSocketChannel.class;
}

@Test
public void testRebuildSelector() throws Exception {
EventLoopGroup group = new NioEventLoopGroup(1);
final NioEventLoop loop = (NioEventLoop) group.next();
try {
Channel channel = new NioServerSocketChannel();
loop.register(channel).syncUninterruptibly();

Selector selector = loop.unwrappedSelector();
assertSame(selector, ((NioEventLoop) channel.eventLoop()).unwrappedSelector());
assertTrue(selector.isOpen());

// Submit to the EventLoop so we are sure its really executed in a non-async manner.
loop.submit(new Runnable() {
@Override
public void run() {
loop.rebuildSelector();
}
}).syncUninterruptibly();

Selector newSelector = ((NioEventLoop) channel.eventLoop()).unwrappedSelector();
assertTrue(newSelector.isOpen());
assertNotSame(selector, newSelector);
assertFalse(selector.isOpen());

channel.close().syncUninterruptibly();
} finally {
group.shutdownGracefully();
}
}
}

0 comments on commit 6e98959

Please sign in to comment.