author | michaelm |
Thu, 24 May 2018 18:41:30 +0100 | |
branch | http-client-branch |
changeset 56604 | 8a808d85fc1a |
parent 56598 | 4c502e3991bf |
child 56771 | 73a6534bce94 |
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; |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
56 |
import java.util.concurrent.Semaphore; |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
57 |
import javax.net.ssl.SSLContext; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
58 |
import java.net.http.HttpClient; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
59 |
import java.net.http.HttpRequest; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
60 |
import java.net.http.HttpResponse; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
61 |
import java.net.http.HttpResponse.BodyHandler; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
62 |
import java.net.http.HttpResponse.BodyHandlers; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
63 |
import jdk.testlibrary.SimpleSSLContext; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
64 |
import org.testng.annotations.AfterTest; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
65 |
import org.testng.annotations.BeforeTest; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
66 |
import org.testng.annotations.DataProvider; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
67 |
import org.testng.annotations.Test; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
68 |
import static java.nio.charset.StandardCharsets.UTF_8; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
69 |
import static java.net.http.HttpResponse.BodyHandlers.discarding; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
70 |
import static org.testng.Assert.assertEquals; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
71 |
import static org.testng.Assert.assertFalse; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
72 |
import static org.testng.Assert.fail; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
73 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
74 |
public class MaxStreams { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
75 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
76 |
Http2TestServer http2TestServer; // HTTP/2 ( h2c ) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
77 |
Http2TestServer https2TestServer; // HTTP/2 ( h2 ) |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
78 |
final Http2FixedHandler handler = new Http2FixedHandler(); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
79 |
String http2FixedURI; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
80 |
String https2FixedURI; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
81 |
volatile CountDownLatch latch; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
82 |
ExecutorService exec; |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
83 |
final Semaphore canStartTestRun = new Semaphore(1); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
84 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
85 |
// 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
|
86 |
// 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
|
87 |
// 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
|
88 |
// 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
|
89 |
// MAX_STREAMS+2 requests per test run. |
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 |
static final int MAX_STREAMS = 10; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
92 |
static final String RESPONSE = "Hello world"; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
93 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
94 |
@DataProvider(name = "uris") |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
95 |
public Object[][] variants() { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
96 |
return new Object[][]{ |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
97 |
{http2FixedURI}, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
98 |
{https2FixedURI}, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
99 |
{http2FixedURI}, |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
100 |
{https2FixedURI} |
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 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
103 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
104 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
105 |
@Test(dataProvider = "uris", timeOut=20000) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
106 |
void testAsString(String uri) throws Exception { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
107 |
canStartTestRun.acquire(); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
108 |
latch = new CountDownLatch(1); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
109 |
handler.setLatch(latch); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
110 |
HttpClient client = HttpClient.newBuilder().build(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
111 |
List<CompletableFuture<HttpResponse<String>>> responses = new LinkedList<>(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
112 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
113 |
HttpRequest request = HttpRequest.newBuilder(URI.create(uri)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
114 |
.version(HttpClient.Version.HTTP_2) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
115 |
.GET() |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
116 |
.build(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
117 |
// 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
|
118 |
HttpResponse<String> warmup = client.send(request, BodyHandlers.ofString()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
119 |
if (warmup.statusCode() != 200 || !warmup.body().equals(RESPONSE)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
120 |
throw new RuntimeException(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
121 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
122 |
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
|
123 |
responses.add(client.sendAsync(request, BodyHandlers.ofString())); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
124 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
125 |
|
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
126 |
// wait until we get local exception before allow server to proceed |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
127 |
try { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
128 |
CompletableFuture.anyOf(responses.toArray(new CompletableFuture<?>[0])).join(); |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
129 |
} catch (Exception ee) { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
130 |
System.err.println("Expected exception 1 " + ee); |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
131 |
} |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
132 |
|
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
133 |
latch.countDown(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
134 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
135 |
// check the first MAX_STREAMS requests succeeded |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
136 |
try { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
137 |
CompletableFuture.allOf(responses.toArray(new CompletableFuture<?>[0])).join(); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
138 |
System.err.println("Did not get Expected exception 2 "); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
139 |
} catch (Exception ee) { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
140 |
System.err.println("Expected exception 2 " + ee); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
141 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
142 |
int count = 0; |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
143 |
int failures = 0; |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
144 |
for (CompletableFuture<HttpResponse<String>> cf : responses) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
145 |
HttpResponse<String> r = null; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
146 |
try { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
147 |
count++; |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
148 |
r = cf.join(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
149 |
if (r.statusCode() != 200 || !r.body().equals(RESPONSE)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
150 |
throw new RuntimeException(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
151 |
} catch (Throwable t) { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
152 |
failures++; |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
153 |
System.err.printf("Failure %d at count %d\n", failures, count); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
154 |
System.err.println(t); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
155 |
t.printStackTrace(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
156 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
157 |
} |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
158 |
if (failures != 1) { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
159 |
String msg = "Expected 1 failure. Got " + failures; |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
160 |
throw new RuntimeException(msg); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
161 |
} |
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 |
// 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
|
164 |
HttpResponse<String> warmdown = client.send(request, BodyHandlers.ofString()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
165 |
if (warmdown.statusCode() != 200 || !warmdown.body().equals(RESPONSE)) |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
166 |
throw new RuntimeException(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
167 |
System.err.println("Test OK"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
168 |
} |
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 |
@BeforeTest |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
171 |
public void setup() throws Exception { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
172 |
SSLContext ctx = (new SimpleSSLContext()).get(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
173 |
exec = Executors.newCachedThreadPool(); |
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 |
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
176 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
177 |
Properties props = new Properties(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
178 |
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
|
179 |
http2TestServer = new Http2TestServer("localhost", false, 0, exec, 10, props, null); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
180 |
http2TestServer.addHandler(handler, "/http2/fixed"); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
181 |
http2FixedURI = "http://" + http2TestServer.serverAuthority()+ "/http2/fixed"; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
182 |
http2TestServer.start(); |
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 |
https2TestServer = new Http2TestServer("localhost", true, 0, exec, 10, props, ctx); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
185 |
https2TestServer.addHandler(handler, "/http2/fixed"); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
186 |
https2FixedURI = "https://" + https2TestServer.serverAuthority()+ "/http2/fixed"; |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
187 |
https2TestServer.start(); |
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 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
190 |
@AfterTest |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
191 |
public void teardown() throws Exception { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
192 |
System.err.println("Stopping test server now"); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
193 |
http2TestServer.stop(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
194 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
195 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
196 |
class Http2FixedHandler implements Http2Handler { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
197 |
final AtomicInteger counter = new AtomicInteger(0); |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
198 |
CountDownLatch latch; |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
199 |
|
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
200 |
synchronized void setLatch(CountDownLatch latch) { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
201 |
this.latch = latch; |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
202 |
} |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
203 |
|
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
204 |
synchronized CountDownLatch getLatch() { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
205 |
return latch; |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
206 |
} |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
207 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
208 |
@Override |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
209 |
public void handle(Http2TestExchange t) throws IOException { |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
210 |
int c = -1; |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
211 |
try (InputStream is = t.getRequestBody(); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
212 |
OutputStream os = t.getResponseBody()) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
213 |
|
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
214 |
is.readAllBytes(); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
215 |
c = counter.getAndIncrement(); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
216 |
if (c > 0 && c <= MAX_STREAMS) { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
217 |
// Wait for latch. |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
218 |
try { |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
219 |
// 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
|
220 |
System.err.println("latch await"); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
221 |
getLatch().await(); |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
222 |
System.err.println("latch resume"); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
223 |
} catch (InterruptedException ee) {} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
224 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
225 |
t.sendResponseHeaders(200, RESPONSE.length()); |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
226 |
os.write(RESPONSE.getBytes()); |
56604
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
227 |
} finally { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
228 |
// client issues MAX_STREAMS + 3 requests in total |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
229 |
// but server should only see MAX_STREAMS + 2 in total. One is rejected by client |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
230 |
// counter c captured before increment so final value is MAX_STREAMS + 1 |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
231 |
if (c == MAX_STREAMS + 1) { |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
232 |
counter.set(0); |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
233 |
canStartTestRun.release(); |
8a808d85fc1a
http-client-branch: Fix for new MaxStreams.java test
michaelm
parents:
56598
diff
changeset
|
234 |
} |
56598
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
235 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
236 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
237 |
} |
4c502e3991bf
8196389: Should HttpClient support SETTINGS_MAX_CONCURRENT_STREAMS from the server
michaelm
parents:
diff
changeset
|
238 |
} |