author | chegar |
Tue, 18 Jun 2019 18:38:53 +0100 | |
changeset 55405 | 17f24c0e2f01 |
parent 53467 | 97cf88608d76 |
permissions | -rw-r--r-- |
53467
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
1 |
/* |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
4 |
* |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
8 |
* |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
14 |
* |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
18 |
* |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
22 |
*/ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
23 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
24 |
/* |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
25 |
* @test |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
26 |
* @bug 8217264 |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
27 |
* @summary Tests that you can map an InputStream to a GZIPInputStream |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
28 |
* @library /test/lib http2/server |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
29 |
* @build jdk.test.lib.net.SimpleSSLContext |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
30 |
* @modules java.base/sun.net.www.http |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
31 |
* java.net.http/jdk.internal.net.http.common |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
32 |
* java.net.http/jdk.internal.net.http.frame |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
33 |
* java.net.http/jdk.internal.net.http.hpack |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
34 |
* @run testng/othervm GZIPInputStreamTest |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
35 |
*/ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
36 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
37 |
import com.sun.net.httpserver.HttpServer; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
38 |
import com.sun.net.httpserver.HttpsConfigurator; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
39 |
import com.sun.net.httpserver.HttpsServer; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
40 |
import jdk.test.lib.net.SimpleSSLContext; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
41 |
import org.testng.annotations.AfterTest; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
42 |
import org.testng.annotations.BeforeTest; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
43 |
import org.testng.annotations.DataProvider; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
44 |
import org.testng.annotations.Test; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
45 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
46 |
import javax.net.ssl.SSLContext; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
47 |
import java.io.IOException; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
48 |
import java.io.InputStream; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
49 |
import java.io.OutputStream; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
50 |
import java.io.UncheckedIOException; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
51 |
import java.net.InetAddress; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
52 |
import java.net.InetSocketAddress; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
53 |
import java.net.URI; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
54 |
import java.net.http.HttpClient; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
55 |
import java.net.http.HttpRequest; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
56 |
import java.net.http.HttpResponse; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
57 |
import java.net.http.HttpResponse.BodyHandler; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
58 |
import java.net.http.HttpResponse.BodyHandlers; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
59 |
import java.net.http.HttpResponse.BodySubscribers; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
60 |
import java.nio.charset.StandardCharsets; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
61 |
import java.util.concurrent.CompletableFuture; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
62 |
import java.util.concurrent.Executor; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
63 |
import java.util.concurrent.Executors; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
64 |
import java.util.function.Function; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
65 |
import java.util.function.Supplier; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
66 |
import java.util.zip.GZIPInputStream; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
67 |
import java.util.zip.GZIPOutputStream; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
68 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
69 |
import static java.lang.System.out; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
70 |
import static java.nio.charset.StandardCharsets.UTF_8; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
71 |
import static org.testng.Assert.assertEquals; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
72 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
73 |
public class GZIPInputStreamTest implements HttpServerAdapters { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
74 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
75 |
SSLContext sslContext; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
76 |
HttpTestServer httpTestServer; // HTTP/1.1 [ 4 servers ] |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
77 |
HttpTestServer httpsTestServer; // HTTPS/1.1 |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
78 |
HttpTestServer http2TestServer; // HTTP/2 ( h2c ) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
79 |
HttpTestServer https2TestServer; // HTTP/2 ( h2 ) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
80 |
String httpURI; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
81 |
String httpsURI; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
82 |
String http2URI; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
83 |
String https2URI; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
84 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
85 |
static final int ITERATION_COUNT = 3; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
86 |
// a shared executor helps reduce the amount of threads created by the test |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
87 |
// this test will block if the executor doesn't have at least two threads. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
88 |
static final Executor executor = Executors.newFixedThreadPool(2); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
89 |
static final Executor singleThreadExecutor = Executors.newSingleThreadExecutor(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
90 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
91 |
public static final String LOREM_IPSUM = |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
92 |
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
93 |
+ "Proin et lorem a sem faucibus finibus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
94 |
+ "Nam nisl nibh, elementum laoreet rutrum quis, lobortis at sem. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
95 |
+ "Aenean purus libero, vehicula sed auctor ac, finibus commodo massa. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
96 |
+ "Etiam dapibus nisl ex, viverra iaculis sapien suscipit sit amet. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
97 |
+ "Phasellus fringilla id orci sit amet convallis. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
98 |
+ "Nam suscipit tempor felis sed feugiat. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
99 |
+ "Mauris quis viverra justo, vitae vulputate turpis. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
100 |
+ "Ut eu orci eget ante faucibus volutpat quis quis urna. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
101 |
+ "Ut porttitor mattis diam, ac sollicitudin ligula volutpat vel. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
102 |
+ "Quisque pretium leo sed augue lacinia, eu mollis dui tempor.\n\n" |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
103 |
+ "Nullam at mi porttitor, condimentum enim et, tristique felis. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
104 |
+ "Nulla ante elit, interdum id ante ac, dignissim suscipit urna. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
105 |
+ "Sed rhoncus felis eget placerat tincidunt. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
106 |
+ "Duis pellentesque, eros et laoreet lacinia, urna arcu elementum metus, " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
107 |
+ "et tempor nibh ante vel odio. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
108 |
+ "Donec et dolor posuere, sagittis libero sit amet, imperdiet ligula. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
109 |
+ "Sed aliquam nulla congue bibendum hendrerit. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
110 |
+ "Morbi ut tincidunt turpis. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
111 |
+ "Nullam semper ipsum et sem imperdiet, sit amet commodo turpis euismod. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
112 |
+ "Nullam aliquet metus id libero elementum, ut pulvinar urna gravida. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
113 |
+ "Nullam non rhoncus diam. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
114 |
+ "Mauris sagittis bibendum odio, sed accumsan sem ullamcorper ut.\n\n" |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
115 |
+ "Proin malesuada nisl a quam dignissim rhoncus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
116 |
+ "Pellentesque vitae dui velit. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
117 |
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
118 |
+ "Vivamus sagittis magna id magna vestibulum, nec lacinia odio maximus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
119 |
+ "Nunc commodo, nisl non sagittis posuere, tortor ligula accumsan diam, " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
120 |
+ "a rhoncus augue velit quis enim. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
121 |
+ "Nulla et dictum mauris. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
122 |
+ "Vivamus et accumsan mauris, et tincidunt nunc.\n\n" |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
123 |
+ "Nullam non pharetra lectus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
124 |
+ "Fusce lobortis sapien ante, quis egestas tellus tincidunt efficitur. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
125 |
+ "Proin tempus mollis urna, sit amet congue diam eleifend in. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
126 |
+ "Ut auctor metus ipsum, at porta turpis consectetur sed. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
127 |
+ "Ut malesuada euismod massa, ut elementum nisi mattis eget. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
128 |
+ "Donec ultrices vel dolor at convallis. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
129 |
+ "Nunc eget felis nec nunc faucibus finibus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
130 |
+ "Curabitur nec auctor metus, sit amet tristique lorem. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
131 |
+ "Donec tempus fringilla suscipit. Cras sit amet ante elit. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
132 |
+ "Ut sodales sagittis eros quis cursus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
133 |
+ "Maecenas finibus ante quis euismod rutrum. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
134 |
+ "Aenean scelerisque placerat nisi. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
135 |
+ "Fusce porta, nibh vel efficitur sodales, urna eros consequat tellus, " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
136 |
+ "at fringilla ex justo in mi. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
137 |
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
138 |
+ "Morbi accumsan, justo nec tincidunt pretium, justo ex consectetur ante, " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
139 |
+ "nec euismod diam velit vitae quam.\n\n" |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
140 |
+ "Vestibulum ante ipsum primis in faucibus orci luctus et " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
141 |
+ "ultrices posuere cubilia Curae; " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
142 |
+ "Praesent eget consequat nunc, vel dapibus nulla. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
143 |
+ "Maecenas egestas luctus consectetur. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
144 |
+ "Duis lacus risus, sollicitudin sit amet justo sed, " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
145 |
+ "ultrices facilisis sapien. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
146 |
+ "Mauris eget fermentum risus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
147 |
+ "Suspendisse potenti. Nam at tempor risus. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
148 |
+ "Quisque lacus augue, dictum vel interdum quis, interdum et mi. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
149 |
+ "In purus mauris, pellentesque et lectus eget, condimentum pretium odio." |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
150 |
+ " Donec imperdiet congue laoreet. " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
151 |
+ "Cras pharetra hendrerit purus ac efficitur. \n"; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
152 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
153 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
154 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
155 |
@DataProvider(name = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
156 |
public Object[][] variants() { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
157 |
return new Object[][]{ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
158 |
{ httpURI, false }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
159 |
{ httpURI, true }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
160 |
{ httpsURI, false }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
161 |
{ httpsURI, true }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
162 |
{ http2URI, false }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
163 |
{ http2URI, true }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
164 |
{ https2URI, false }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
165 |
{ https2URI, true }, |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
166 |
}; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
167 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
168 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
169 |
final ReferenceTracker TRACKER = ReferenceTracker.INSTANCE; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
170 |
HttpClient newHttpClient() { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
171 |
return TRACKER.track(HttpClient.newBuilder() |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
172 |
.executor(executor) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
173 |
.sslContext(sslContext) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
174 |
.build()); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
175 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
176 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
177 |
HttpClient newSingleThreadClient() { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
178 |
return TRACKER.track(HttpClient.newBuilder() |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
179 |
.executor(singleThreadExecutor) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
180 |
.sslContext(sslContext) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
181 |
.build()); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
182 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
183 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
184 |
HttpClient newInLineClient() { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
185 |
return TRACKER.track(HttpClient.newBuilder() |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
186 |
.executor((r) -> r.run() ) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
187 |
.sslContext(sslContext) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
188 |
.build()); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
189 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
190 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
191 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
192 |
public void testPlainSyncAsString(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
193 |
out.println("\nSmoke test: verify that the result we get from the server is correct."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
194 |
out.println("Uses plain send() and `asString` to get the plain string."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
195 |
out.println("Uses single threaded executor"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
196 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
197 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
198 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
199 |
client = newSingleThreadClient(); // should work with 1 single thread |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
200 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
201 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri +"/txt/LoremIpsum.txt")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
202 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
203 |
BodyHandler<String> handler = BodyHandlers.ofString(UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
204 |
HttpResponse<String> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
205 |
String lorem = response.body(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
206 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
207 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
208 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
209 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
210 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
211 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
212 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
213 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
214 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
215 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
216 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
217 |
public void testPlainSyncAsInputStream(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
218 |
out.println("Uses plain send() and `asInputStream` - calls readAllBytes() from main thread"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
219 |
out.println("Uses single threaded executor"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
220 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
221 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
222 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
223 |
client = newSingleThreadClient(); // should work with 1 single thread |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
224 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
225 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/txt/LoremIpsum.txt")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
226 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
227 |
BodyHandler<InputStream> handler = BodyHandlers.ofInputStream(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
228 |
HttpResponse<InputStream> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
229 |
String lorem = new String(response.body().readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
230 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
231 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
232 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
233 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
234 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
235 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
236 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
237 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
238 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
239 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
240 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
241 |
public void testGZIPSyncAsInputStream(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
242 |
out.println("Uses plain send() and `asInputStream` - " + |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
243 |
"creates GZIPInputStream and calls readAllBytes() from main thread"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
244 |
out.println("Uses single threaded executor"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
245 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
246 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
247 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
248 |
client = newSingleThreadClient(); // should work with 1 single thread |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
249 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
250 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/gz/LoremIpsum.txt.gz")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
251 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
252 |
BodyHandler<InputStream> handler = BodyHandlers.ofInputStream(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
253 |
HttpResponse<InputStream> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
254 |
GZIPInputStream gz = new GZIPInputStream(response.body()); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
255 |
String lorem = new String(gz.readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
256 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
257 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
258 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
259 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
260 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
261 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
262 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
263 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
264 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
265 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
266 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
267 |
public void testGZIPSyncAsGZIPInputStream(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
268 |
out.println("Uses plain send() and a mapping subscriber to "+ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
269 |
"create the GZIPInputStream. Calls readAllBytes() from main thread"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
270 |
out.println("Uses a fixed thread pool executor with 2 thread"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
271 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
272 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
273 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
274 |
client = newHttpClient(); // needs at least 2 threads |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
275 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
276 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/gz/LoremIpsum.txt.gz")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
277 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
278 |
// This is dangerous, because the finisher will block. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
279 |
// We support this, but the executor must have enough threads. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
280 |
BodyHandler<InputStream> handler = new GZIPBodyHandler(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
281 |
HttpResponse<InputStream> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
282 |
String lorem = new String(response.body().readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
283 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
284 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
285 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
286 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
287 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
288 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
289 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
290 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
291 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
292 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
293 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
294 |
public void testGZIPSyncAsGZIPInputStreamSupplier(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
295 |
out.println("Uses plain send() and a mapping subscriber to "+ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
296 |
"create a Supplier<GZIPInputStream>. Calls Supplier.get() " + |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
297 |
"and readAllBytes() from main thread"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
298 |
out.println("Uses a single threaded executor"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
299 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
300 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
301 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
302 |
client = newSingleThreadClient(); // should work with 1 single thread |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
303 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
304 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/gz/LoremIpsum.txt.gz")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
305 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
306 |
// This is dangerous, because the finisher will block. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
307 |
// We support this, but the executor must have enough threads. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
308 |
BodyHandler<Supplier<InputStream>> handler = new BodyHandler<Supplier<InputStream>>() { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
309 |
public HttpResponse.BodySubscriber<Supplier<InputStream>> apply( |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
310 |
HttpResponse.ResponseInfo responseInfo) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
311 |
{ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
312 |
String contentType = responseInfo.headers().firstValue("Content-Encoding") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
313 |
.orElse("identity"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
314 |
out.println("Content-Encoding: " + contentType); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
315 |
if (contentType.equalsIgnoreCase("gzip")) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
316 |
// This is dangerous. Blocking in the mapping function can wedge the |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
317 |
// response. We do support it provided that there enough thread in |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
318 |
// the executor. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
319 |
return BodySubscribers.mapping(BodySubscribers.ofInputStream(), |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
320 |
(is) -> (() -> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
321 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
322 |
return new GZIPInputStream(is); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
323 |
} catch (IOException io) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
324 |
throw new UncheckedIOException(io); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
325 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
326 |
})); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
327 |
} else return BodySubscribers.mapping(BodySubscribers.ofInputStream(), |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
328 |
(is) -> (() -> is)); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
329 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
330 |
}; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
331 |
HttpResponse<Supplier<InputStream>> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
332 |
String lorem = new String(response.body().get().readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
333 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
334 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
335 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
336 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
337 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
338 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
339 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
340 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
341 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
342 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
343 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
344 |
public void testPlainAsyncAsInputStreamBlocks(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
345 |
out.println("Uses sendAsync() and `asInputStream`. Registers a dependent action "+ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
346 |
"that calls readAllBytes()"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
347 |
out.println("Uses a fixed thread pool executor with two threads"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
348 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
349 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
350 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
351 |
client = newHttpClient(); // needs at least 2 threads |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
352 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
353 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/txt/LoremIpsum.txt")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
354 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
355 |
BodyHandler<InputStream> handler = BodyHandlers.ofInputStream(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
356 |
CompletableFuture<HttpResponse<InputStream>> responseCF = client.sendAsync(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
357 |
// This is dangerous. Blocking in the mapping function can wedge the |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
358 |
// response. We do support it provided that there enough threads in |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
359 |
// the executor. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
360 |
String lorem = responseCF.thenApply((r) -> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
361 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
362 |
return new String(r.body().readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
363 |
} catch (IOException io) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
364 |
throw new UncheckedIOException(io); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
365 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
366 |
}).join(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
367 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
368 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
369 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
370 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
371 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
372 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
373 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
374 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
375 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
376 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
377 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
378 |
public void testGZIPAsyncAsGZIPInputStreamBlocks(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
379 |
out.println("Uses sendAsync() and a mapping subscriber to create a GZIPInputStream. " + |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
380 |
"Registers a dependent action that calls readAllBytes()"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
381 |
out.println("Uses a fixed thread pool executor with two threads"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
382 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
383 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
384 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
385 |
client = newHttpClient(); // needs at least 2 threads |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
386 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
387 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/gz/LoremIpsum.txt.gz")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
388 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
389 |
BodyHandler<InputStream> handler = new GZIPBodyHandler(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
390 |
CompletableFuture<HttpResponse<InputStream>> responseCF = client.sendAsync(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
391 |
// This is dangerous - we support this, but it can block |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
392 |
// if there are not enough threads available. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
393 |
// Correct custom code should use thenApplyAsync instead. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
394 |
String lorem = responseCF.thenApply((r) -> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
395 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
396 |
return new String(r.body().readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
397 |
} catch (IOException io) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
398 |
throw new UncheckedIOException(io); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
399 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
400 |
}).join(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
401 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
402 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
403 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
404 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
405 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
406 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
407 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
408 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
409 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
410 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
411 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
412 |
public void testGZIPSyncAsGZIPInputStreamBlocks(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
413 |
out.println("Uses sendAsync() and a mapping subscriber to create a GZIPInputStream," + |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
414 |
"which is mapped again using a mapping subscriber " + |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
415 |
"to call readAllBytes() and map to String"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
416 |
out.println("Uses a fixed thread pool executor with two threads"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
417 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
418 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
419 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
420 |
client = newHttpClient(); // needs at least 2 threads |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
421 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
422 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/gz/LoremIpsum.txt.gz")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
423 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
424 |
// This is dangerous. Blocking in the mapping function can wedge the |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
425 |
// response. We do support it provided that there enough thread in |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
426 |
// the executor. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
427 |
BodyHandler<String> handler = new MappingBodyHandler<>(new GZIPBodyHandler(), |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
428 |
(InputStream is) -> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
429 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
430 |
return new String(is.readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
431 |
} catch(IOException io) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
432 |
throw new UncheckedIOException(io); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
433 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
434 |
}); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
435 |
HttpResponse<String> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
436 |
String lorem = response.body(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
437 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
438 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
439 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
440 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
441 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
442 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
443 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
444 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
445 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
446 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
447 |
@Test(dataProvider = "variants") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
448 |
public void testGZIPSyncAsGZIPInputStreamSupplierInline(String uri, boolean sameClient) throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
449 |
out.println("Uses plain send() and a mapping subscriber to "+ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
450 |
"create a Supplier<GZIPInputStream>. Calls Supplier.get() " + |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
451 |
"and readAllBytes() from main thread"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
452 |
out.println("Uses an inline executor (no threads)"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
453 |
HttpClient client = null; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
454 |
for (int i=0; i< ITERATION_COUNT; i++) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
455 |
if (!sameClient || client == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
456 |
client = newInLineClient(); // should even work with no threads |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
457 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
458 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri + "/gz/LoremIpsum.txt.gz")) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
459 |
.build(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
460 |
// This is dangerous, because the finisher will block. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
461 |
// We support this, but the executor must have enough threads. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
462 |
BodyHandler<Supplier<InputStream>> handler = new BodyHandler<Supplier<InputStream>>() { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
463 |
public HttpResponse.BodySubscriber<Supplier<InputStream>> apply( |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
464 |
HttpResponse.ResponseInfo responseInfo) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
465 |
{ |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
466 |
String contentType = responseInfo.headers().firstValue("Content-Encoding") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
467 |
.orElse("identity"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
468 |
out.println("Content-Encoding: " + contentType); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
469 |
if (contentType.equalsIgnoreCase("gzip")) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
470 |
// This is dangerous. Blocking in the mapping function can wedge the |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
471 |
// response. We do support it provided that there enough thread in |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
472 |
// the executor. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
473 |
return BodySubscribers.mapping(BodySubscribers.ofInputStream(), |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
474 |
(is) -> (() -> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
475 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
476 |
return new GZIPInputStream(is); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
477 |
} catch (IOException io) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
478 |
throw new UncheckedIOException(io); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
479 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
480 |
})); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
481 |
} else return BodySubscribers.mapping(BodySubscribers.ofInputStream(), |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
482 |
(is) -> (() -> is)); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
483 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
484 |
}; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
485 |
HttpResponse<Supplier<InputStream>> response = client.send(req, handler); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
486 |
String lorem = new String(response.body().get().readAllBytes(), UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
487 |
if (!LOREM_IPSUM.equals(lorem)) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
488 |
out.println("Response doesn't match"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
489 |
out.println("[" + LOREM_IPSUM + "] != [" + lorem + "]"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
490 |
assertEquals(LOREM_IPSUM, lorem); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
491 |
} else { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
492 |
out.println("Received expected response."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
493 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
494 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
495 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
496 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
497 |
static final class GZIPBodyHandler implements BodyHandler<InputStream> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
498 |
@Override |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
499 |
public HttpResponse.BodySubscriber<InputStream> apply(HttpResponse.ResponseInfo responseInfo) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
500 |
String contentType = responseInfo.headers().firstValue("Content-Encoding") |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
501 |
.orElse("identity"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
502 |
out.println("Content-Encoding: " + contentType); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
503 |
if (contentType.equalsIgnoreCase("gzip")) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
504 |
// This is dangerous. Blocking in the mapping function can wedge the |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
505 |
// response. We do support it provided that there enough thread in |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
506 |
// the executor. |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
507 |
return BodySubscribers.mapping(BodySubscribers.ofInputStream(), |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
508 |
(is) -> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
509 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
510 |
return new GZIPInputStream(is); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
511 |
} catch (IOException io) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
512 |
throw new UncheckedIOException(io); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
513 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
514 |
}); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
515 |
} else return BodySubscribers.ofInputStream(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
516 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
517 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
518 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
519 |
static final class MappingBodyHandler<T,U> implements BodyHandler<U> { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
520 |
final BodyHandler<T> upstream; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
521 |
final Function<? super T,? extends U> finisher; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
522 |
MappingBodyHandler(BodyHandler<T> upstream, Function<T,U> finisher) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
523 |
this.upstream = upstream; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
524 |
this.finisher = finisher; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
525 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
526 |
@Override |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
527 |
public HttpResponse.BodySubscriber<U> apply(HttpResponse.ResponseInfo responseInfo) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
528 |
return BodySubscribers.mapping(upstream.apply(responseInfo), finisher); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
529 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
530 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
531 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
532 |
static String serverAuthority(HttpServer server) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
533 |
return InetAddress.getLoopbackAddress().getHostName() + ":" |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
534 |
+ server.getAddress().getPort(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
535 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
536 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
537 |
@BeforeTest |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
538 |
public void setup() throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
539 |
sslContext = new SimpleSSLContext().get(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
540 |
if (sslContext == null) |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
541 |
throw new AssertionError("Unexpected null sslContext"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
542 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
543 |
HttpTestHandler plainHandler = new LoremIpsumPlainHandler(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
544 |
HttpTestHandler gzipHandler = new LoremIpsumGZIPHandler(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
545 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
546 |
// HTTP/1.1 |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
547 |
InetSocketAddress sa = new InetSocketAddress(InetAddress.getLoopbackAddress(), 0); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
548 |
httpTestServer = HttpTestServer.of(HttpServer.create(sa, 0)); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
549 |
httpTestServer.addHandler(plainHandler, "/http1/chunk/txt"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
550 |
httpTestServer.addHandler(gzipHandler, "/http1/chunk/gz"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
551 |
httpURI = "http://" + httpTestServer.serverAuthority() + "/http1/chunk"; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
552 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
553 |
HttpsServer httpsServer = HttpsServer.create(sa, 0); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
554 |
httpsServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
555 |
httpsTestServer = HttpTestServer.of(httpsServer); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
556 |
httpsTestServer.addHandler(plainHandler, "/https1/chunk/txt"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
557 |
httpsTestServer.addHandler(gzipHandler, "/https1/chunk/gz"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
558 |
httpsURI = "https://" + httpsTestServer.serverAuthority() + "/https1/chunk"; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
559 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
560 |
// HTTP/2 |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
561 |
http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
562 |
http2TestServer.addHandler(plainHandler, "/http2/chunk/txt"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
563 |
http2TestServer.addHandler(gzipHandler, "/http2/chunk/gz"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
564 |
http2URI = "http://" + http2TestServer.serverAuthority() + "/http2/chunk"; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
565 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
566 |
https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, sslContext)); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
567 |
https2TestServer.addHandler(plainHandler, "/https2/chunk/txt"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
568 |
https2TestServer.addHandler(gzipHandler, "/https2/chunk/gz"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
569 |
https2URI = "https://" + https2TestServer.serverAuthority() + "/https2/chunk"; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
570 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
571 |
httpTestServer.start(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
572 |
httpsTestServer.start(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
573 |
http2TestServer.start(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
574 |
https2TestServer.start(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
575 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
576 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
577 |
@AfterTest |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
578 |
public void teardown() throws Exception { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
579 |
Thread.sleep(100); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
580 |
AssertionError fail = TRACKER.check(500); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
581 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
582 |
httpTestServer.stop(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
583 |
httpsTestServer.stop(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
584 |
http2TestServer.stop(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
585 |
https2TestServer.stop(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
586 |
} finally { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
587 |
if (fail != null) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
588 |
throw fail; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
589 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
590 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
591 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
592 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
593 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
594 |
static class LoremIpsumPlainHandler implements HttpTestHandler { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
595 |
@Override |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
596 |
public void handle(HttpTestExchange t) throws IOException { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
597 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
598 |
out.println("LoremIpsumPlainHandler received request to " + t.getRequestURI()); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
599 |
t.getResponseHeaders().addHeader("Content-Encoding", "identity"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
600 |
t.sendResponseHeaders(200, -1); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
601 |
long size = 0; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
602 |
try (OutputStream os = t.getResponseBody()) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
603 |
for (String s : LOREM_IPSUM.split("\n")) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
604 |
byte[] buf = s.getBytes(StandardCharsets.UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
605 |
System.out.println("Writing " + (buf.length + 1) + " bytes..."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
606 |
os.write(buf); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
607 |
os.write('\n'); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
608 |
os.flush(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
609 |
size += buf.length + 1; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
610 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
611 |
} finally { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
612 |
System.out.println("Sent " + size + " bytes"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
613 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
614 |
} catch (IOException | RuntimeException | Error e) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
615 |
e.printStackTrace(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
616 |
throw e; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
617 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
618 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
619 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
620 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
621 |
static class LoremIpsumGZIPHandler implements HttpTestHandler { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
622 |
@Override |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
623 |
public void handle(HttpTestExchange t) throws IOException { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
624 |
try { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
625 |
out.println("LoremIpsumGZIPHandler received request to " + t.getRequestURI()); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
626 |
t.getResponseHeaders().addHeader("Content-Encoding", "gzip"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
627 |
t.sendResponseHeaders(200, -1); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
628 |
long size = 0; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
629 |
try (GZIPOutputStream os = |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
630 |
new GZIPOutputStream(t.getResponseBody())) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
631 |
for (String s : LOREM_IPSUM.split("\n")) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
632 |
byte[] buf = s.getBytes(StandardCharsets.UTF_8); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
633 |
System.out.println("Writing and compressing " |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
634 |
+ (buf.length + 1) + " uncompressed bytes..."); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
635 |
os.write(buf); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
636 |
os.write('\n'); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
637 |
os.flush(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
638 |
size += buf.length + 1; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
639 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
640 |
} finally { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
641 |
System.out.println("Sent and compressed " + size + " uncompressed bytes"); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
642 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
643 |
} catch (IOException | RuntimeException | Error e) { |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
644 |
e.printStackTrace(); |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
645 |
throw e; |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
646 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
647 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
648 |
} |
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
649 |
|
97cf88608d76
8217264: HttpClient: Blocking operations in mapper function do not work as documented
dfuchs
parents:
diff
changeset
|
650 |
} |