1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.testing.nio;
29
30 import java.io.IOException;
31
32 import org.apache.hc.core5.http.URIScheme;
33 import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncRequester;
34 import org.apache.hc.core5.http.impl.bootstrap.HttpAsyncServer;
35 import org.apache.hc.core5.http.protocol.UriPatternMatcher;
36 import org.apache.hc.core5.http2.HttpVersionPolicy;
37 import org.apache.hc.core5.reactor.IOReactorConfig;
38 import org.apache.hc.core5.testing.nio.extension.H2AsyncRequesterResource;
39 import org.apache.hc.core5.testing.nio.extension.H2AsyncServerResource;
40 import org.apache.hc.core5.util.Timeout;
41 import org.junit.jupiter.api.extension.RegisterExtension;
42
43 public abstract class H2CoreTransportTest extends HttpCoreTransportTest {
44
45 private static final Timeout TIMEOUT = Timeout.ofMinutes(1);
46
47 @RegisterExtension
48 private final H2AsyncServerResource serverResource;
49 @RegisterExtension
50 private final H2AsyncRequesterResource clientResource;
51
52 public H2CoreTransportTest(final URIScheme scheme) {
53 super(scheme);
54 this.serverResource = new H2AsyncServerResource(bootstrap -> bootstrap
55 .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
56 .setIOReactorConfig(
57 IOReactorConfig.custom()
58 .setSoTimeout(TIMEOUT)
59 .build())
60 .setLookupRegistry(new UriPatternMatcher<>())
61 .register("*", () -> new EchoHandler(2048))
62 );
63 this.clientResource = new H2AsyncRequesterResource(bootstrap -> bootstrap
64 .setVersionPolicy(HttpVersionPolicy.NEGOTIATE)
65 .setIOReactorConfig(IOReactorConfig.custom()
66 .setSoTimeout(TIMEOUT)
67 .build())
68 );
69 }
70
71 @Override
72 HttpAsyncServer serverStart() throws IOException {
73 return serverResource.start();
74 }
75
76 @Override
77 HttpAsyncRequester clientStart() {
78 return clientResource.start();
79 }
80
81 }