Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metadata for Netty SelectorProviderUtil #382

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading