|
18 | 18 | import java.lang.reflect.Method;
|
19 | 19 |
|
20 | 20 | import org.eclipse.jetty.client.HttpClient;
|
| 21 | +import org.eclipse.jetty.client.HttpClientTransport; |
| 22 | +import org.eclipse.jetty.client.http.HttpClientTransportOverHTTP; |
| 23 | +import org.eclipse.jetty.http2.client.HTTP2Client; |
| 24 | +import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2; |
| 25 | +import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; |
| 26 | +import org.eclipse.jetty.server.ConnectionFactory; |
21 | 27 | import org.eclipse.jetty.server.Handler;
|
| 28 | +import org.eclipse.jetty.server.HttpConfiguration; |
| 29 | +import org.eclipse.jetty.server.HttpConnectionFactory; |
22 | 30 | import org.eclipse.jetty.server.Server;
|
23 | 31 | import org.eclipse.jetty.server.ServerConnector;
|
24 | 32 | import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
25 | 33 | import org.testng.annotations.AfterMethod;
|
26 | 34 | import org.testng.annotations.BeforeMethod;
|
| 35 | +import org.testng.annotations.DataProvider; |
27 | 36 |
|
28 | 37 | public class AbstractTest {
|
| 38 | + @DataProvider(name = "protocols") |
| 39 | + public static Object[][] protocols() { |
| 40 | + return new Object[][]{ |
| 41 | + new Object[]{"http"}, |
| 42 | + new Object[]{"h2c"} |
| 43 | + }; |
| 44 | + } |
| 45 | + |
| 46 | + private final HttpConfiguration httpConfiguration = new HttpConfiguration(); |
| 47 | + private final String protocol; |
29 | 48 | private HttpClient httpClient;
|
30 | 49 | private Server server;
|
31 | 50 | private ServerConnector connector;
|
32 | 51 |
|
| 52 | + public AbstractTest(String protocol) { |
| 53 | + this.protocol = protocol; |
| 54 | + } |
| 55 | + |
| 56 | + @BeforeMethod |
| 57 | + public void printTestName(Method method) { |
| 58 | + System.err.printf("Running %s.%s() [%s]%n", getClass().getName(), method.getName(), protocol); |
| 59 | + } |
| 60 | + |
33 | 61 | public void prepare(Handler handler) throws Exception {
|
34 | 62 | QueuedThreadPool serverThreads = new QueuedThreadPool();
|
35 | 63 | serverThreads.setName("server");
|
36 | 64 | server = new Server(serverThreads);
|
37 |
| - connector = new ServerConnector(server); |
| 65 | + connector = new ServerConnector(server, createServerConnectionFactory(protocol)); |
38 | 66 | server.addConnector(connector);
|
39 | 67 | server.setHandler(handler);
|
40 | 68 | server.start();
|
41 | 69 |
|
42 | 70 | QueuedThreadPool clientThreads = new QueuedThreadPool();
|
43 | 71 | clientThreads.setName("client");
|
44 |
| - httpClient = new HttpClient(); |
| 72 | + httpClient = new HttpClient(createClientTransport(protocol), null); |
45 | 73 | httpClient.setExecutor(clientThreads);
|
46 | 74 | httpClient.start();
|
47 | 75 | }
|
48 | 76 |
|
49 |
| - @BeforeMethod |
50 |
| - public void printTestName(Method method) { |
51 |
| - System.err.printf("Running %s.%s()%n", getClass().getName(), method.getName()); |
| 77 | + private ConnectionFactory createServerConnectionFactory(String protocol) { |
| 78 | + switch (protocol) { |
| 79 | + case "h2c": |
| 80 | + return new HTTP2CServerConnectionFactory(httpConfiguration); |
| 81 | + default: |
| 82 | + return new HttpConnectionFactory(httpConfiguration); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + private HttpClientTransport createClientTransport(String protocol) { |
| 87 | + switch (protocol) { |
| 88 | + case "h2c": |
| 89 | + HTTP2Client http2Client = new HTTP2Client(); |
| 90 | + http2Client.setSelectors(1); |
| 91 | + return new HttpClientTransportOverHTTP2(http2Client); |
| 92 | + default: |
| 93 | + return new HttpClientTransportOverHTTP(1); |
| 94 | + } |
52 | 95 | }
|
53 | 96 |
|
54 | 97 | @AfterMethod
|
|
0 commit comments