Skip to content

Commit 705ef80

Browse files
committed
Add native transport dependencies and parameterized tests for VirtualMultithreadIoEventLoopGroup
1 parent 7b9b122 commit 705ef80

2 files changed

Lines changed: 92 additions & 8 deletions

File tree

core/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
<artifactId>junit-jupiter-api</artifactId>
2323
<scope>test</scope>
2424
</dependency>
25+
<dependency>
26+
<groupId>org.junit.jupiter</groupId>
27+
<artifactId>junit-jupiter-params</artifactId>
28+
<version>${junit.version}</version>
29+
<scope>test</scope>
30+
</dependency>
31+
<!-- Add native transport test dependency so tests can reference Epoll classes directly. -->
32+
<dependency>
33+
<groupId>io.netty</groupId>
34+
<artifactId>netty-transport-native-epoll</artifactId>
35+
<version>${netty.version}</version>
36+
<classifier>linux-x86_64</classifier>
37+
<scope>test</scope>
38+
</dependency>
2539
</dependencies>
2640

2741
<build>

core/src/test/java/io/netty/loom/VirtualMultithreadIoEventLoopGroupTest.java

Lines changed: 78 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.concurrent.atomic.AtomicBoolean;
1919
import java.util.concurrent.atomic.AtomicInteger;
2020
import java.util.concurrent.atomic.AtomicReference;
21+
import java.util.stream.Stream;
2122

2223
import io.netty.channel.Channel;
2324
import io.netty.channel.ChannelInboundHandlerAdapter;
@@ -28,8 +29,13 @@
2829
import io.netty.channel.IoHandlerFactory;
2930
import io.netty.channel.IoRegistration;
3031
import io.netty.channel.local.LocalIoHandler;
32+
import io.netty.channel.epoll.Epoll;
33+
import io.netty.channel.epoll.EpollIoHandler;
34+
import io.netty.channel.epoll.EpollServerSocketChannel;
3135

3236
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.params.ParameterizedTest;
38+
import org.junit.jupiter.params.provider.MethodSource;
3339

3440
import io.netty.bootstrap.ServerBootstrap;
3541
import io.netty.channel.nio.NioIoHandler;
@@ -50,13 +56,74 @@
5056

5157
public class VirtualMultithreadIoEventLoopGroupTest {
5258

53-
@Test
54-
void processHttpRequestWithVirtualThreadOnManualNettyEventLoop() throws InterruptedException {
55-
var group = new VirtualMultithreadIoEventLoopGroup(1, NioIoHandler.newFactory());
59+
// Transport enumeration to drive tests across available Netty transports.
60+
private enum Transport {
61+
NIO, EPOLL, LOCAL;
62+
63+
boolean isLocal() {
64+
return this == LOCAL;
65+
}
66+
67+
boolean isAvailable() {
68+
switch (this) {
69+
case NIO :
70+
return true;
71+
case EPOLL :
72+
return Epoll.isAvailable();
73+
case LOCAL :
74+
return true;
75+
default :
76+
return false;
77+
}
78+
}
79+
80+
IoHandlerFactory handlerFactory() {
81+
switch (this) {
82+
case NIO :
83+
return NioIoHandler.newFactory();
84+
case EPOLL :
85+
return EpollIoHandler.newFactory();
86+
case LOCAL :
87+
return LocalIoHandler.newFactory();
88+
default :
89+
throw new IllegalStateException();
90+
}
91+
}
92+
93+
Class<? extends io.netty.channel.ServerChannel> serverChannelClass() {
94+
switch (this) {
95+
case NIO :
96+
return NioServerSocketChannel.class;
97+
case EPOLL :
98+
return EpollServerSocketChannel.class;
99+
case LOCAL :
100+
throw new IllegalStateException(
101+
"LOCAL transport does not provide a ServerChannel class for real networking");
102+
default :
103+
throw new IllegalStateException();
104+
}
105+
}
106+
}
107+
108+
private static Stream<Transport> transportsForNetworking() {
109+
return Stream.of(Transport.values()).filter(t -> !t.isLocal() && t.isAvailable());
110+
}
111+
112+
private static Stream<Transport> transportsAllowLocal() {
113+
return Stream.of(Transport.values()).filter(Transport::isAvailable);
114+
}
115+
116+
@ParameterizedTest
117+
@MethodSource("transportsForNetworking")
118+
void processHttpRequestWithVirtualThreadOnManualNettyEventLoop(Transport transport) throws InterruptedException {
119+
assumeTrue(transport.isAvailable());
120+
// avoid LOCAL for real networking tests
121+
assumeTrue(!transport.isLocal());
122+
var group = new VirtualMultithreadIoEventLoopGroup(1, transport.handlerFactory());
56123
// create a simple http request server
57124
InetSocketAddress inetAddress = new InetSocketAddress(8080);
58125
CountDownLatch sendResponse = new CountDownLatch(1);
59-
var bootstrap = new ServerBootstrap().group(group).channel(NioServerSocketChannel.class)
126+
var bootstrap = new ServerBootstrap().group(group).channel(transport.serverChannelClass())
60127
.childHandler(new ChannelInitializer<SocketChannel>() {
61128

62129
@Override
@@ -114,16 +181,19 @@ void virtualEventExecutorGroupCorrectlySetEventExecutor() throws ExecutionExcept
114181
group.shutdownGracefully();
115182
}
116183

117-
@Test
118-
void busyYieldMakeEveryoneToProgress() throws InterruptedException {
119-
var group = new VirtualMultithreadIoEventLoopGroup(1, NioIoHandler.newFactory());
184+
@ParameterizedTest
185+
@MethodSource("transportsForNetworking")
186+
void busyYieldMakeEveryoneToProgress(Transport transport) throws InterruptedException {
187+
assumeTrue(transport.isAvailable());
188+
assumeTrue(!transport.isLocal());
189+
var group = new VirtualMultithreadIoEventLoopGroup(1, transport.handlerFactory());
120190
// create a simple http request server
121191
InetSocketAddress inetAddress = new InetSocketAddress(8080);
122192
CountDownLatch sendResponse = new CountDownLatch(1);
123193
AtomicBoolean secondVThreadHasDone = new AtomicBoolean(false);
124194
AtomicInteger yields = new AtomicInteger();
125195
CyclicBarrier bothDone = new CyclicBarrier(2);
126-
var bootstrap = new ServerBootstrap().group(group).channel(NioServerSocketChannel.class)
196+
var bootstrap = new ServerBootstrap().group(group).channel(transport.serverChannelClass())
127197
.childHandler(new ChannelInitializer<SocketChannel>() {
128198

129199
@Override

0 commit comments

Comments
 (0)