author | michaelm |
Wed, 23 May 2018 16:44:13 +0100 | |
branch | http-client-branch |
changeset 56598 | 4c502e3991bf |
child 56604 | 8a808d85fc1a |
permissions | -rw-r--r-- |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
1 |
/* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
4 |
* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
8 |
* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
14 |
* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
18 |
* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
21 |
* questions. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
22 |
*/ |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
23 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
24 |
/* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
25 |
* @test |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
26 |
* @bug 8196389 |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
27 |
* @summary Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
28 |
* |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
29 |
* @modules java.base/sun.net.www.http |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
30 |
* java.net.http/jdk.internal.net.http.common |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
31 |
* java.net.http/jdk.internal.net.http.frame |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
32 |
* java.net.http/jdk.internal.net.http.hpack |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
33 |
* java.logging |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
34 |
* jdk.httpserver |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
35 |
* @library /lib/testlibrary http2/server |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
36 |
* @build Http2TestServer |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
37 |
* @build jdk.testlibrary.SimpleSSLContext |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
38 |
* @run testng/othervm -ea -esa MaxStreams |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
39 |
*/ |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
40 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
41 |
import java.io.IOException; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
42 |
import java.io.InputStream; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
43 |
import java.io.OutputStream; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
44 |
import java.net.InetAddress; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
45 |
import java.net.InetSocketAddress; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
46 |
import java.net.URI; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
47 |
import java.util.List; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
48 |
import java.util.LinkedList; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
49 |
import java.util.Properties; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
50 |
import java.util.concurrent.atomic.AtomicInteger; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
51 |
import java.util.concurrent.CompletableFuture; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
52 |
import java.util.concurrent.CompletionException; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
53 |
import java.util.concurrent.CountDownLatch; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
54 |
import java.util.concurrent.Executors; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
55 |
import java.util.concurrent.ExecutorService; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
56 |
import javax.net.ssl.SSLContext; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
57 |
import java.net.http.HttpClient; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
58 |
import java.net.http.HttpRequest; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
59 |
import java.net.http.HttpResponse; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
60 |
import java.net.http.HttpResponse.BodyHandler; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
61 |
import java.net.http.HttpResponse.BodyHandlers; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
62 |
import jdk.testlibrary.SimpleSSLContext; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
63 |
import org.testng.annotations.AfterTest; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
64 |
import org.testng.annotations.BeforeTest; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
65 |
import org.testng.annotations.DataProvider; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
66 |
import org.testng.annotations.Test; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
67 |
import static java.nio.charset.StandardCharsets.UTF_8; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
68 |
import static java.net.http.HttpResponse.BodyHandlers.discarding; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
69 |
import static org.testng.Assert.assertEquals; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
70 |
import static org.testng.Assert.assertFalse; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
71 |
import static org.testng.Assert.fail; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
72 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
73 |
public class MaxStreams { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
74 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
75 |
Http2TestServer http2TestServer; // HTTP/2 ( h2c ) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
76 |
Http2TestServer https2TestServer; // HTTP/2 ( h2 ) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
77 |
String http2FixedURI; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
78 |
String https2FixedURI; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
79 |
volatile CountDownLatch latch; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
80 |
ExecutorService exec; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
81 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
82 |
// we send an initial warm up request, then MAX_STREAMS+1 requests |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
83 |
// in parallel. The last of them should hit the limit. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
84 |
// Then we wait for all the responses and send a further request |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
85 |
// which should succeed. The server should see (and respond to) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
86 |
// MAX_STREAMS+2 requests per test run. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
87 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
88 |
static final int MAX_STREAMS = 10; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
89 |
static final String RESPONSE = "Hello world"; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
90 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
91 |
@DataProvider(name = "uris") |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
92 |
public Object[][] variants() { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
93 |
return new Object[][]{ |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
94 |
{http2FixedURI}, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
95 |
{https2FixedURI}, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
96 |
{http2FixedURI}, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
97 |
{https2FixedURI} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
98 |
}; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
99 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
100 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
101 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
102 |
@Test(dataProvider = "uris", timeOut=20000) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
103 |
void testAsString(String uri) throws Exception { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
104 |
latch = new CountDownLatch(1); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
105 |
HttpClient client = HttpClient.newBuilder().build(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
106 |
List<CompletableFuture<HttpResponse<String>>> responses = new LinkedList<>(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
107 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
108 |
HttpRequest request = HttpRequest.newBuilder(URI.create(uri)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
109 |
.version(HttpClient.Version.HTTP_2) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
110 |
.GET() |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
111 |
.build(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
112 |
// send warmup to ensure we only have one Http2Connection |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
113 |
HttpResponse<String> warmup = client.send(request, BodyHandlers.ofString()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
114 |
if (warmup.statusCode() != 200 || !warmup.body().equals(RESPONSE)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
115 |
throw new RuntimeException(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
116 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
117 |
for (int i=0;i<MAX_STREAMS+1; i++) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
118 |
responses.add(client.sendAsync(request, BodyHandlers.ofString())); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
119 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
120 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
121 |
Thread.sleep(1000); // race possible even with latch |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
122 |
latch.countDown(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
123 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
124 |
// check the first MAX_STREAMS requests succeeded |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
125 |
try { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
126 |
CompletableFuture.allOf(responses.toArray(new CompletableFuture<?>[0])).join(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
127 |
} catch (Exception ee) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
128 |
System.err.println("Expected exception " + ee); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
129 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
130 |
int count = 0; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
131 |
for (CompletableFuture<HttpResponse<String>> cf : responses) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
132 |
HttpResponse<String> r = null; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
133 |
try { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
134 |
r = cf.join(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
135 |
if (r.statusCode() != 200 || !r.body().equals(RESPONSE)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
136 |
throw new RuntimeException(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
137 |
} catch (Throwable t) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
138 |
System.err.println("Exception at count = " + count); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
139 |
System.err.println(t); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
140 |
t.printStackTrace(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
141 |
count++; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
142 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
143 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
144 |
if (count != 1) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
145 |
String msg = "Expected 1 failure. Got " + count; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
146 |
throw new RuntimeException(msg); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
147 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
148 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
149 |
// make sure it succeeds now as number of streams == 0 now |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
150 |
HttpResponse<String> warmdown = client.send(request, BodyHandlers.ofString()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
151 |
if (warmdown.statusCode() != 200 || !warmdown.body().equals(RESPONSE)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
152 |
throw new RuntimeException(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
153 |
System.err.println("Test OK"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
154 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
155 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
156 |
@BeforeTest |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
157 |
public void setup() throws Exception { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
158 |
SSLContext ctx = (new SimpleSSLContext()).get(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
159 |
exec = Executors.newCachedThreadPool(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
160 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
161 |
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
162 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
163 |
Properties props = new Properties(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
164 |
props.setProperty("http2server.settings.max_concurrent_streams", Integer.toString(MAX_STREAMS)); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
165 |
http2TestServer = new Http2TestServer("localhost", false, 0, exec, 10, props, null); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
166 |
http2TestServer.addHandler(new Http2FixedHandler(), "/http2/fixed"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
167 |
http2FixedURI = "http://" + http2TestServer.serverAuthority()+ "/http2/fixed"; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
168 |
http2TestServer.start(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
169 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
170 |
https2TestServer = new Http2TestServer("localhost", true, 0, exec, 10, props, ctx); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
171 |
https2TestServer.addHandler(new Http2FixedHandler(), "/http2/fixed"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
172 |
https2FixedURI = "https://" + https2TestServer.serverAuthority()+ "/http2/fixed"; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
173 |
https2TestServer.start(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
174 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
175 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
176 |
@AfterTest |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
177 |
public void teardown() throws Exception { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
178 |
http2TestServer.stop(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
179 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
180 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
181 |
class Http2FixedHandler implements Http2Handler { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
182 |
volatile AtomicInteger counter = new AtomicInteger(0); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
183 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
184 |
@Override |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
185 |
public void handle(Http2TestExchange t) throws IOException { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
186 |
try (InputStream is = t.getRequestBody(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
187 |
OutputStream os = t.getResponseBody()) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
188 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
189 |
is.readAllBytes(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
190 |
int c = counter.getAndIncrement(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
191 |
if (c > 0 && c <= MAX_STREAMS) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
192 |
// Wait for latch. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
193 |
try { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
194 |
// don't send any replies until all requests are sent |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
195 |
System.err.println("latch await"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
196 |
latch.await(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
197 |
System.err.println("latch resume"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
198 |
} catch (InterruptedException ee) {} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
199 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
200 |
if (c == MAX_STREAMS + 1) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
201 |
counter = new AtomicInteger(0); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
202 |
t.sendResponseHeaders(200, RESPONSE.length()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
203 |
os.write(RESPONSE.getBytes()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
204 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
205 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
206 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
207 |
} |