author | chegar |
Wed, 07 Feb 2018 21:45:37 +0000 | |
branch | http-client-branch |
changeset 56092 | fd85b2bf2b0d |
parent 56089 | 42208b2f224e |
child 56093 | 22d94c4a3641 |
permissions | -rw-r--r-- |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
1 |
/* |
48083 | 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 |
/* |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
25 |
* @test |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
26 |
* @bug 8161157 |
48083 | 27 |
* @summary Test response body handlers/subscribers when there is no body |
28 |
* @library /lib/testlibrary http2/server |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
29 |
* @build jdk.testlibrary.SimpleSSLContext |
48083 | 30 |
* @modules java.base/sun.net.www.http |
56092
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
31 |
* java.net.http/jdk.internal.net.http.common |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
32 |
* java.net.http/jdk.internal.net.http.frame |
fd85b2bf2b0d
http-client-branch: move implementation to jdk.internal.net.http
chegar
parents:
56089
diff
changeset
|
33 |
* java.net.http/jdk.internal.net.http.hpack |
48083 | 34 |
* @run testng/othervm -Djdk.internal.httpclient.debug=true -Djdk.httpclient.HttpClient.log=all NoBodyPartOne |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
35 |
*/ |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
36 |
|
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
37 |
import java.net.URI; |
48083 | 38 |
import java.nio.file.Files; |
39 |
import java.nio.file.Path; |
|
40 |
import java.nio.file.Paths; |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
41 |
import java.net.http.HttpClient; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
42 |
import java.net.http.HttpRequest; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
43 |
import java.net.http.HttpResponse; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
44 |
import java.net.http.HttpResponse.BodyHandler; |
48083 | 45 |
import org.testng.annotations.Test; |
46 |
import static java.nio.charset.StandardCharsets.UTF_8; |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
47 |
import static java.net.http.HttpRequest.BodyPublisher.fromString; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
48 |
import static java.net.http.HttpResponse.BodyHandler.asByteArray; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
49 |
import static java.net.http.HttpResponse.BodyHandler.asFile; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
55973
diff
changeset
|
50 |
import static java.net.http.HttpResponse.BodyHandler.asString; |
48083 | 51 |
import static org.testng.Assert.assertEquals; |
52 |
import static org.testng.Assert.assertTrue; |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
53 |
|
48083 | 54 |
public class NoBodyPartOne extends AbstractNoBody { |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
55 |
|
48083 | 56 |
@Test(dataProvider = "variants") |
57 |
public void testAsString(String uri, boolean sameClient) throws Exception { |
|
58 |
printStamp(START, "testAsString(\"%s\", %s)", uri, sameClient); |
|
59 |
HttpClient client = null; |
|
60 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
61 |
if (!sameClient || client == null) |
|
62 |
client = newHttpClient(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
63 |
|
48083 | 64 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
65 |
.PUT(fromString(SIMPLE_STRING)) |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
66 |
.build(); |
48083 | 67 |
BodyHandler<String> handler = i % 2 == 0 ? asString() : asString(UTF_8); |
68 |
HttpResponse<String> response = client.send(req, handler); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
69 |
String body = response.body(); |
48083 | 70 |
assertEquals(body, ""); |
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
71 |
} |
48083 | 72 |
// We have created many clients here. Try to speed up their release. |
73 |
if (!sameClient) System.gc(); |
|
74 |
} |
|
75 |
||
76 |
@Test(dataProvider = "variants") |
|
77 |
public void testAsFile(String uri, boolean sameClient) throws Exception { |
|
78 |
printStamp(START, "testAsFile(\"%s\", %s)", uri, sameClient); |
|
79 |
HttpClient client = null; |
|
80 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
81 |
if (!sameClient || client == null) |
|
82 |
client = newHttpClient(); |
|
83 |
||
84 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
|
85 |
.PUT(fromString(SIMPLE_STRING)) |
|
86 |
.build(); |
|
87 |
Path p = Paths.get("NoBody_testAsFile.txt"); |
|
88 |
HttpResponse<Path> response = client.send(req, asFile(p)); |
|
89 |
Path bodyPath = response.body(); |
|
90 |
assertTrue(Files.exists(bodyPath)); |
|
91 |
assertEquals(Files.size(bodyPath), 0); |
|
92 |
} |
|
93 |
// We have created many clients here. Try to speed up their release. |
|
94 |
if (!sameClient) System.gc(); |
|
95 |
} |
|
96 |
||
97 |
@Test(dataProvider = "variants") |
|
98 |
public void testAsByteArray(String uri, boolean sameClient) throws Exception { |
|
99 |
printStamp(START, "testAsByteArray(\"%s\", %s)", uri, sameClient); |
|
100 |
HttpClient client = null; |
|
101 |
for (int i=0; i< ITERATION_COUNT; i++) { |
|
102 |
if (!sameClient || client == null) |
|
103 |
client = newHttpClient(); |
|
104 |
||
105 |
HttpRequest req = HttpRequest.newBuilder(URI.create(uri)) |
|
106 |
.PUT(fromString(SIMPLE_STRING)) |
|
107 |
.build(); |
|
108 |
HttpResponse<byte[]> response = client.send(req, asByteArray()); |
|
109 |
byte[] body = response.body(); |
|
110 |
assertEquals(body.length, 0); |
|
111 |
} |
|
112 |
// We have created many clients here. Try to speed up their release. |
|
113 |
if (!sameClient) System.gc(); |
|
42460
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
114 |
} |
7133f144981a
8170648: Move java.net.http package out of Java SE to incubator namespace
michaelm
parents:
diff
changeset
|
115 |
} |