author | prappo |
Wed, 21 Mar 2018 10:25:26 +0000 | |
branch | http-client-branch |
changeset 56327 | efd50952acd9 |
parent 56324 | 3edf200fff01 |
child 56428 | 3dbf8ee93b08 |
permissions | -rw-r--r-- |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
1 |
/* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
4 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
8 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
14 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
18 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
21 |
* questions. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
22 |
*/ |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
23 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
24 |
/* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
25 |
* @test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
26 |
* @build DummyWebSocketServer |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
27 |
* @run testng/othervm |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
28 |
* -Djdk.internal.httpclient.websocket.debug=true |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
29 |
* SendTest |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
30 |
*/ |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
31 |
|
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
32 |
import org.testng.annotations.AfterTest; |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
33 |
import org.testng.annotations.Test; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
34 |
|
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
35 |
import java.io.IOException; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
36 |
import java.net.http.WebSocket; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
37 |
import java.nio.ByteBuffer; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
38 |
import java.util.concurrent.CompletableFuture; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
39 |
import java.util.concurrent.TimeUnit; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
40 |
import java.util.concurrent.TimeoutException; |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
41 |
|
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
42 |
import static java.net.http.HttpClient.newHttpClient; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
43 |
import static java.net.http.WebSocket.NORMAL_CLOSURE; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
44 |
import static org.testng.Assert.assertEquals; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
45 |
import static org.testng.Assert.assertFalse; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
46 |
import static org.testng.Assert.assertThrows; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
47 |
import static org.testng.Assert.assertTrue; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
48 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
49 |
public class SendTest { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
50 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
51 |
private static final Class<NullPointerException> NPE = NullPointerException.class; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
52 |
|
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
53 |
private DummyWebSocketServer server; |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
54 |
private WebSocket webSocket; |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
55 |
|
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
56 |
@AfterTest |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
57 |
public void cleanup() { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
58 |
server.close(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
59 |
webSocket.abort(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
60 |
} |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
61 |
|
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
62 |
@Test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
63 |
public void sendMethodsThrowNPE() throws IOException { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
64 |
server = new DummyWebSocketServer(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
65 |
server.open(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
66 |
webSocket = newHttpClient().newWebSocketBuilder() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
67 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
68 |
.join(); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
69 |
|
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
70 |
assertThrows(NPE, () -> webSocket.sendText(null, false)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
71 |
assertThrows(NPE, () -> webSocket.sendText(null, true)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
72 |
assertThrows(NPE, () -> webSocket.sendBinary(null, false)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
73 |
assertThrows(NPE, () -> webSocket.sendBinary(null, true)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
74 |
assertThrows(NPE, () -> webSocket.sendPing(null)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
75 |
assertThrows(NPE, () -> webSocket.sendPong(null)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
76 |
assertThrows(NPE, () -> webSocket.sendClose(NORMAL_CLOSURE, null)); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
77 |
|
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
78 |
webSocket.abort(); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
79 |
|
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
80 |
assertThrows(NPE, () -> webSocket.sendText(null, false)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
81 |
assertThrows(NPE, () -> webSocket.sendText(null, true)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
82 |
assertThrows(NPE, () -> webSocket.sendBinary(null, false)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
83 |
assertThrows(NPE, () -> webSocket.sendBinary(null, true)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
84 |
assertThrows(NPE, () -> webSocket.sendPing(null)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
85 |
assertThrows(NPE, () -> webSocket.sendPong(null)); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
86 |
assertThrows(NPE, () -> webSocket.sendClose(NORMAL_CLOSURE, null)); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
87 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
88 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
89 |
// TODO: request in onClose/onError |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
90 |
// TODO: throw exception in onClose/onError |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
91 |
// TODO: exception is thrown from request() |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
92 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
93 |
@Test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
94 |
public void sendCloseCompleted() throws IOException { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
95 |
server = new DummyWebSocketServer(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
96 |
server.open(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
97 |
webSocket = newHttpClient().newWebSocketBuilder() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
98 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
99 |
.join(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
100 |
webSocket.sendClose(NORMAL_CLOSURE, "").join(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
101 |
assertTrue(webSocket.isOutputClosed()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
102 |
assertEquals(webSocket.getSubprotocol(), ""); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
103 |
webSocket.request(1); // No exceptions must be thrown |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
104 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
105 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
106 |
@Test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
107 |
public void sendClosePending() throws Exception { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
108 |
server = Support.notReadingServer(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
109 |
server.open(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
110 |
webSocket = newHttpClient().newWebSocketBuilder() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
111 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
112 |
.join(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
113 |
ByteBuffer data = ByteBuffer.allocate(65536); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
114 |
for (int i = 0; ; i++) { // fill up the send buffer |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
115 |
System.out.printf("begin cycle #%s at %s%n", |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
116 |
i, System.currentTimeMillis()); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
117 |
try { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
118 |
webSocket.sendBinary(data, true).get(10, TimeUnit.SECONDS); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
119 |
data.clear(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
120 |
} catch (TimeoutException e) { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
121 |
break; |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
122 |
} finally { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
123 |
System.out.printf("end cycle #%s at %s%n", |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
124 |
i, System.currentTimeMillis()); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
125 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
126 |
} |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
127 |
CompletableFuture<WebSocket> cf = webSocket.sendClose(NORMAL_CLOSURE, ""); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
128 |
// The output closes even if the Close message has not been sent |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
129 |
assertFalse(cf.isDone()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
130 |
assertTrue(webSocket.isOutputClosed()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
131 |
assertEquals(webSocket.getSubprotocol(), ""); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
132 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
133 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
134 |
@Test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
135 |
public void abortPendingSendBinary() throws Exception { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
136 |
server = Support.notReadingServer(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
137 |
server.open(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
138 |
webSocket = newHttpClient() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
139 |
.newWebSocketBuilder() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
140 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
141 |
.join(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
142 |
ByteBuffer data = ByteBuffer.allocate(65536); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
143 |
CompletableFuture<WebSocket> cf = null; |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
144 |
for (int i = 0; ; i++) { // fill up the send buffer |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
145 |
System.out.printf("begin cycle #%s at %s%n", |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
146 |
i, System.currentTimeMillis()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
147 |
try { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
148 |
cf = webSocket.sendBinary(data, true); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
149 |
cf.get(5, TimeUnit.SECONDS); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
150 |
data.clear(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
151 |
} catch (TimeoutException e) { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
152 |
break; |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
153 |
} finally { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
154 |
System.out.printf("end cycle #%s at %s%n", |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
155 |
i, System.currentTimeMillis()); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
156 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
157 |
} |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
158 |
webSocket.abort(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
159 |
assertTrue(webSocket.isOutputClosed()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
160 |
assertTrue(webSocket.isInputClosed()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
161 |
Support.assertFails(IOException.class, cf); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
162 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
163 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
164 |
@Test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
165 |
public void abortPendingSendText() throws Exception { |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
166 |
server = Support.notReadingServer(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
167 |
server.open(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
168 |
webSocket = newHttpClient() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
169 |
.newWebSocketBuilder() |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
170 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
171 |
.join(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
172 |
String data = Support.stringWith2NBytes(32768); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
173 |
CompletableFuture<WebSocket> cf = null; |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
174 |
for (int i = 0; ; i++) { // fill up the send buffer |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
175 |
System.out.printf("begin cycle #%s at %s%n", |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
176 |
i, System.currentTimeMillis()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
177 |
try { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
178 |
cf = webSocket.sendText(data, true); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
179 |
cf.get(5, TimeUnit.SECONDS); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
180 |
} catch (TimeoutException e) { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
181 |
break; |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
182 |
} finally { |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
183 |
System.out.printf("end cycle #%s at %s%n", |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
184 |
i, System.currentTimeMillis()); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
185 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
186 |
} |
56324
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
187 |
webSocket.abort(); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
188 |
assertTrue(webSocket.isOutputClosed()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
189 |
assertTrue(webSocket.isInputClosed()); |
3edf200fff01
http-client-branch: (WebSocket) full-duplex DummyWebSocketServer; tests stabilization & fixes
prappo
parents:
56320
diff
changeset
|
190 |
Support.assertFails(IOException.class, cf); |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
191 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
192 |
} |