author | michaelm |
Fri, 24 Nov 2017 17:34:57 +0000 | |
branch | http-client-branch |
changeset 55868 | 5899aa5e1837 |
parent 55817 | 2aec8081d2ad |
child 55871 | 45c88bf0592b |
permissions | -rw-r--r-- |
37720 | 1 |
/* |
45535 | 2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
37720 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 8087112 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
27 |
* @library /lib/testlibrary server |
37720 | 28 |
* @build jdk.testlibrary.SimpleSSLContext |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
29 |
* @modules java.base/sun.net.www.http |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
30 |
* jdk.incubator.httpclient/jdk.incubator.http.internal.common |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
31 |
* jdk.incubator.httpclient/jdk.incubator.http.internal.frame |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
32 |
* jdk.incubator.httpclient/jdk.incubator.http.internal.hpack |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
33 |
* @run testng/othervm -Djdk.httpclient.HttpClient.log=ssl,requests,responses,errors BasicTest |
37720 | 34 |
*/ |
35 |
||
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
36 |
import java.io.IOException; |
37720 | 37 |
import java.net.*; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
38 |
import jdk.incubator.http.*; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
39 |
import static jdk.incubator.http.HttpClient.Version.HTTP_2; |
37720 | 40 |
import javax.net.ssl.*; |
41 |
import java.nio.file.*; |
|
42 |
import java.util.concurrent.*; |
|
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
43 |
import java.util.LinkedList; |
37720 | 44 |
import jdk.testlibrary.SimpleSSLContext; |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
45 |
import static jdk.incubator.http.HttpRequest.BodyPublisher.fromFile; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
46 |
import static jdk.incubator.http.HttpRequest.BodyPublisher.fromString; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
47 |
import static jdk.incubator.http.HttpResponse.BodyHandler.asFile; |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
48 |
import static jdk.incubator.http.HttpResponse.BodyHandler.asString; |
37720 | 49 |
|
50 |
import org.testng.annotations.Test; |
|
51 |
||
52 |
@Test |
|
53 |
public class BasicTest { |
|
54 |
static int httpPort, httpsPort; |
|
55 |
static Http2TestServer httpServer, httpsServer; |
|
56 |
static HttpClient client = null; |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
57 |
static ExecutorService clientExec; |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
58 |
static ExecutorService serverExec; |
37720 | 59 |
static SSLContext sslContext; |
60 |
||
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
61 |
static String pingURIString, httpURIString, httpsURIString; |
37720 | 62 |
|
63 |
static void initialize() throws Exception { |
|
64 |
try { |
|
65 |
SimpleSSLContext sslct = new SimpleSSLContext(); |
|
66 |
sslContext = sslct.get(); |
|
67 |
client = getClient(); |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
68 |
httpServer = new Http2TestServer(false, 0, serverExec, sslContext); |
45535 | 69 |
httpServer.addHandler(new Http2EchoHandler(), "/"); |
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
70 |
httpServer.addHandler(new EchoWithPingHandler(), "/ping"); |
37720 | 71 |
httpPort = httpServer.getAddress().getPort(); |
72 |
||
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
73 |
httpsServer = new Http2TestServer(true, 0, serverExec, sslContext); |
45535 | 74 |
httpsServer.addHandler(new Http2EchoHandler(), "/"); |
37720 | 75 |
|
76 |
httpsPort = httpsServer.getAddress().getPort(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
77 |
httpURIString = "http://127.0.0.1:" + httpPort + "/foo/"; |
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
78 |
pingURIString = "http://127.0.0.1:" + httpPort + "/ping/"; |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
79 |
httpsURIString = "https://127.0.0.1:" + httpsPort + "/bar/"; |
37720 | 80 |
|
81 |
httpServer.start(); |
|
82 |
httpsServer.start(); |
|
83 |
} catch (Throwable e) { |
|
84 |
System.err.println("Throwing now"); |
|
85 |
e.printStackTrace(); |
|
86 |
throw e; |
|
87 |
} |
|
88 |
} |
|
89 |
||
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
90 |
static LinkedList<CompletableFuture<Long>> cfs = new LinkedList<>(); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
91 |
|
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
92 |
static class EchoWithPingHandler extends Http2EchoHandler { |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
93 |
@Override |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
94 |
public void handle(Http2TestExchange exchange) throws IOException { |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
95 |
CompletableFuture<Long> cf = new CompletableFuture<>(); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
96 |
cfs.add(cf); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
97 |
exchange.sendPing(cf); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
98 |
super.handle(exchange); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
99 |
} |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
100 |
} |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
101 |
|
55817
2aec8081d2ad
http-client-branch: Add a test for CONTINUATION frame handling
chegar
parents:
55763
diff
changeset
|
102 |
@Test |
37720 | 103 |
public static void test() throws Exception { |
104 |
try { |
|
105 |
initialize(); |
|
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
106 |
simpleTest(false, false); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
107 |
simpleTest(false, true); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
108 |
simpleTest(true, false); |
37720 | 109 |
streamTest(false); |
110 |
streamTest(true); |
|
37799
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
111 |
paramsTest(); |
37720 | 112 |
Thread.sleep(1000 * 4); |
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
113 |
CompletableFuture.allOf(cfs.toArray(new CompletableFuture[0])).join(); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
114 |
for (CompletableFuture<Long> cf : cfs) { |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
115 |
System.out.printf("Ping ack received in %d millisec\n", cf.get()); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
116 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
117 |
} catch (Throwable tt) { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
118 |
System.err.println("tt caught"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
119 |
tt.printStackTrace(); |
43788
22a618ec8268
8174833: java/net/httpclient/http2/BasicTest.java always fails but always report success
dfuchs
parents:
42460
diff
changeset
|
120 |
throw tt; |
37720 | 121 |
} finally { |
122 |
httpServer.stop(); |
|
123 |
httpsServer.stop(); |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
124 |
//clientExec.shutdown(); |
37720 | 125 |
} |
126 |
} |
|
127 |
||
128 |
static HttpClient getClient() { |
|
129 |
if (client == null) { |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
130 |
serverExec = Executors.newCachedThreadPool(); |
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
131 |
clientExec = Executors.newCachedThreadPool(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
132 |
client = HttpClient.newBuilder() |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
133 |
.executor(clientExec) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
134 |
.sslContext(sslContext) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
135 |
.version(HTTP_2) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
136 |
.build(); |
37720 | 137 |
} |
138 |
return client; |
|
139 |
} |
|
140 |
||
141 |
static URI getURI(boolean secure) { |
|
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
142 |
return getURI(secure, false); |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
143 |
} |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
144 |
|
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
145 |
static URI getURI(boolean secure, boolean ping) { |
37720 | 146 |
if (secure) |
147 |
return URI.create(httpsURIString); |
|
148 |
else |
|
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
149 |
return URI.create(ping ? pingURIString: httpURIString); |
37720 | 150 |
} |
151 |
||
152 |
static void checkStatus(int expected, int found) throws Exception { |
|
153 |
if (expected != found) { |
|
154 |
System.err.printf ("Test failed: wrong status code %d/%d\n", |
|
155 |
expected, found); |
|
156 |
throw new RuntimeException("Test failed"); |
|
157 |
} |
|
158 |
} |
|
159 |
||
160 |
static void checkStrings(String expected, String found) throws Exception { |
|
161 |
if (!expected.equals(found)) { |
|
162 |
System.err.printf ("Test failed: wrong string %s/%s\n", |
|
163 |
expected, found); |
|
164 |
throw new RuntimeException("Test failed"); |
|
165 |
} |
|
166 |
} |
|
167 |
||
168 |
static Void compareFiles(Path path1, Path path2) { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
169 |
return TestUtil.compareFiles(path1, path2); |
37720 | 170 |
} |
171 |
||
172 |
static Path tempFile() { |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
173 |
return TestUtil.tempFile(); |
37720 | 174 |
} |
175 |
||
176 |
static final String SIMPLE_STRING = "Hello world Goodbye world"; |
|
177 |
||
178 |
static final int LOOPS = 13; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
179 |
static final int FILESIZE = 64 * 1024 + 200; |
37720 | 180 |
|
181 |
static void streamTest(boolean secure) throws Exception { |
|
182 |
URI uri = getURI(secure); |
|
183 |
System.err.printf("streamTest %b to %s\n" , secure, uri); |
|
184 |
||
185 |
HttpClient client = getClient(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
186 |
Path src = TestUtil.getAFile(FILESIZE * 4); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
187 |
HttpRequest req = HttpRequest.newBuilder(uri) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
188 |
.POST(fromFile(src)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
189 |
.build(); |
37720 | 190 |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
191 |
Path dest = Paths.get("streamtest.txt"); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
192 |
dest.toFile().delete(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
193 |
CompletableFuture<Path> response = client.sendAsync(req, asFile(dest)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
194 |
.thenApply(resp -> { |
37720 | 195 |
if (resp.statusCode() != 200) |
196 |
throw new RuntimeException(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
197 |
return resp.body(); |
37720 | 198 |
}); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
199 |
response.join(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
200 |
compareFiles(src, dest); |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
201 |
System.err.println("streamTest: DONE"); |
37720 | 202 |
} |
203 |
||
37799
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
204 |
static void paramsTest() throws Exception { |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
205 |
Http2TestServer server = new Http2TestServer(true, 0, serverExec, sslContext); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
206 |
server.addHandler((t -> { |
37799
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
207 |
SSLSession s = t.getSSLSession(); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
208 |
String prot = s.getProtocol(); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
209 |
if (prot.equals("TLSv1.2")) { |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
210 |
t.sendResponseHeaders(200, -1); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
211 |
} else { |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
212 |
System.err.printf("Protocols =%s\n", prot); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
213 |
t.sendResponseHeaders(500, -1); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
214 |
} |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
215 |
}), "/"); |
37799
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
216 |
server.start(); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
217 |
int port = server.getAddress().getPort(); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
218 |
URI u = new URI("https://127.0.0.1:"+port+"/foo"); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
219 |
HttpClient client = getClient(); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
220 |
HttpRequest req = HttpRequest.newBuilder(u).build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
221 |
HttpResponse<String> resp = client.send(req, asString()); |
37799
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
222 |
int stat = resp.statusCode(); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
223 |
if (stat != 200) { |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
224 |
throw new RuntimeException("paramsTest failed " |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
225 |
+ Integer.toString(stat)); |
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
226 |
} |
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
227 |
System.err.println("paramsTest: DONE"); |
37799
635c430d5a99
8153572: [JEP 110] IOException (connection closed for reading) is thrown when try to connect HTTPS service
michaelm
parents:
37720
diff
changeset
|
228 |
} |
37720 | 229 |
|
55868
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
230 |
static void simpleTest(boolean secure, boolean ping) throws Exception { |
5899aa5e1837
http-client-branch: added ping support to test http2 server and some test pings from server to client in the BasicTest
michaelm
parents:
55817
diff
changeset
|
231 |
URI uri = getURI(secure, ping); |
37720 | 232 |
System.err.println("Request to " + uri); |
233 |
||
234 |
// Do a simple warmup request |
|
235 |
||
236 |
HttpClient client = getClient(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
237 |
HttpRequest req = HttpRequest.newBuilder(uri) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
238 |
.POST(fromString(SIMPLE_STRING)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
239 |
.build(); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
240 |
HttpResponse<String> response = client.send(req, asString()); |
37720 | 241 |
HttpHeaders h = response.headers(); |
242 |
||
243 |
checkStatus(200, response.statusCode()); |
|
244 |
||
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
245 |
String responseBody = response.body(); |
37720 | 246 |
checkStrings(SIMPLE_STRING, responseBody); |
247 |
||
248 |
checkStrings(h.firstValue("x-hello").get(), "world"); |
|
249 |
checkStrings(h.firstValue("x-bye").get(), "universe"); |
|
250 |
||
251 |
// Do loops asynchronously |
|
252 |
||
253 |
CompletableFuture[] responses = new CompletableFuture[LOOPS]; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
254 |
final Path source = TestUtil.getAFile(FILESIZE); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
255 |
HttpRequest request = HttpRequest.newBuilder(uri) |
43788
22a618ec8268
8174833: java/net/httpclient/http2/BasicTest.java always fails but always report success
dfuchs
parents:
42460
diff
changeset
|
256 |
.POST(fromFile(source)) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
257 |
.build(); |
37720 | 258 |
for (int i = 0; i < LOOPS; i++) { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
259 |
responses[i] = client.sendAsync(request, asFile(tempFile())) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
260 |
//.thenApply(resp -> compareFiles(resp.body(), source)); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
261 |
.thenApply(resp -> { |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
262 |
System.out.printf("Resp status %d body size %d\n", |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
263 |
resp.statusCode(), resp.body().toFile().length()); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
264 |
return compareFiles(resp.body(), source); |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
38745
diff
changeset
|
265 |
}); |
37720 | 266 |
Thread.sleep(100); |
267 |
} |
|
268 |
CompletableFuture.allOf(responses).join(); |
|
55763
634d8e14c172
http-client-branch: intial load from jdk10/sandbox
chegar
parents:
47242
diff
changeset
|
269 |
System.err.println("simpleTest: DONE"); |
37720 | 270 |
} |
271 |
} |