From b151957a5b03ea08a65bedd798f0dfd94761948a Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Wed, 24 Mar 2021 14:21:43 +0100 Subject: [PATCH] more end2end tests Signed-off-by: Ludovic Orban --- .../jetty/http3/client/End2EndClientTest.java | 87 +++++++++++++++++-- 1 file changed, 78 insertions(+), 9 deletions(-) diff --git a/jetty-http3/http3-client/src/test/java/org/eclipse/jetty/http3/client/End2EndClientTest.java b/jetty-http3/http3-client/src/test/java/org/eclipse/jetty/http3/client/End2EndClientTest.java index 2c3fdfbc848..79ce32bcd28 100644 --- a/jetty-http3/http3-client/src/test/java/org/eclipse/jetty/http3/client/End2EndClientTest.java +++ b/jetty-http3/http3-client/src/test/java/org/eclipse/jetty/http3/client/End2EndClientTest.java @@ -15,7 +15,11 @@ package org.eclipse.jetty.http3.client; import java.io.IOException; import java.io.PrintWriter; -import javax.servlet.ServletException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -38,6 +42,7 @@ import static org.hamcrest.core.Is.is; public class End2EndClientTest { private Server server; + private HttpClient client; @BeforeEach public void setUp() throws Exception @@ -55,7 +60,7 @@ public class End2EndClientTest server.setHandler(new AbstractHandler() { @Override - public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException + public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { baseRequest.setHandled(true); PrintWriter writer = response.getWriter(); @@ -68,21 +73,28 @@ public class End2EndClientTest }); server.start(); + + HttpClientTransportOverQuic transport = new HttpClientTransportOverQuic(); + client = new HttpClient(transport); + client.start(); } @AfterEach public void tearDown() throws Exception { - server.stop(); + try + { + server.stop(); + } + finally + { + client.stop(); + } } @Test public void simple() throws Exception { - HttpClientTransportOverQuic transport = new HttpClientTransportOverQuic(); - HttpClient client = new HttpClient(transport); - client.start(); - ContentResponse response = client.GET("https://localhost:8443/"); int status = response.getStatus(); String contentAsString = response.getContentAsString(); @@ -91,8 +103,6 @@ public class End2EndClientTest System.out.println(contentAsString); System.out.println("=========="); - client.stop(); - assertThat(status, is(200)); assertThat(contentAsString, is("\n" + "\t\n" + @@ -100,4 +110,63 @@ public class End2EndClientTest "\t\n" + "\n")); } + + @Test + public void multiple() throws Exception + { + for (int i = 0; i < 1000; i++) + { + ContentResponse response = client.GET("https://localhost:8443/"); + int status = response.getStatus(); + String contentAsString = response.getContentAsString(); + assertThat(status, is(200)); + assertThat(contentAsString, is("\n" + + "\t\n" + + "\t\tRequest served\n" + + "\t\n" + + "\n")); + } + } + + @Test + public void multiThreaded() throws Exception + { + ExecutorService executor = Executors.newFixedThreadPool(2); + try + { + List> futures = new ArrayList<>(); + + for (int i = 0; i < 1000; i++) + { + futures.add(executor.submit(() -> + { + try + { + ContentResponse response = client.GET("https://localhost:8443/"); + int status = response.getStatus(); + String contentAsString = response.getContentAsString(); + assertThat(status, is(200)); + assertThat(contentAsString, is("\n" + + "\t\n" + + "\t\tRequest served\n" + + "\t\n" + + "\n")); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + })); + } + + for (Future future : futures) + { + future.get(); + } + } + finally + { + executor.shutdownNow(); + } + } }