author | dfuchs |
Mon, 27 Nov 2017 14:29:38 +0000 | |
branch | http-client-branch |
changeset 55891 | 050803da27e5 |
parent 55819 | 18e431209168 |
child 55973 | 4d9b002587db |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
55819
18e431209168
http-client-branch: Update copyright years in tests
chegar
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
4 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
8 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
13 |
* accompanied this code). |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
14 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
18 |
* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
21 |
* questions. |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
22 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
23 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
24 |
import java.io.IOException; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
import java.net.ServerSocket; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
26 |
import java.net.URI; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
27 |
import jdk.incubator.http.HttpClient; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
28 |
import jdk.incubator.http.HttpRequest; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
import jdk.incubator.http.HttpResponse; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
30 |
import jdk.incubator.http.HttpTimeoutException; |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
31 |
import jdk.testlibrary.SimpleSSLContext; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
32 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
33 |
import javax.net.ServerSocketFactory; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
34 |
import javax.net.ssl.SSLContext; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
35 |
import javax.net.ssl.SSLServerSocketFactory; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
import java.time.Duration; |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
37 |
import java.util.Arrays; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
38 |
import java.util.List; |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
39 |
import java.util.concurrent.CompletionException; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
40 |
import java.util.function.Function; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
41 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
42 |
import static java.lang.System.out; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
43 |
import static jdk.incubator.http.HttpResponse.BodyHandler.discard; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
44 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
45 |
/** |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
46 |
* @test |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
47 |
* @library /lib/testlibrary |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
48 |
* @build jdk.testlibrary.SimpleSSLContext |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
49 |
* @summary Basic tests for response timeouts |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
50 |
* @run main/othervm TimeoutBasic |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
51 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
52 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
53 |
public class TimeoutBasic { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
54 |
|
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
55 |
static List<Duration> TIMEOUTS = List.of(Duration.ofSeconds(1), |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
56 |
Duration.ofMillis(100), |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
57 |
Duration.ofNanos(99), |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
58 |
Duration.ofNanos(1)); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
59 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
60 |
static final List<Function<HttpRequest.Builder, HttpRequest.Builder>> METHODS = |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
61 |
Arrays.asList(HttpRequest.Builder::GET, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
62 |
TimeoutBasic::DELETE, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
63 |
TimeoutBasic::PUT, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
64 |
TimeoutBasic::POST, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
65 |
null); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
66 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
67 |
static final List<HttpClient.Version> VERSIONS = |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
68 |
Arrays.asList(HttpClient.Version.HTTP_2, HttpClient.Version.HTTP_1_1, null); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
69 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
70 |
static final List<String> SCHEMES = List.of("https", "http"); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
71 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
72 |
static { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
73 |
try { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
74 |
SSLContext.setDefault(new SimpleSSLContext().get()); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
75 |
} catch (IOException x) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
76 |
throw new ExceptionInInitializerError(x); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
77 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
78 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
79 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
80 |
public static void main(String[] args) throws Exception { |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
81 |
for (Function<HttpRequest.Builder, HttpRequest.Builder> m : METHODS) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
82 |
for (HttpClient.Version version : List.of(HttpClient.Version.HTTP_1_1)) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
83 |
for (HttpClient.Version reqVersion : VERSIONS) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
84 |
for (String scheme : SCHEMES) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
85 |
ServerSocketFactory ssf; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
86 |
if (scheme.equalsIgnoreCase("https")) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
87 |
ssf = SSLServerSocketFactory.getDefault(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
88 |
} else { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
89 |
ssf = ServerSocketFactory.getDefault(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
90 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
91 |
test(version, reqVersion, scheme, m, ssf); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
92 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
93 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
94 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
95 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
96 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
97 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
98 |
static HttpRequest.Builder DELETE(HttpRequest.Builder builder) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
99 |
HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublisher.noBody(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
100 |
return builder.DELETE(noBody); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
101 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
102 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
103 |
static HttpRequest.Builder PUT(HttpRequest.Builder builder) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
104 |
HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublisher.noBody(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
105 |
return builder.PUT(noBody); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
106 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
107 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
108 |
static HttpRequest.Builder POST(HttpRequest.Builder builder) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
109 |
HttpRequest.BodyPublisher noBody = HttpRequest.BodyPublisher.noBody(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
110 |
return builder.POST(noBody); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
111 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
112 |
|
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
113 |
static HttpRequest newRequest(URI uri, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
114 |
Duration duration, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
115 |
HttpClient.Version reqVersion, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
116 |
Function<HttpRequest.Builder, HttpRequest.Builder> method) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
117 |
HttpRequest.Builder reqBuilder = HttpRequest.newBuilder(uri) |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
118 |
.timeout(duration); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
119 |
if (method != null) reqBuilder = method.apply(reqBuilder); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
120 |
if (reqVersion != null) reqBuilder = reqBuilder.version(reqVersion); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
121 |
HttpRequest request = reqBuilder.build(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
122 |
if (duration.compareTo(Duration.ofSeconds(1)) >= 0) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
123 |
if (method == null || !request.method().equalsIgnoreCase("get")) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
124 |
out.println("Skipping " + duration + " for " + request.method()); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
125 |
return null; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
126 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
127 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
128 |
return request; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
129 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
130 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
131 |
public static void test(HttpClient.Version version, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
132 |
HttpClient.Version reqVersion, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
133 |
String scheme, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
134 |
Function<HttpRequest.Builder, HttpRequest.Builder> method, |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
135 |
ServerSocketFactory ssf) |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
136 |
throws Exception |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
137 |
{ |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
138 |
HttpClient.Builder builder = HttpClient.newBuilder() |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
139 |
.proxy(HttpClient.Builder.NO_PROXY); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
140 |
if (version != null) builder.version(version); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
141 |
HttpClient client = builder.build(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
142 |
out.printf("%ntest(version=%s, reqVersion=%s, scheme=%s)%n", version, reqVersion, scheme); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
143 |
try (ServerSocket ss = ssf.createServerSocket(0, 20)) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
144 |
int port = ss.getLocalPort(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
145 |
URI uri = new URI(scheme +"://127.0.0.1:" + port + "/"); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
146 |
|
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
147 |
out.println("--- TESTING Async"); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
148 |
int count = 0; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
149 |
for (Duration duration : TIMEOUTS) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
150 |
out.println(" with duration of " + duration); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
151 |
HttpRequest request = newRequest(uri, duration, reqVersion, method); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
152 |
if (request == null) continue; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
153 |
count++; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
154 |
try { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
155 |
HttpResponse<?> resp = client.sendAsync(request, discard(null)).join(); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
156 |
throw new RuntimeException("Unexpected response: " + resp.statusCode()); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
157 |
} catch (CompletionException e) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
158 |
if (!(e.getCause() instanceof HttpTimeoutException)) { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
159 |
throw new RuntimeException("Unexpected exception: " + e.getCause()); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
160 |
} else { |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
161 |
out.println("Caught expected timeout: " + e.getCause()); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
162 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
163 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
164 |
} |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
165 |
assert count >= TIMEOUTS.size() -1; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
166 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
167 |
out.println("--- TESTING Sync"); |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
168 |
count = 0; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
169 |
for (Duration duration : TIMEOUTS) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
170 |
out.println(" with duration of " + duration); |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
171 |
HttpRequest request = newRequest(uri, duration, reqVersion, method); |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
172 |
if (request == null) continue; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
173 |
count++; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
174 |
try { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
175 |
client.send(request, discard(null)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
176 |
} catch (HttpTimeoutException e) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
177 |
out.println("Caught expected timeout: " + e); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
178 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
179 |
} |
55891
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
180 |
assert count >= TIMEOUTS.size() -1; |
050803da27e5
http-client-branch: review comments: TimeoutBasic.java is ignored
dfuchs
parents:
55819
diff
changeset
|
181 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
182 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
183 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
184 |
} |