use of io.netty.channel.SelectStrategy in project netty by netty.
the class NioEventLoopTest method testRebuildSelectorOnIOException.
@Test
public void testRebuildSelectorOnIOException() {
SelectStrategyFactory selectStrategyFactory = new SelectStrategyFactory() {
@Override
public SelectStrategy newSelectStrategy() {
return new SelectStrategy() {
private boolean thrown;
@Override
public int calculateStrategy(IntSupplier selectSupplier, boolean hasTasks) throws Exception {
if (!thrown) {
thrown = true;
throw new IOException();
}
return -1;
}
};
}
};
EventLoopGroup group = new NioEventLoopGroup(1, new DefaultThreadFactory("ioPool"), SelectorProvider.provider(), selectStrategyFactory);
final NioEventLoop loop = (NioEventLoop) group.next();
try {
Channel channel = new NioServerSocketChannel();
Selector selector = loop.unwrappedSelector();
loop.register(channel).syncUninterruptibly();
Selector newSelector = ((NioEventLoop) channel.eventLoop()).unwrappedSelector();
assertTrue(newSelector.isOpen());
assertNotSame(selector, newSelector);
assertFalse(selector.isOpen());
channel.close().syncUninterruptibly();
} finally {
group.shutdownGracefully();
}
}
Aggregations