author | prappo |
Tue, 20 Mar 2018 10:19:00 +0000 | |
branch | http-client-branch |
changeset 56325 | 195d2970d981 |
child 56335 | 7e56c39fa1fa |
permissions | -rw-r--r-- |
56325
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
1 |
/* |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
4 |
* |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
8 |
* |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
13 |
* accompanied this code). |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
14 |
* |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
18 |
* |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
21 |
* questions. |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
22 |
*/ |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
23 |
|
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
24 |
/* |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
25 |
* @test |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
26 |
* @build DummyWebSocketServer |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
27 |
* @run testng/othervm |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
28 |
* -Djdk.internal.httpclient.websocket.debug=true |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
29 |
* PendingTextPongClose |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
30 |
*/ |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
31 |
|
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
32 |
import org.testng.annotations.Test; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
33 |
|
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
34 |
import java.net.http.WebSocket; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
35 |
import java.nio.ByteBuffer; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
36 |
import java.nio.CharBuffer; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
37 |
import java.util.concurrent.CompletableFuture; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
38 |
import java.util.concurrent.TimeUnit; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
39 |
import java.util.concurrent.TimeoutException; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
40 |
|
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
41 |
import static java.net.http.HttpClient.newHttpClient; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
42 |
|
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
43 |
public class PendingTextPongClose extends PendingOperations { |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
44 |
|
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
45 |
@Test(dataProvider = "booleans") |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
46 |
public void pendingTextPongClose(boolean last) throws Exception { |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
47 |
server = Support.notReadingServer(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
48 |
server.open(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
49 |
webSocket = newHttpClient().newWebSocketBuilder() |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
50 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
51 |
.join(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
52 |
CharBuffer data = CharBuffer.allocate(65536); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
53 |
CompletableFuture<WebSocket> cfText; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
54 |
for (int i = 0; ; i++) { // fill up the send buffer |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
55 |
long start = System.currentTimeMillis(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
56 |
System.out.printf("begin cycle #%s at %s%n", i, start); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
57 |
cfText = webSocket.sendText(data, last); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
58 |
try { |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
59 |
cfText.get(5, TimeUnit.SECONDS); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
60 |
data.clear(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
61 |
} catch (TimeoutException e) { |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
62 |
break; |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
63 |
} finally { |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
64 |
long stop = System.currentTimeMillis(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
65 |
System.out.printf("end cycle #%s at %s (%s ms)%n", i, stop, stop - start); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
66 |
} |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
67 |
} |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
68 |
assertFails(ISE, webSocket.sendText("", true)); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
69 |
assertFails(ISE, webSocket.sendText("", false)); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
70 |
assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), true)); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
71 |
assertFails(ISE, webSocket.sendBinary(ByteBuffer.allocate(0), false)); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
72 |
CompletableFuture<WebSocket> cfPong = webSocket.sendPong(ByteBuffer.allocate(125)); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
73 |
assertHangs(cfPong); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
74 |
assertFails(ISE, webSocket.sendPing(ByteBuffer.allocate(125))); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
75 |
assertFails(ISE, webSocket.sendPong(ByteBuffer.allocate(125))); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
76 |
CompletableFuture<WebSocket> cfClose = webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
77 |
assertHangs(cfClose); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
78 |
webSocket.abort(); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
79 |
assertFails(IOE, cfText); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
80 |
assertFails(IOE, cfPong); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
81 |
assertFails(IOE, cfClose); |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
82 |
} |
195d2970d981
http-client-branch: (WebSocket) split pending operations tests, otherwise it took them too long to run
prappo
parents:
diff
changeset
|
83 |
} |