Skip to content

Commit 83ca1ec

Browse files
committed
Add a server sharing HTTP/3 test
1 parent a332339 commit 83ca1ec

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

vertx-core/src/test/java/io/vertx/tests/http/http3/Http3ServerTest.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,17 @@
1515
import io.netty.handler.codec.http3.Http3Settings;
1616
import io.netty.handler.codec.quic.QuicStreamResetException;
1717
import io.netty.util.NetUtil;
18+
import io.vertx.core.Context;
1819
import io.vertx.core.Future;
20+
import io.vertx.core.Vertx;
1921
import io.vertx.core.buffer.Buffer;
2022
import io.vertx.core.http.*;
23+
import io.vertx.core.internal.VertxInternal;
24+
import io.vertx.core.net.QuicConnection;
25+
import io.vertx.core.net.QuicServer;
26+
import io.vertx.core.net.QuicStream;
2127
import io.vertx.core.net.ServerSSLOptions;
28+
import io.vertx.core.net.SocketAddress;
2229
import io.vertx.test.core.VertxTestBase;
2330
import io.vertx.test.tls.Cert;
2431
import org.junit.Assert;
@@ -29,7 +36,11 @@
2936
import java.time.Duration;
3037
import java.util.ArrayList;
3138
import java.util.Collections;
39+
import java.util.HashMap;
40+
import java.util.HashSet;
3241
import java.util.List;
42+
import java.util.Map;
43+
import java.util.Set;
3344
import java.util.concurrent.CompletableFuture;
3445
import java.util.concurrent.CountDownLatch;
3546
import java.util.concurrent.TimeUnit;
@@ -454,7 +465,38 @@ public void testConnect() throws Exception {
454465
await();
455466
}
456467

457-
// @Test
468+
@Test
469+
public void testServerSharing() throws Exception {
470+
VertxInternal vxi = (VertxInternal) vertx;
471+
int num = 3;
472+
List<Http3TestClient.Client.Connection> connections = new ArrayList<>();
473+
Set<HttpConnection> serverConnections = Collections.synchronizedSet(new HashSet<>());
474+
for (int i = 0;i < num;i++) {
475+
HttpServerConfig config = serverConfig();
476+
config.getQuicConfig().setLoadBalanced(true);
477+
HttpServer server = vertx.createHttpServer(config, sslOptions());
478+
server.connectionHandler(serverConnections::add);
479+
server.requestHandler(request -> {
480+
request.response().end("Hello World " + request.connection().localAddress().port());
481+
});
482+
Context ctx = vxi.createEventLoopContext();
483+
Future.future(p -> ctx.runOnContext(v -> server
484+
.listen(SocketAddress.inetSocketAddress(8443, "localhost"))
485+
.onComplete(p)))
486+
.await();
487+
Http3TestClient.Client.Connection connection = client.connect(new InetSocketAddress("localhost", 8443));
488+
connections.add(connection);
489+
}
490+
assertEquals(num, serverConnections.size());
491+
for (Http3TestClient.Client.Connection connection : connections) {
492+
Http3TestClient.Client.Stream stream = connection.stream();
493+
stream.GET("/");
494+
byte[] body = stream.responseBody();
495+
assertEquals("Hello World 8443", new String(body));
496+
}
497+
}
498+
499+
// @Test
458500
// public void testNetworkLogging() {
459501
// TestLoggerFactory factory = TestUtils.testLogging(() -> {
460502
// server.close();

vertx-core/src/test/java/io/vertx/tests/net/quic/QuicServerLoadBalancingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void testMultiServer() {
109109
}
110110

111111
@Test
112-
public void testAddServers() throws Exception {
112+
public void testAddServer() throws Exception {
113113
client.bind(SocketAddress.inetSocketAddress(0, "localhost")).await();
114114
Map<QuicServer, Context> servers = new HashMap<>();
115115
VertxInternal vxi = (VertxInternal) vertx;

0 commit comments

Comments
 (0)