author | michaelm |
Tue, 10 Apr 2018 15:04:27 +0100 | |
branch | http-client-branch |
changeset 56410 | 1b37529eaf3a |
parent 56282 | 10cebcd18d47 |
child 56451 | 9585061fdb04 |
permissions | -rw-r--r-- |
56282
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
1 |
/* |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
4 |
* |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
8 |
* |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
13 |
* accompanied this code). |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
14 |
* |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
18 |
* |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
21 |
* questions. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
22 |
*/ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
23 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
24 |
/* |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
25 |
* @test |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
26 |
* @summary Verify that dependent synchronous actions added before the promise CF |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
27 |
* completes are executed either asynchronously in an executor when the |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
28 |
* CF later completes, or in the user thread that joins. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
29 |
* @library /lib/testlibrary http2/server |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
30 |
* @build jdk.testlibrary.SimpleSSLContext HttpServerAdapters ThrowingPublishers |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
31 |
* @modules java.base/sun.net.www.http |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
32 |
* java.net.http/jdk.internal.net.http.common |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
33 |
* java.net.http/jdk.internal.net.http.frame |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
34 |
* java.net.http/jdk.internal.net.http.hpack |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
35 |
* @run testng/othervm -Djdk.internal.httpclient.debug=true DependentPromiseActionsTest |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
36 |
* @run testng/othervm/java.security.policy=dependent.policy |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
37 |
* -Djdk.internal.httpclient.debug=true DependentPromiseActionsTest |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
38 |
*/ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
39 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
40 |
import java.io.BufferedReader; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
41 |
import java.io.InputStreamReader; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
42 |
import java.lang.StackWalker.StackFrame; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
43 |
import jdk.internal.net.http.common.HttpHeadersImpl; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
44 |
import jdk.testlibrary.SimpleSSLContext; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
45 |
import org.testng.annotations.AfterTest; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
46 |
import org.testng.annotations.AfterClass; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
47 |
import org.testng.annotations.BeforeTest; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
48 |
import org.testng.annotations.DataProvider; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
49 |
import org.testng.annotations.Test; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
50 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
51 |
import javax.net.ssl.SSLContext; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
52 |
import java.io.IOException; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
53 |
import java.io.InputStream; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
54 |
import java.io.OutputStream; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
55 |
import java.net.URI; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
56 |
import java.net.URISyntaxException; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
57 |
import java.net.http.HttpClient; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
58 |
import java.net.http.HttpHeaders; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
59 |
import java.net.http.HttpRequest; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
60 |
import java.net.http.HttpResponse; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
61 |
import java.net.http.HttpResponse.BodyHandler; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
62 |
import java.net.http.HttpResponse.BodyHandlers; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
63 |
import java.net.http.HttpResponse.BodySubscriber; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
64 |
import java.net.http.HttpResponse.PushPromiseHandler; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
65 |
import java.nio.ByteBuffer; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
66 |
import java.nio.charset.StandardCharsets; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
67 |
import java.util.EnumSet; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
68 |
import java.util.List; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
69 |
import java.util.Map; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
70 |
import java.util.Optional; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
71 |
import java.util.concurrent.CompletableFuture; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
72 |
import java.util.concurrent.CompletionException; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
73 |
import java.util.concurrent.CompletionStage; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
74 |
import java.util.concurrent.ConcurrentHashMap; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
75 |
import java.util.concurrent.ConcurrentMap; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
76 |
import java.util.concurrent.Executor; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
77 |
import java.util.concurrent.Executors; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
78 |
import java.util.concurrent.Flow; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
79 |
import java.util.concurrent.Semaphore; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
80 |
import java.util.concurrent.atomic.AtomicLong; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
81 |
import java.util.concurrent.atomic.AtomicReference; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
82 |
import java.util.function.Consumer; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
83 |
import java.util.function.Function; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
84 |
import java.util.function.Supplier; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
85 |
import java.util.stream.Collectors; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
86 |
import java.util.stream.Stream; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
87 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
88 |
import static java.lang.System.err; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
89 |
import static java.lang.System.out; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
90 |
import static java.lang.String.format; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
91 |
import static java.nio.charset.StandardCharsets.UTF_8; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
92 |
import static org.testng.Assert.assertEquals; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
93 |
import static org.testng.Assert.assertTrue; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
94 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
95 |
public class DependentPromiseActionsTest implements HttpServerAdapters { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
96 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
97 |
SSLContext sslContext; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
98 |
HttpTestServer http2TestServer; // HTTP/2 ( h2c ) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
99 |
HttpTestServer https2TestServer; // HTTP/2 ( h2 ) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
100 |
String http2URI_fixed; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
101 |
String http2URI_chunk; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
102 |
String https2URI_fixed; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
103 |
String https2URI_chunk; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
104 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
105 |
static final StackWalker WALKER = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
106 |
StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
107 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
108 |
static final int ITERATION_COUNT = 1; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
109 |
// a shared executor helps reduce the amount of threads created by the test |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
110 |
static final Executor executor = new TestExecutor(Executors.newCachedThreadPool()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
111 |
static final ConcurrentMap<String, Throwable> FAILURES = new ConcurrentHashMap<>(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
112 |
static volatile boolean tasksFailed; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
113 |
static final AtomicLong serverCount = new AtomicLong(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
114 |
static final AtomicLong clientCount = new AtomicLong(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
115 |
static final long start = System.nanoTime(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
116 |
public static String now() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
117 |
long now = System.nanoTime() - start; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
118 |
long secs = now / 1000_000_000; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
119 |
long mill = (now % 1000_000_000) / 1000_000; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
120 |
long nan = now % 1000_000; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
121 |
return String.format("[%d s, %d ms, %d ns] ", secs, mill, nan); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
122 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
123 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
124 |
private volatile HttpClient sharedClient; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
125 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
126 |
static class TestExecutor implements Executor { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
127 |
final AtomicLong tasks = new AtomicLong(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
128 |
Executor executor; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
129 |
TestExecutor(Executor executor) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
130 |
this.executor = executor; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
131 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
132 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
133 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
134 |
public void execute(Runnable command) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
135 |
long id = tasks.incrementAndGet(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
136 |
executor.execute(() -> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
137 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
138 |
command.run(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
139 |
} catch (Throwable t) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
140 |
tasksFailed = true; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
141 |
System.out.printf(now() + "Task %s failed: %s%n", id, t); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
142 |
System.err.printf(now() + "Task %s failed: %s%n", id, t); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
143 |
FAILURES.putIfAbsent("Task " + id, t); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
144 |
throw t; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
145 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
146 |
}); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
147 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
148 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
149 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
150 |
@AfterClass |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
151 |
static final void printFailedTests() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
152 |
out.println("\n========================="); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
153 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
154 |
out.printf("%n%sCreated %d servers and %d clients%n", |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
155 |
now(), serverCount.get(), clientCount.get()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
156 |
if (FAILURES.isEmpty()) return; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
157 |
out.println("Failed tests: "); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
158 |
FAILURES.entrySet().forEach((e) -> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
159 |
out.printf("\t%s: %s%n", e.getKey(), e.getValue()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
160 |
e.getValue().printStackTrace(out); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
161 |
e.getValue().printStackTrace(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
162 |
}); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
163 |
if (tasksFailed) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
164 |
System.out.println("WARNING: Some tasks failed"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
165 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
166 |
} finally { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
167 |
out.println("\n=========================\n"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
168 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
169 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
170 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
171 |
private String[] uris() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
172 |
return new String[] { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
173 |
http2URI_fixed, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
174 |
http2URI_chunk, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
175 |
https2URI_fixed, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
176 |
https2URI_chunk, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
177 |
}; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
178 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
179 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
180 |
static final class SemaphoreStallerSupplier |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
181 |
implements Supplier<SemaphoreStaller> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
182 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
183 |
public SemaphoreStaller get() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
184 |
return new SemaphoreStaller(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
185 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
186 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
187 |
public String toString() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
188 |
return "SemaphoreStaller"; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
189 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
190 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
191 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
192 |
@DataProvider(name = "noStalls") |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
193 |
public Object[][] noThrows() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
194 |
String[] uris = uris(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
195 |
Object[][] result = new Object[uris.length * 2][]; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
196 |
int i = 0; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
197 |
for (boolean sameClient : List.of(false, true)) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
198 |
for (String uri: uris()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
199 |
result[i++] = new Object[] {uri, sameClient}; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
200 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
201 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
202 |
assert i == uris.length * 2; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
203 |
return result; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
204 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
205 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
206 |
@DataProvider(name = "variants") |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
207 |
public Object[][] variants() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
208 |
String[] uris = uris(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
209 |
Object[][] result = new Object[uris.length * 2][]; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
210 |
int i = 0; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
211 |
Supplier<? extends Staller> s = new SemaphoreStallerSupplier(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
212 |
for (Supplier<? extends Staller> staller : List.of(s)) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
213 |
for (boolean sameClient : List.of(false, true)) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
214 |
for (String uri : uris()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
215 |
result[i++] = new Object[]{uri, sameClient, staller}; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
216 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
217 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
218 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
219 |
assert i == uris.length * 2; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
220 |
return result; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
221 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
222 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
223 |
private HttpClient makeNewClient() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
224 |
clientCount.incrementAndGet(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
225 |
return HttpClient.newBuilder() |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
226 |
.executor(executor) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
227 |
.sslContext(sslContext) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
228 |
.build(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
229 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
230 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
231 |
HttpClient newHttpClient(boolean share) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
232 |
if (!share) return makeNewClient(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
233 |
HttpClient shared = sharedClient; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
234 |
if (shared != null) return shared; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
235 |
synchronized (this) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
236 |
shared = sharedClient; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
237 |
if (shared == null) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
238 |
shared = sharedClient = makeNewClient(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
239 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
240 |
return shared; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
241 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
242 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
243 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
244 |
@Test(dataProvider = "noStalls") |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
245 |
public void testNoStalls(String uri, boolean sameClient) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
246 |
throws Exception { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
247 |
HttpClient client = null; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
248 |
out.printf("%ntestNoStalls(%s, %b)%n", uri, sameClient); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
249 |
for (int i=0; i< ITERATION_COUNT; i++) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
250 |
if (!sameClient || client == null) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
251 |
client = newHttpClient(sameClient); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
252 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
253 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
254 |
.build(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
255 |
BodyHandler<Stream<String>> handler = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
256 |
new StallingBodyHandler((w) -> {}, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
257 |
BodyHandlers.ofLines()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
258 |
Map<HttpRequest, CompletableFuture<HttpResponse<Stream<String>>>> pushPromises = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
259 |
new ConcurrentHashMap<>(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
260 |
PushPromiseHandler<Stream<String>> pushHandler = new PushPromiseHandler<>() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
261 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
262 |
public void applyPushPromise(HttpRequest initiatingRequest, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
263 |
HttpRequest pushPromiseRequest, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
264 |
Function<BodyHandler<Stream<String>>, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
265 |
CompletableFuture<HttpResponse<Stream<String>>>> |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
266 |
acceptor) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
267 |
pushPromises.putIfAbsent(pushPromiseRequest, acceptor.apply(handler)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
268 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
269 |
}; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
270 |
HttpResponse<Stream<String>> response = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
271 |
client.sendAsync(req, BodyHandlers.ofLines(), pushHandler).get(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
272 |
String body = response.body().collect(Collectors.joining("|")); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
273 |
assertEquals(URI.create(body).getPath(), URI.create(uri).getPath()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
274 |
for (HttpRequest promised : pushPromises.keySet()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
275 |
out.printf("%s Received promise: %s%n\tresponse: %s%n", |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
276 |
now(), promised, pushPromises.get(promised).get()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
277 |
String promisedBody = pushPromises.get(promised).get().body() |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
278 |
.collect(Collectors.joining("|")); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
279 |
assertEquals(promisedBody, promised.uri().toASCIIString()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
280 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
281 |
assertEquals(3, pushPromises.size()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
282 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
283 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
284 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
285 |
@Test(dataProvider = "variants") |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
286 |
public void testAsStringAsync(String uri, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
287 |
boolean sameClient, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
288 |
Supplier<Staller> stallers) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
289 |
throws Exception |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
290 |
{ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
291 |
String test = format("testAsStringAsync(%s, %b, %s)", |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
292 |
uri, sameClient, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
293 |
testDependent(test, uri, sameClient, BodyHandlers::ofString, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
294 |
this::finish, this::extractString, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
295 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
296 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
297 |
@Test(dataProvider = "variants") |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
298 |
public void testAsLinesAsync(String uri, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
299 |
boolean sameClient, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
300 |
Supplier<Staller> stallers) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
301 |
throws Exception |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
302 |
{ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
303 |
String test = format("testAsLinesAsync(%s, %b, %s)", |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
304 |
uri, sameClient, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
305 |
testDependent(test, uri, sameClient, BodyHandlers::ofLines, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
306 |
this::finish, this::extractStream, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
307 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
308 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
309 |
@Test(dataProvider = "variants") |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
310 |
public void testAsInputStreamAsync(String uri, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
311 |
boolean sameClient, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
312 |
Supplier<Staller> stallers) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
313 |
throws Exception |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
314 |
{ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
315 |
String test = format("testAsInputStreamAsync(%s, %b, %s)", |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
316 |
uri, sameClient, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
317 |
testDependent(test, uri, sameClient, BodyHandlers::ofInputStream, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
318 |
this::finish, this::extractInputStream, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
319 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
320 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
321 |
private <T,U> void testDependent(String name, String uri, boolean sameClient, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
322 |
Supplier<BodyHandler<T>> handlers, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
323 |
Finisher finisher, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
324 |
Extractor<T> extractor, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
325 |
Supplier<Staller> stallers) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
326 |
throws Exception |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
327 |
{ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
328 |
out.printf("%n%s%s%n", now(), name); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
329 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
330 |
testDependent(uri, sameClient, handlers, finisher, extractor, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
331 |
} catch (Error | Exception x) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
332 |
FAILURES.putIfAbsent(name, x); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
333 |
throw x; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
334 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
335 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
336 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
337 |
private <T,U> void testDependent(String uri, boolean sameClient, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
338 |
Supplier<BodyHandler<T>> handlers, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
339 |
Finisher finisher, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
340 |
Extractor<T> extractor, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
341 |
Supplier<Staller> stallers) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
342 |
throws Exception |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
343 |
{ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
344 |
HttpClient client = null; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
345 |
for (Where where : EnumSet.of(Where.BODY_HANDLER)) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
346 |
if (!sameClient || client == null) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
347 |
client = newHttpClient(sameClient); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
348 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
349 |
HttpRequest req = HttpRequest. |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
350 |
newBuilder(URI.create(uri)) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
351 |
.build(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
352 |
StallingPushPromiseHandler<T> promiseHandler = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
353 |
new StallingPushPromiseHandler<>(where, handlers, stallers); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
354 |
BodyHandler<T> handler = handlers.get(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
355 |
System.out.println("try stalling in " + where); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
356 |
CompletableFuture<HttpResponse<T>> responseCF = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
357 |
client.sendAsync(req, handler, promiseHandler); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
358 |
assert !responseCF.isDone(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
359 |
finisher.finish(where, responseCF, promiseHandler, extractor); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
360 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
361 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
362 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
363 |
enum Where { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
364 |
ON_PUSH_PROMISE, BODY_HANDLER, ON_SUBSCRIBE, ON_NEXT, ON_COMPLETE, ON_ERROR, GET_BODY, BODY_CF; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
365 |
public Consumer<Where> select(Consumer<Where> consumer) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
366 |
return new Consumer<Where>() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
367 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
368 |
public void accept(Where where) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
369 |
if (Where.this == where) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
370 |
consumer.accept(where); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
371 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
372 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
373 |
}; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
374 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
375 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
376 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
377 |
static final class StallingPushPromiseHandler<T> implements PushPromiseHandler<T> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
378 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
379 |
static final class Tuple<U> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
380 |
public final CompletableFuture<HttpResponse<U>> response; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
381 |
public final Staller staller; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
382 |
public final AtomicReference<RuntimeException> failed; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
383 |
Tuple(AtomicReference<RuntimeException> failed, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
384 |
CompletableFuture<HttpResponse<U>> response, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
385 |
Staller staller) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
386 |
this.response = response; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
387 |
this.staller = staller; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
388 |
this.failed = failed; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
389 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
390 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
391 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
392 |
public final ConcurrentMap<HttpRequest, Tuple<T>> promiseMap = |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
393 |
new ConcurrentHashMap<>(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
394 |
private final Supplier<Staller> stallers; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
395 |
private final Supplier<BodyHandler<T>> handlers; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
396 |
private final Where where; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
397 |
private final Thread thread = Thread.currentThread(); // main thread |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
398 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
399 |
StallingPushPromiseHandler(Where where, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
400 |
Supplier<BodyHandler<T>> handlers, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
401 |
Supplier<Staller> stallers) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
402 |
this.where = where; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
403 |
this.handlers = handlers; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
404 |
this.stallers = stallers; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
405 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
406 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
407 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
408 |
public void applyPushPromise(HttpRequest initiatingRequest, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
409 |
HttpRequest pushPromiseRequest, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
410 |
Function<BodyHandler<T>, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
411 |
CompletableFuture<HttpResponse<T>>> acceptor) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
412 |
AtomicReference<RuntimeException> failed = new AtomicReference<>(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
413 |
Staller staller = stallers.get(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
414 |
staller.acquire(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
415 |
assert staller.willStall(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
416 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
417 |
BodyHandler handler = new StallingBodyHandler<>( |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
418 |
where.select(staller), handlers.get()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
419 |
CompletableFuture<HttpResponse<T>> cf = acceptor.apply(handler); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
420 |
Tuple<T> tuple = new Tuple(failed, cf, staller); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
421 |
promiseMap.putIfAbsent(pushPromiseRequest, tuple); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
422 |
CompletableFuture<?> done = cf.whenComplete( |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
423 |
(r, t) -> checkThreadAndStack(thread, failed, r, t)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
424 |
assert !cf.isDone(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
425 |
} finally { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
426 |
staller.release(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
427 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
428 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
429 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
430 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
431 |
interface Extractor<T> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
432 |
public List<String> extract(HttpResponse<T> resp); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
433 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
434 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
435 |
final List<String> extractString(HttpResponse<String> resp) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
436 |
return List.of(resp.body()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
437 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
438 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
439 |
final List<String> extractStream(HttpResponse<Stream<String>> resp) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
440 |
return resp.body().collect(Collectors.toList()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
441 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
442 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
443 |
final List<String> extractInputStream(HttpResponse<InputStream> resp) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
444 |
try (InputStream is = resp.body()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
445 |
return new BufferedReader(new InputStreamReader(is)) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
446 |
.lines().collect(Collectors.toList()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
447 |
} catch (IOException x) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
448 |
throw new CompletionException(x); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
449 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
450 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
451 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
452 |
interface Finisher<T> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
453 |
public void finish(Where w, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
454 |
CompletableFuture<HttpResponse<T>> cf, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
455 |
StallingPushPromiseHandler<T> ph, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
456 |
Extractor<T> extractor); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
457 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
458 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
459 |
static Optional<StackFrame> findFrame(Stream<StackFrame> s, String name) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
460 |
return s.filter((f) -> f.getClassName().contains(name)) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
461 |
.filter((f) -> f.getDeclaringClass().getModule().equals(HttpClient.class.getModule())) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
462 |
.findFirst(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
463 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
464 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
465 |
static <T> void checkThreadAndStack(Thread thread, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
466 |
AtomicReference<RuntimeException> failed, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
467 |
T result, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
468 |
Throwable error) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
469 |
if (Thread.currentThread() == thread) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
470 |
//failed.set(new RuntimeException("Dependant action was executed in " + thread)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
471 |
List<StackFrame> httpStack = WALKER.walk(s -> s.filter(f -> f.getDeclaringClass() |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
472 |
.getModule().equals(HttpClient.class.getModule())) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
473 |
.collect(Collectors.toList())); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
474 |
if (!httpStack.isEmpty()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
475 |
System.out.println("Found unexpected trace: "); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
476 |
httpStack.forEach(f -> System.out.printf("\t%s%n", f)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
477 |
failed.set(new RuntimeException("Dependant action has unexpected frame in " + |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
478 |
Thread.currentThread() + ": " + httpStack.get(0))); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
479 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
480 |
} return; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
481 |
} else if (System.getSecurityManager() != null) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
482 |
Optional<StackFrame> sf = WALKER.walk(s -> findFrame(s, "PrivilegedRunnable")); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
483 |
if (!sf.isPresent()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
484 |
failed.set(new RuntimeException("Dependant action does not have expected frame in " |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
485 |
+ Thread.currentThread())); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
486 |
return; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
487 |
} else { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
488 |
System.out.println("Found expected frame: " + sf.get()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
489 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
490 |
} else { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
491 |
List<StackFrame> httpStack = WALKER.walk(s -> s.filter(f -> f.getDeclaringClass() |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
492 |
.getModule().equals(HttpClient.class.getModule())) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
493 |
.collect(Collectors.toList())); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
494 |
if (!httpStack.isEmpty()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
495 |
System.out.println("Found unexpected trace: "); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
496 |
httpStack.forEach(f -> System.out.printf("\t%s%n", f)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
497 |
failed.set(new RuntimeException("Dependant action has unexpected frame in " + |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
498 |
Thread.currentThread() + ": " + httpStack.get(0))); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
499 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
500 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
501 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
502 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
503 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
504 |
<T> void finish(Where w, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
505 |
StallingPushPromiseHandler.Tuple<T> tuple, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
506 |
Extractor<T> extractor) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
507 |
AtomicReference<RuntimeException> failed = tuple.failed; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
508 |
CompletableFuture<HttpResponse<T>> done = tuple.response; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
509 |
Staller staller = tuple.staller; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
510 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
511 |
HttpResponse<T> response = done.join(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
512 |
List<String> result = extractor.extract(response); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
513 |
URI uri = response.uri(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
514 |
RuntimeException error = failed.get(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
515 |
if (error != null) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
516 |
throw new RuntimeException("Test failed in " |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
517 |
+ w + ": " + uri, error); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
518 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
519 |
assertEquals(result, List.of(response.request().uri().toASCIIString())); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
520 |
} finally { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
521 |
staller.reset(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
522 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
523 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
524 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
525 |
<T> void finish(Where w, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
526 |
CompletableFuture<HttpResponse<T>> cf, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
527 |
StallingPushPromiseHandler<T> ph, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
528 |
Extractor<T> extractor) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
529 |
HttpResponse<T> response = cf.join(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
530 |
List<String> result = extractor.extract(response); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
531 |
for (HttpRequest req : ph.promiseMap.keySet()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
532 |
finish(w, ph.promiseMap.get(req), extractor); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
533 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
534 |
assertEquals(ph.promiseMap.size(), 3, |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
535 |
"Expected 3 push promises for " + w + " in " |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
536 |
+ response.request().uri()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
537 |
assertEquals(result, List.of(response.request().uri().toASCIIString())); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
538 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
539 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
540 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
541 |
interface Staller extends Consumer<Where> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
542 |
void release(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
543 |
void acquire(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
544 |
void reset(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
545 |
boolean willStall(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
546 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
547 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
548 |
static final class SemaphoreStaller implements Staller { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
549 |
final Semaphore sem = new Semaphore(1); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
550 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
551 |
public void accept(Where where) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
552 |
sem.acquireUninterruptibly(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
553 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
554 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
555 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
556 |
public void release() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
557 |
sem.release(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
558 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
559 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
560 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
561 |
public void acquire() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
562 |
sem.acquireUninterruptibly(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
563 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
564 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
565 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
566 |
public void reset() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
567 |
sem.drainPermits(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
568 |
sem.release(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
569 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
570 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
571 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
572 |
public boolean willStall() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
573 |
return sem.availablePermits() <= 0; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
574 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
575 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
576 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
577 |
public String toString() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
578 |
return "SemaphoreStaller"; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
579 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
580 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
581 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
582 |
static final class StallingBodyHandler<T> implements BodyHandler<T> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
583 |
final Consumer<Where> stalling; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
584 |
final BodyHandler<T> bodyHandler; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
585 |
StallingBodyHandler(Consumer<Where> stalling, BodyHandler<T> bodyHandler) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
586 |
this.stalling = stalling; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
587 |
this.bodyHandler = bodyHandler; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
588 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
589 |
@Override |
56410
1b37529eaf3a
http-client-branch: 8201312: More evolution friendly BodyHandler API
michaelm
parents:
56282
diff
changeset
|
590 |
public BodySubscriber<T> apply(HttpResponse.ResponseInfo rinfo) { |
56282
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
591 |
stalling.accept(Where.BODY_HANDLER); |
56410
1b37529eaf3a
http-client-branch: 8201312: More evolution friendly BodyHandler API
michaelm
parents:
56282
diff
changeset
|
592 |
BodySubscriber<T> subscriber = bodyHandler.apply(rinfo); |
56282
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
593 |
return new StallingBodySubscriber(stalling, subscriber); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
594 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
595 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
596 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
597 |
static final class StallingBodySubscriber<T> implements BodySubscriber<T> { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
598 |
private final BodySubscriber<T> subscriber; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
599 |
volatile boolean onSubscribeCalled; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
600 |
final Consumer<Where> stalling; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
601 |
StallingBodySubscriber(Consumer<Where> stalling, BodySubscriber<T> subscriber) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
602 |
this.stalling = stalling; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
603 |
this.subscriber = subscriber; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
604 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
605 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
606 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
607 |
public void onSubscribe(Flow.Subscription subscription) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
608 |
//out.println("onSubscribe "); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
609 |
onSubscribeCalled = true; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
610 |
stalling.accept(Where.ON_SUBSCRIBE); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
611 |
subscriber.onSubscribe(subscription); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
612 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
613 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
614 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
615 |
public void onNext(List<ByteBuffer> item) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
616 |
// out.println("onNext " + item); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
617 |
assertTrue(onSubscribeCalled); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
618 |
stalling.accept(Where.ON_NEXT); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
619 |
subscriber.onNext(item); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
620 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
621 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
622 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
623 |
public void onError(Throwable throwable) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
624 |
//out.println("onError"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
625 |
assertTrue(onSubscribeCalled); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
626 |
stalling.accept(Where.ON_ERROR); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
627 |
subscriber.onError(throwable); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
628 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
629 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
630 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
631 |
public void onComplete() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
632 |
//out.println("onComplete"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
633 |
assertTrue(onSubscribeCalled, "onComplete called before onSubscribe"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
634 |
stalling.accept(Where.ON_COMPLETE); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
635 |
subscriber.onComplete(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
636 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
637 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
638 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
639 |
public CompletionStage<T> getBody() { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
640 |
stalling.accept(Where.GET_BODY); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
641 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
642 |
stalling.accept(Where.BODY_CF); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
643 |
} catch (Throwable t) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
644 |
return CompletableFuture.failedFuture(t); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
645 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
646 |
return subscriber.getBody(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
647 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
648 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
649 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
650 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
651 |
@BeforeTest |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
652 |
public void setup() throws Exception { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
653 |
sslContext = new SimpleSSLContext().get(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
654 |
if (sslContext == null) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
655 |
throw new AssertionError("Unexpected null sslContext"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
656 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
657 |
// HTTP/2 |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
658 |
HttpTestHandler h2_fixedLengthHandler = new HTTP_FixedLengthHandler(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
659 |
HttpTestHandler h2_chunkedHandler = new HTTP_ChunkedHandler(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
660 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
661 |
http2TestServer = HttpTestServer.of(new Http2TestServer("localhost", false, 0)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
662 |
http2TestServer.addHandler(h2_fixedLengthHandler, "/http2/fixed"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
663 |
http2TestServer.addHandler(h2_chunkedHandler, "/http2/chunk"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
664 |
http2URI_fixed = "http://" + http2TestServer.serverAuthority() + "/http2/fixed/y"; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
665 |
http2URI_chunk = "http://" + http2TestServer.serverAuthority() + "/http2/chunk/y"; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
666 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
667 |
https2TestServer = HttpTestServer.of(new Http2TestServer("localhost", true, 0)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
668 |
https2TestServer.addHandler(h2_fixedLengthHandler, "/https2/fixed"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
669 |
https2TestServer.addHandler(h2_chunkedHandler, "/https2/chunk"); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
670 |
https2URI_fixed = "https://" + https2TestServer.serverAuthority() + "/https2/fixed/y"; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
671 |
https2URI_chunk = "https://" + https2TestServer.serverAuthority() + "/https2/chunk/y"; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
672 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
673 |
serverCount.addAndGet(4); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
674 |
http2TestServer.start(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
675 |
https2TestServer.start(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
676 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
677 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
678 |
@AfterTest |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
679 |
public void teardown() throws Exception { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
680 |
sharedClient = null; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
681 |
http2TestServer.stop(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
682 |
https2TestServer.stop(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
683 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
684 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
685 |
private static void pushPromiseFor(HttpTestExchange t, URI requestURI, String pushPath, boolean fixed) |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
686 |
throws IOException |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
687 |
{ |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
688 |
try { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
689 |
URI promise = new URI(requestURI.getScheme(), |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
690 |
requestURI.getAuthority(), |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
691 |
pushPath, null, null); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
692 |
byte[] promiseBytes = promise.toASCIIString().getBytes(UTF_8); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
693 |
out.printf("TestServer: %s Pushing promise: %s%n", now(), promise); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
694 |
err.printf("TestServer: %s Pushing promise: %s%n", now(), promise); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
695 |
HttpTestHeaders headers = HttpTestHeaders.of(new HttpHeadersImpl()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
696 |
if (fixed) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
697 |
headers.addHeader("Content-length", String.valueOf(promiseBytes.length)); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
698 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
699 |
t.serverPush(promise, headers, promiseBytes); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
700 |
} catch (URISyntaxException x) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
701 |
throw new IOException(x.getMessage(), x); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
702 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
703 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
704 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
705 |
static class HTTP_FixedLengthHandler implements HttpTestHandler { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
706 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
707 |
public void handle(HttpTestExchange t) throws IOException { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
708 |
out.println("HTTP_FixedLengthHandler received request to " + t.getRequestURI()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
709 |
try (InputStream is = t.getRequestBody()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
710 |
is.readAllBytes(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
711 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
712 |
URI requestURI = t.getRequestURI(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
713 |
for (int i = 1; i<2; i++) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
714 |
String path = requestURI.getPath() + "/before/promise-" + i; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
715 |
pushPromiseFor(t, requestURI, path, true); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
716 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
717 |
byte[] resp = t.getRequestURI().toString().getBytes(StandardCharsets.UTF_8); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
718 |
t.sendResponseHeaders(200, resp.length); //fixed content length |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
719 |
try (OutputStream os = t.getResponseBody()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
720 |
int bytes = resp.length/3; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
721 |
for (int i = 0; i<2; i++) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
722 |
String path = requestURI.getPath() + "/after/promise-" + (i + 2); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
723 |
os.write(resp, i * bytes, bytes); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
724 |
os.flush(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
725 |
pushPromiseFor(t, requestURI, path, true); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
726 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
727 |
os.write(resp, 2*bytes, resp.length - 2*bytes); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
728 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
729 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
730 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
731 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
732 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
733 |
static class HTTP_ChunkedHandler implements HttpTestHandler { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
734 |
@Override |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
735 |
public void handle(HttpTestExchange t) throws IOException { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
736 |
out.println("HTTP_ChunkedHandler received request to " + t.getRequestURI()); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
737 |
byte[] resp = t.getRequestURI().toString().getBytes(StandardCharsets.UTF_8); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
738 |
try (InputStream is = t.getRequestBody()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
739 |
is.readAllBytes(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
740 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
741 |
URI requestURI = t.getRequestURI(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
742 |
for (int i = 1; i<2; i++) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
743 |
String path = requestURI.getPath() + "/before/promise-" + i; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
744 |
pushPromiseFor(t, requestURI, path, false); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
745 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
746 |
t.sendResponseHeaders(200, -1); // chunked/variable |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
747 |
try (OutputStream os = t.getResponseBody()) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
748 |
int bytes = resp.length/3; |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
749 |
for (int i = 0; i<2; i++) { |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
750 |
String path = requestURI.getPath() + "/after/promise-" + (i + 2); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
751 |
os.write(resp, i * bytes, bytes); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
752 |
os.flush(); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
753 |
pushPromiseFor(t, requestURI, path, false); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
754 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
755 |
os.write(resp, 2*bytes, resp.length - 2*bytes); |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
756 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
757 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
758 |
} |
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
759 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
760 |
|
10cebcd18d47
http-client-branch: verify that dependent actions registered by the user in the CF we return are always executed either in the user thread that joins or asynchronously in the executor.
dfuchs
parents:
diff
changeset
|
761 |
} |