author | chegar |
Thu, 26 Apr 2018 14:42:36 +0100 | |
branch | http-client-branch |
changeset 56486 | b664a887e277 |
parent 56451 | 9585061fdb04 |
child 56507 | 2294c51eae30 |
permissions | -rw-r--r-- |
49765 | 1 |
/* |
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
|
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 |
* @build DummyWebSocketServer |
|
27 |
* @run testng/othervm |
|
28 |
* PendingPongTextClose |
|
29 |
*/ |
|
30 |
||
31 |
// This test produce huge logs (14Mb+) so disable logging by default |
|
32 |
// * -Djdk.internal.httpclient.debug=true |
|
33 |
// * -Djdk.internal.httpclient.websocket.debug=true |
|
34 |
||
35 |
import org.testng.annotations.Test; |
|
36 |
||
37 |
import java.net.http.WebSocket; |
|
38 |
import java.nio.ByteBuffer; |
|
39 |
import java.util.concurrent.CompletableFuture; |
|
40 |
import java.util.concurrent.TimeUnit; |
|
41 |
import java.util.concurrent.TimeoutException; |
|
42 |
||
56486
b664a887e277
http-client-branch: set NO_PROXY in several WebSocket tests
chegar
parents:
56451
diff
changeset
|
43 |
import static java.net.http.HttpClient.Builder.NO_PROXY; |
b664a887e277
http-client-branch: set NO_PROXY in several WebSocket tests
chegar
parents:
56451
diff
changeset
|
44 |
import static java.net.http.HttpClient.newBuilder; |
49765 | 45 |
import static java.net.http.HttpClient.newHttpClient; |
46 |
||
47 |
public class PendingPongTextClose extends PendingOperations { |
|
48 |
||
49 |
CompletableFuture<WebSocket> cfText; |
|
50 |
CompletableFuture<WebSocket> cfPong; |
|
51 |
CompletableFuture<WebSocket> cfClose; |
|
52 |
||
53 |
@Test(dataProvider = "booleans") |
|
54 |
public void pendingPongTextClose(boolean last) throws Exception { |
|
55 |
repeatable( () -> { |
|
56 |
server = Support.notReadingServer(); |
|
57 |
server.open(); |
|
56486
b664a887e277
http-client-branch: set NO_PROXY in several WebSocket tests
chegar
parents:
56451
diff
changeset
|
58 |
webSocket = newBuilder().proxy(NO_PROXY).build().newWebSocketBuilder() |
49765 | 59 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
60 |
.join(); |
|
61 |
ByteBuffer data = ByteBuffer.allocate(125); |
|
62 |
for (int i = 0; ; i++) { // fill up the send buffer |
|
63 |
long start = System.currentTimeMillis(); |
|
64 |
System.out.printf("begin cycle #%s at %s%n", i, start); |
|
65 |
cfPong = webSocket.sendPong(data); |
|
66 |
try { |
|
67 |
cfPong.get(MAX_WAIT_SEC, TimeUnit.SECONDS); |
|
68 |
data.clear(); |
|
69 |
} catch (TimeoutException e) { |
|
70 |
break; |
|
71 |
} finally { |
|
72 |
long stop = System.currentTimeMillis(); |
|
73 |
System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start); |
|
74 |
} |
|
75 |
} |
|
76 |
assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125))); |
|
77 |
assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125))); |
|
78 |
cfText = webSocket.sendText("hello", last); |
|
79 |
assertHangs(cfText); |
|
80 |
cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
|
81 |
assertHangs(cfClose); |
|
82 |
return null; |
|
83 |
}, () -> cfPong.isDone() ? true : false); |
|
84 |
webSocket.abort(); |
|
85 |
assertFails(IOE, cfPong); |
|
86 |
assertFails(IOE, cfText); |
|
87 |
assertFails(IOE, cfClose); |
|
88 |
} |
|
89 |
} |