Skip to content

Commit bc3d675

Browse files
authored
Add metadata for Netty SelectorProviderUtil (#382)
* Add metadata for Netty SelectorProviderUtil * add testcase for Netty SelectorProviderUtil
1 parent 2c3d0f6 commit bc3d675

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

metadata/io.netty/netty-common/4.1.80.Final/reflect-config.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,6 +3838,34 @@
38383838
}
38393839
]
38403840
},
3841+
{
3842+
"condition": {
3843+
"typeReachable": "io.netty.channel.socket.nio.NioServerSocketChannel"
3844+
},
3845+
"name": "java.nio.channels.spi.SelectorProvider",
3846+
"methods": [
3847+
{
3848+
"name": "openServerSocketChannel",
3849+
"parameterTypes": [
3850+
"java.net.ProtocolFamily"
3851+
]
3852+
}
3853+
]
3854+
},
3855+
{
3856+
"condition": {
3857+
"typeReachable": "io.netty.channel.socket.nio.NioSocketChannel"
3858+
},
3859+
"name": "java.nio.channels.spi.SelectorProvider",
3860+
"methods": [
3861+
{
3862+
"name": "openSocketChannel",
3863+
"parameterTypes": [
3864+
"java.net.ProtocolFamily"
3865+
]
3866+
}
3867+
]
3868+
},
38413869
{
38423870
"condition": {
38433871
"typeReachable": "io.netty.util.internal.logging.Slf4JLoggerFactory"

tests/src/io.netty/netty-common/4.1.80.Final/src/test/java/netty/NettyTests.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
package netty;
88

99
import java.io.InputStream;
10+
import java.net.Inet6Address;
11+
import java.nio.channels.UnsupportedAddressTypeException;
12+
import java.nio.channels.spi.SelectorProvider;
1013
import java.time.Duration;
1114
import java.util.Objects;
1215
import java.util.concurrent.atomic.AtomicReference;
@@ -56,8 +59,13 @@
5659
import io.netty.util.CharsetUtil;
5760
import org.awaitility.Awaitility;
5861
import org.hamcrest.CoreMatchers;
62+
import org.junit.jupiter.api.Assertions;
63+
import org.junit.jupiter.api.Assumptions;
5964
import org.junit.jupiter.api.Test;
6065

66+
import static io.netty.channel.socket.InternetProtocolFamily.IPv4;
67+
import static io.netty.util.NetUtil.LOCALHOST;
68+
6169
public class NettyTests {
6270
private static final int PORT = 8080;
6371

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

82+
@Test
83+
void testNioSocketChannel() {
84+
Assumptions.assumeTrue(LOCALHOST instanceof Inet6Address);
85+
86+
EventLoopGroup group = new NioEventLoopGroup();
87+
try {
88+
Bootstrap b = new Bootstrap().group(group)
89+
.channelFactory(() -> new NioSocketChannel(SelectorProvider.provider(), IPv4))
90+
.handler(new LoggingHandler());
91+
Assertions.assertThrows(UnsupportedAddressTypeException.class, () -> b.bind(LOCALHOST, 7777).sync().channel());
92+
} finally {
93+
group.shutdownGracefully();
94+
}
95+
}
96+
97+
@Test
98+
void testNioServerSocketChannel() {
99+
Assumptions.assumeTrue(LOCALHOST instanceof Inet6Address);
100+
101+
EventLoopGroup group = new NioEventLoopGroup();
102+
try {
103+
Bootstrap b = new Bootstrap().group(group)
104+
.channelFactory(() -> new NioServerSocketChannel(SelectorProvider.provider(), IPv4))
105+
.handler(new LoggingHandler());
106+
Assertions.assertThrows(UnsupportedAddressTypeException.class, () -> b.bind(LOCALHOST, 7777).sync().channel());
107+
} finally {
108+
group.shutdownGracefully();
109+
}
110+
}
111+
74112
private void test(boolean ssl) throws Exception {
75113
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
76114
EventLoopGroup workerGroup = new NioEventLoopGroup();

0 commit comments

Comments
 (0)