Skip to content

Commit

Permalink
Add metadata for Netty SelectorProviderUtil (#382)
Browse files Browse the repository at this point in the history
* Add metadata for Netty SelectorProviderUtil

* add testcase for Netty SelectorProviderUtil
  • Loading branch information
czp3009 authored Jan 23, 2024
1 parent 2c3d0f6 commit bc3d675
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
28 changes: 28 additions & 0 deletions metadata/io.netty/netty-common/4.1.80.Final/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3838,6 +3838,34 @@
}
]
},
{
"condition": {
"typeReachable": "io.netty.channel.socket.nio.NioServerSocketChannel"
},
"name": "java.nio.channels.spi.SelectorProvider",
"methods": [
{
"name": "openServerSocketChannel",
"parameterTypes": [
"java.net.ProtocolFamily"
]
}
]
},
{
"condition": {
"typeReachable": "io.netty.channel.socket.nio.NioSocketChannel"
},
"name": "java.nio.channels.spi.SelectorProvider",
"methods": [
{
"name": "openSocketChannel",
"parameterTypes": [
"java.net.ProtocolFamily"
]
}
]
},
{
"condition": {
"typeReachable": "io.netty.util.internal.logging.Slf4JLoggerFactory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
package netty;

import java.io.InputStream;
import java.net.Inet6Address;
import java.nio.channels.UnsupportedAddressTypeException;
import java.nio.channels.spi.SelectorProvider;
import java.time.Duration;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicReference;
Expand Down Expand Up @@ -56,8 +59,13 @@
import io.netty.util.CharsetUtil;
import org.awaitility.Awaitility;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;

import static io.netty.channel.socket.InternetProtocolFamily.IPv4;
import static io.netty.util.NetUtil.LOCALHOST;

public class NettyTests {
private static final int PORT = 8080;

Expand All @@ -71,6 +79,36 @@ public void noSsl() throws Exception {
test(false);
}

@Test
void testNioSocketChannel() {
Assumptions.assumeTrue(LOCALHOST instanceof Inet6Address);

EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap().group(group)
.channelFactory(() -> new NioSocketChannel(SelectorProvider.provider(), IPv4))
.handler(new LoggingHandler());
Assertions.assertThrows(UnsupportedAddressTypeException.class, () -> b.bind(LOCALHOST, 7777).sync().channel());
} finally {
group.shutdownGracefully();
}
}

@Test
void testNioServerSocketChannel() {
Assumptions.assumeTrue(LOCALHOST instanceof Inet6Address);

EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap().group(group)
.channelFactory(() -> new NioServerSocketChannel(SelectorProvider.provider(), IPv4))
.handler(new LoggingHandler());
Assertions.assertThrows(UnsupportedAddressTypeException.class, () -> b.bind(LOCALHOST, 7777).sync().channel());
} finally {
group.shutdownGracefully();
}
}

private void test(boolean ssl) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
Expand Down

0 comments on commit bc3d675

Please sign in to comment.