|
15 | 15 | import io.netty.handler.codec.http3.Http3Settings; |
16 | 16 | import io.netty.handler.codec.quic.QuicStreamResetException; |
17 | 17 | import io.netty.util.NetUtil; |
| 18 | +import io.vertx.core.Context; |
18 | 19 | import io.vertx.core.Future; |
| 20 | +import io.vertx.core.Vertx; |
19 | 21 | import io.vertx.core.buffer.Buffer; |
20 | 22 | 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; |
21 | 27 | import io.vertx.core.net.ServerSSLOptions; |
| 28 | +import io.vertx.core.net.SocketAddress; |
22 | 29 | import io.vertx.test.core.VertxTestBase; |
23 | 30 | import io.vertx.test.tls.Cert; |
24 | 31 | import org.junit.Assert; |
|
29 | 36 | import java.time.Duration; |
30 | 37 | import java.util.ArrayList; |
31 | 38 | import java.util.Collections; |
| 39 | +import java.util.HashMap; |
| 40 | +import java.util.HashSet; |
32 | 41 | import java.util.List; |
| 42 | +import java.util.Map; |
| 43 | +import java.util.Set; |
33 | 44 | import java.util.concurrent.CompletableFuture; |
34 | 45 | import java.util.concurrent.CountDownLatch; |
35 | 46 | import java.util.concurrent.TimeUnit; |
@@ -454,7 +465,38 @@ public void testConnect() throws Exception { |
454 | 465 | await(); |
455 | 466 | } |
456 | 467 |
|
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 |
458 | 500 | // public void testNetworkLogging() { |
459 | 501 | // TestLoggerFactory factory = TestUtils.testLogging(() -> { |
460 | 502 | // server.close(); |
|
0 commit comments