author | prappo |
Mon, 19 Mar 2018 17:04:28 +0000 | |
branch | http-client-branch |
changeset 56321 | 4c3e5976942a |
parent 56320 | f82729ca8660 |
child 56323 | cf43d0ee8959 |
permissions | -rw-r--r-- |
56052 | 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 |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
27 |
* @run testng/othervm/timeout=600 |
56307
5f07fa266686
http-client-branch: add debug flags to WebSocketTest
dfuchs
parents:
56303
diff
changeset
|
28 |
* -Djdk.internal.httpclient.websocket.debug=true |
5f07fa266686
http-client-branch: add debug flags to WebSocketTest
dfuchs
parents:
56303
diff
changeset
|
29 |
* WebSocketTest |
56052 | 30 |
*/ |
31 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
32 |
import org.testng.annotations.DataProvider; |
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 |
|
56052 | 35 |
import java.io.IOException; |
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
36 |
import java.net.http.WebSocket; |
56052 | 37 |
import java.nio.ByteBuffer; |
38 |
import java.nio.CharBuffer; |
|
39 |
import java.nio.charset.StandardCharsets; |
|
56058 | 40 |
import java.util.ArrayList; |
41 |
import java.util.List; |
|
56052 | 42 |
import java.util.concurrent.CompletableFuture; |
43 |
import java.util.concurrent.CompletionStage; |
|
44 |
import java.util.concurrent.TimeUnit; |
|
45 |
import java.util.concurrent.TimeoutException; |
|
56263 | 46 |
import java.util.stream.Collectors; |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
47 |
|
56089
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56064
diff
changeset
|
48 |
import static java.net.http.HttpClient.newHttpClient; |
42208b2f224e
http-client-branch: move to standard package and module name
chegar
parents:
56064
diff
changeset
|
49 |
import static java.net.http.WebSocket.NORMAL_CLOSURE; |
56052 | 50 |
import static org.testng.Assert.assertEquals; |
51 |
import static org.testng.Assert.assertFalse; |
|
52 |
import static org.testng.Assert.assertThrows; |
|
53 |
import static org.testng.Assert.assertTrue; |
|
56057 | 54 |
import static org.testng.Assert.fail; |
56052 | 55 |
|
56 |
public class WebSocketTest { |
|
57 |
||
56057 | 58 |
private static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class; |
59 |
private static final Class<IllegalStateException> ISE = IllegalStateException.class; |
|
60 |
private static final Class<IOException> IOE = IOException.class; |
|
56052 | 61 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
62 |
/* shortcut */ |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
63 |
private static void assertFails(Class<? extends Throwable> clazz, |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
64 |
CompletionStage<?> stage) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
65 |
Support.assertCompletesExceptionally(clazz, stage); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
66 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
67 |
|
56294
181bc33917e4
http-client-branch: (WebSocket) logging and closure timer
prappo
parents:
56269
diff
changeset
|
68 |
@Test |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
69 |
public void illegalArgument() throws IOException { |
56052 | 70 |
try (DummyWebSocketServer server = new DummyWebSocketServer()) { |
71 |
server.open(); |
|
72 |
WebSocket ws = newHttpClient() |
|
73 |
.newWebSocketBuilder() |
|
74 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
|
75 |
.join(); |
|
76 |
||
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
77 |
assertFails(IAE, ws.sendPing(ByteBuffer.allocate(126))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
78 |
assertFails(IAE, ws.sendPing(ByteBuffer.allocate(127))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
79 |
assertFails(IAE, ws.sendPing(ByteBuffer.allocate(128))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
80 |
assertFails(IAE, ws.sendPing(ByteBuffer.allocate(129))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
81 |
assertFails(IAE, ws.sendPing(ByteBuffer.allocate(256))); |
56052 | 82 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
83 |
assertFails(IAE, ws.sendPong(ByteBuffer.allocate(126))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
84 |
assertFails(IAE, ws.sendPong(ByteBuffer.allocate(127))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
85 |
assertFails(IAE, ws.sendPong(ByteBuffer.allocate(128))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
86 |
assertFails(IAE, ws.sendPong(ByteBuffer.allocate(129))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
87 |
assertFails(IAE, ws.sendPong(ByteBuffer.allocate(256))); |
56052 | 88 |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
89 |
assertFails(IOE, ws.sendText(Support.incompleteString(), true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
90 |
assertFails(IOE, ws.sendText(Support.incompleteString(), false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
91 |
assertFails(IOE, ws.sendText(Support.malformedString(), true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
92 |
assertFails(IOE, ws.sendText(Support.malformedString(), false)); |
56052 | 93 |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
94 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.stringWithNBytes(124))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
95 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.stringWithNBytes(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
96 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.stringWithNBytes(128))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
97 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.stringWithNBytes(256))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
98 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.stringWithNBytes(257))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
99 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.stringWith2NBytes((123 / 2) + 1))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
100 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.malformedString())); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
101 |
assertFails(IAE, ws.sendClose(NORMAL_CLOSURE, Support.incompleteString())); |
56052 | 102 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
103 |
assertFails(IAE, ws.sendClose(-2, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
104 |
assertFails(IAE, ws.sendClose(-1, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
105 |
assertFails(IAE, ws.sendClose(0, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
106 |
assertFails(IAE, ws.sendClose(1, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
107 |
assertFails(IAE, ws.sendClose(500, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
108 |
assertFails(IAE, ws.sendClose(998, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
109 |
assertFails(IAE, ws.sendClose(999, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
110 |
assertFails(IAE, ws.sendClose(1002, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
111 |
assertFails(IAE, ws.sendClose(1003, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
112 |
assertFails(IAE, ws.sendClose(1006, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
113 |
assertFails(IAE, ws.sendClose(1007, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
114 |
assertFails(IAE, ws.sendClose(1009, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
115 |
assertFails(IAE, ws.sendClose(1010, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
116 |
assertFails(IAE, ws.sendClose(1012, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
117 |
assertFails(IAE, ws.sendClose(1013, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
118 |
assertFails(IAE, ws.sendClose(1015, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
119 |
assertFails(IAE, ws.sendClose(5000, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
120 |
assertFails(IAE, ws.sendClose(32768, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
121 |
assertFails(IAE, ws.sendClose(65535, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
122 |
assertFails(IAE, ws.sendClose(65536, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
123 |
assertFails(IAE, ws.sendClose(Integer.MAX_VALUE, "a reason")); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
124 |
assertFails(IAE, ws.sendClose(Integer.MIN_VALUE, "a reason")); |
56052 | 125 |
|
126 |
assertThrows(IAE, () -> ws.request(Integer.MIN_VALUE)); |
|
56055
7d387d151a3e
http-client-branch: (WebSocket) tiny spec simplification + test
prappo
parents:
56052
diff
changeset
|
127 |
assertThrows(IAE, () -> ws.request(Long.MIN_VALUE)); |
56052 | 128 |
assertThrows(IAE, () -> ws.request(-1)); |
129 |
assertThrows(IAE, () -> ws.request(0)); |
|
130 |
} |
|
131 |
} |
|
132 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
133 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
134 |
public void pendingTextPingClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
135 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
136 |
server.open(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
137 |
WebSocket ws = newHttpClient() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
138 |
.newWebSocketBuilder() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
139 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
140 |
.join(); |
56052 | 141 |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
142 |
CharBuffer data = CharBuffer.allocate(65536); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
143 |
CompletableFuture<WebSocket> cfText; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
144 |
for (int i = 0; ; i++) { // fill up the send buffer |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
145 |
System.out.printf("begin cycle #%s at %s%n", |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
146 |
i, System.currentTimeMillis()); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
147 |
cfText = ws.sendText(data, last); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
148 |
try { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
149 |
cfText.get(5, TimeUnit.SECONDS); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
150 |
data.clear(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
151 |
} catch (TimeoutException e) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
152 |
break; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
153 |
} finally { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
154 |
System.out.printf("end cycle #%s at %s%n", |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
155 |
i, System.currentTimeMillis()); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
156 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
157 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
158 |
assertFails(ISE, ws.sendText("", true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
159 |
assertFails(ISE, ws.sendText("", false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
160 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
161 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
162 |
CompletableFuture<WebSocket> cfPing = ws.sendPing(ByteBuffer.allocate(125)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
163 |
assertHangs(cfPing); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
164 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
165 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
166 |
CompletableFuture<WebSocket> cfClose = ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
167 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
168 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
169 |
assertFails(IOE, cfText); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
170 |
assertFails(IOE, cfPing); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
171 |
assertFails(IOE, cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
172 |
} |
56052 | 173 |
} |
174 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
175 |
/* shortcut */ |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
176 |
public static void assertHangs(CompletionStage<?> stage) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
177 |
Support.assertHangs(stage); |
56052 | 178 |
} |
179 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
180 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
181 |
public void pendingTextPongClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
182 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
183 |
server.open(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
184 |
WebSocket ws = newHttpClient() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
185 |
.newWebSocketBuilder() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
186 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
187 |
.join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
188 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
189 |
CharBuffer data = CharBuffer.allocate(65536); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
190 |
CompletableFuture<WebSocket> cfText; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
191 |
for (int i = 0; ; i++) { // fill up the send buffer |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
192 |
System.out.printf("begin cycle #%s at %s%n", |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
193 |
i, System.currentTimeMillis()); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
194 |
cfText = ws.sendText(data, last); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
195 |
try { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
196 |
cfText.get(5, TimeUnit.SECONDS); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
197 |
data.clear(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
198 |
} catch (TimeoutException e) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
199 |
break; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
200 |
} finally { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
201 |
System.out.printf("end cycle #%s at %s%n", |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
202 |
i, System.currentTimeMillis()); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
203 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
204 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
205 |
assertFails(ISE, ws.sendText("", true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
206 |
assertFails(ISE, ws.sendText("", false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
207 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
208 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
209 |
CompletableFuture<WebSocket> cfPong = ws.sendPong(ByteBuffer.allocate(125)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
210 |
assertHangs(cfPong); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
211 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
212 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
213 |
CompletableFuture<WebSocket> cfClose = ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
214 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
215 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
216 |
assertFails(IOE, cfText); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
217 |
assertFails(IOE, cfPong); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
218 |
assertFails(IOE, cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
219 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
220 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
221 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
222 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
223 |
public void pendingBinaryPingClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
224 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
56052 | 225 |
server.open(); |
226 |
WebSocket ws = newHttpClient() |
|
227 |
.newWebSocketBuilder() |
|
228 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
|
229 |
.join(); |
|
230 |
||
231 |
ByteBuffer data = ByteBuffer.allocate(65536); |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
232 |
CompletableFuture<WebSocket> cfBinary; |
56263 | 233 |
for (int i = 0; ; i++) { // fill up the send buffer |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
234 |
System.out.printf("begin cycle #%s at %s%n", |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
235 |
i, System.currentTimeMillis()); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
236 |
cfBinary = ws.sendBinary(data, last); |
56052 | 237 |
try { |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
238 |
cfBinary.get(5, TimeUnit.SECONDS); |
56052 | 239 |
data.clear(); |
240 |
} catch (TimeoutException e) { |
|
241 |
break; |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
242 |
} finally { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
243 |
System.out.printf("end cycle #%s at %s%n", |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
244 |
i, System.currentTimeMillis()); |
56052 | 245 |
} |
246 |
} |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
247 |
assertFails(ISE, ws.sendText("", true)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
248 |
assertFails(ISE, ws.sendText("", false)); |
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
249 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), true)); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
250 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
251 |
CompletableFuture<WebSocket> cfPing = ws.sendPing(ByteBuffer.allocate(125)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
252 |
assertHangs(cfPing); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
253 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
254 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
255 |
CompletableFuture<WebSocket> cfClose = ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
256 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
257 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
258 |
assertFails(IOE, cfBinary); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
259 |
assertFails(IOE, cfPing); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
260 |
assertFails(IOE, cfClose); |
56052 | 261 |
} |
262 |
} |
|
263 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
264 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
265 |
public void pendingBinaryPongClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
266 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
56052 | 267 |
server.open(); |
268 |
WebSocket ws = newHttpClient() |
|
269 |
.newWebSocketBuilder() |
|
270 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
|
271 |
.join(); |
|
272 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
273 |
ByteBuffer data = ByteBuffer.allocate(65536); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
274 |
CompletableFuture<WebSocket> cfBinary; |
56263 | 275 |
for (int i = 0; ; i++) { // fill up the send buffer |
56294
181bc33917e4
http-client-branch: (WebSocket) logging and closure timer
prappo
parents:
56269
diff
changeset
|
276 |
System.out.printf("begin cycle #%s at %s%n", |
181bc33917e4
http-client-branch: (WebSocket) logging and closure timer
prappo
parents:
56269
diff
changeset
|
277 |
i, System.currentTimeMillis()); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
278 |
cfBinary = ws.sendBinary(data, last); |
56052 | 279 |
try { |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
280 |
cfBinary.get(5, TimeUnit.SECONDS); |
56052 | 281 |
data.clear(); |
282 |
} catch (TimeoutException e) { |
|
283 |
break; |
|
56294
181bc33917e4
http-client-branch: (WebSocket) logging and closure timer
prappo
parents:
56269
diff
changeset
|
284 |
} finally { |
181bc33917e4
http-client-branch: (WebSocket) logging and closure timer
prappo
parents:
56269
diff
changeset
|
285 |
System.out.printf("end cycle #%s at %s%n", |
181bc33917e4
http-client-branch: (WebSocket) logging and closure timer
prappo
parents:
56269
diff
changeset
|
286 |
i, System.currentTimeMillis()); |
56052 | 287 |
} |
288 |
} |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
289 |
assertFails(ISE, ws.sendText("", true)); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
290 |
assertFails(ISE, ws.sendText("", false)); |
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
291 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), true)); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
292 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(0), false)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
293 |
CompletableFuture<WebSocket> cfPong = ws.sendPong(ByteBuffer.allocate(125)); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
294 |
assertHangs(cfPong); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
295 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
296 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
297 |
CompletableFuture<WebSocket> cfClose = ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
298 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
299 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
300 |
assertFails(IOE, cfBinary); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
301 |
assertFails(IOE, cfPong); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
302 |
assertFails(IOE, cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
303 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
304 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
305 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
306 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
307 |
public void pendingPingTextClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
308 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
309 |
server.open(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
310 |
WebSocket ws = newHttpClient() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
311 |
.newWebSocketBuilder() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
312 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
313 |
.join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
314 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
315 |
ByteBuffer data = ByteBuffer.allocate(125); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
316 |
CompletableFuture<WebSocket> cfPing; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
317 |
for (int i = 0; ; i++) { // fill up the send buffer |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
318 |
System.out.println("cycle #" + i); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
319 |
cfPing = ws.sendPing(data); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
320 |
try { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
321 |
cfPing.get(5, TimeUnit.SECONDS); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
322 |
data.clear(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
323 |
} catch (TimeoutException e) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
324 |
break; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
325 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
326 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
327 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
328 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
329 |
CompletableFuture<WebSocket> cfText = ws.sendText("hello", last); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
330 |
assertHangs(cfText); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
331 |
CompletableFuture<WebSocket> cfClose |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
332 |
= ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
333 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
334 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
335 |
assertFails(IOE, cfPing); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
336 |
assertFails(IOE, cfText); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
337 |
assertFails(IOE, cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
338 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
339 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
340 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
341 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
342 |
public void pendingPingBinaryClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
343 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
344 |
server.open(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
345 |
WebSocket ws = newHttpClient() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
346 |
.newWebSocketBuilder() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
347 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
348 |
.join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
349 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
350 |
ByteBuffer data = ByteBuffer.allocate(125); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
351 |
CompletableFuture<WebSocket> cfPing; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
352 |
for (int i = 0; ; i++) { // fill up the send buffer |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
353 |
System.out.println("cycle #" + i); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
354 |
cfPing = ws.sendPing(data); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
355 |
try { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
356 |
cfPing.get(5, TimeUnit.SECONDS); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
357 |
data.clear(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
358 |
} catch (TimeoutException e) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
359 |
break; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
360 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
361 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
362 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
363 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
364 |
CompletableFuture<WebSocket> cfBinary |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
365 |
= ws.sendBinary(ByteBuffer.allocate(4), last); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
366 |
assertHangs(cfBinary); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
367 |
CompletableFuture<WebSocket> cfClose |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
368 |
= ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
369 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
370 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
371 |
assertFails(IOE, cfPing); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
372 |
assertFails(IOE, cfBinary); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
373 |
assertFails(IOE, cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
374 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
375 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
376 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
377 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
378 |
public void pendingPongTextClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
379 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
380 |
server.open(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
381 |
WebSocket ws = newHttpClient() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
382 |
.newWebSocketBuilder() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
383 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
384 |
.join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
385 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
386 |
ByteBuffer data = ByteBuffer.allocate(125); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
387 |
CompletableFuture<WebSocket> cfPong; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
388 |
for (int i = 0; ; i++) { // fill up the send buffer |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
389 |
System.out.println("cycle #" + i); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
390 |
cfPong = ws.sendPong(data); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
391 |
try { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
392 |
cfPong.get(5, TimeUnit.SECONDS); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
393 |
data.clear(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
394 |
} catch (TimeoutException e) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
395 |
break; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
396 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
397 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
398 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
399 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
400 |
CompletableFuture<WebSocket> cfText = ws.sendText("hello", last); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
401 |
assertHangs(cfText); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
402 |
CompletableFuture<WebSocket> cfClose |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
403 |
= ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
404 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
405 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
406 |
assertFails(IOE, cfPong); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
407 |
assertFails(IOE, cfText); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
408 |
assertFails(IOE, cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
409 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
410 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
411 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
412 |
@Test(dataProvider = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
413 |
public void pendingPongBinaryClose(boolean last) throws Exception { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
414 |
try (DummyWebSocketServer server = Support.notReadingServer()) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
415 |
server.open(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
416 |
WebSocket ws = newHttpClient() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
417 |
.newWebSocketBuilder() |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
418 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
419 |
.join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
420 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
421 |
ByteBuffer data = ByteBuffer.allocate(125); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
422 |
CompletableFuture<WebSocket> cfPong; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
423 |
for (int i = 0; ; i++) { // fill up the send buffer |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
424 |
System.out.println("cycle #" + i); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
425 |
cfPong = ws.sendPong(data); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
426 |
try { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
427 |
cfPong.get(5, TimeUnit.SECONDS); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
428 |
data.clear(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
429 |
} catch (TimeoutException e) { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
430 |
break; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
431 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
432 |
} |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
433 |
assertFails(ISE, ws.sendPing(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
434 |
assertFails(ISE, ws.sendPong(ByteBuffer.allocate(125))); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
435 |
CompletableFuture<WebSocket> cfBinary |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
436 |
= ws.sendBinary(ByteBuffer.allocate(4), last); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
437 |
assertHangs(cfBinary); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
438 |
CompletableFuture<WebSocket> cfClose |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
439 |
= ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok"); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
440 |
assertHangs(cfClose); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
441 |
ws.abort(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
442 |
assertFails(IOE, cfPong); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
443 |
assertFails(IOE, cfBinary); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
444 |
assertFails(IOE, cfClose); |
56052 | 445 |
} |
446 |
} |
|
447 |
||
448 |
@Test |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
449 |
public void partialBinaryThenText() throws IOException { |
56052 | 450 |
try (DummyWebSocketServer server = new DummyWebSocketServer()) { |
451 |
server.open(); |
|
452 |
WebSocket ws = newHttpClient() |
|
453 |
.newWebSocketBuilder() |
|
454 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
|
455 |
.join(); |
|
456 |
||
457 |
ws.sendBinary(ByteBuffer.allocate(16), false).join(); |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
458 |
assertFails(ISE, ws.sendText("text", false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
459 |
assertFails(ISE, ws.sendText("text", true)); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
460 |
// Pings & Pongs are fine |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
461 |
ws.sendPing(ByteBuffer.allocate(125)).join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
462 |
ws.sendPong(ByteBuffer.allocate(125)).join(); |
56052 | 463 |
} |
464 |
} |
|
465 |
||
466 |
@Test |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
467 |
public void partialTextThenBinary() throws IOException { |
56052 | 468 |
try (DummyWebSocketServer server = new DummyWebSocketServer()) { |
469 |
server.open(); |
|
470 |
WebSocket ws = newHttpClient() |
|
471 |
.newWebSocketBuilder() |
|
472 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
|
473 |
.join(); |
|
474 |
||
475 |
ws.sendText("text", false).join(); |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
476 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(16), false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
477 |
assertFails(ISE, ws.sendBinary(ByteBuffer.allocate(16), true)); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
478 |
// Pings & Pongs are fine |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
479 |
ws.sendPing(ByteBuffer.allocate(125)).join(); |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
480 |
ws.sendPong(ByteBuffer.allocate(125)).join(); |
56052 | 481 |
} |
482 |
} |
|
483 |
||
484 |
@Test |
|
56263 | 485 |
public void sendMethodsThrowIOE1() throws IOException { |
56052 | 486 |
try (DummyWebSocketServer server = new DummyWebSocketServer()) { |
487 |
server.open(); |
|
488 |
WebSocket ws = newHttpClient() |
|
489 |
.newWebSocketBuilder() |
|
490 |
.buildAsync(server.getURI(), new WebSocket.Listener() { }) |
|
491 |
.join(); |
|
492 |
||
56263 | 493 |
ws.sendClose(NORMAL_CLOSURE, "ok").join(); |
494 |
||
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
495 |
assertFails(IOE, ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok")); |
56052 | 496 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
497 |
assertFails(IOE, ws.sendText("", true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
498 |
assertFails(IOE, ws.sendText("", false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
499 |
assertFails(IOE, ws.sendText("abc", true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
500 |
assertFails(IOE, ws.sendText("abc", false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
501 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(0), true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
502 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(0), false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
503 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(1), true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
504 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(1), false)); |
56052 | 505 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
506 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(125))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
507 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(124))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
508 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(1))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
509 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(0))); |
56052 | 510 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
511 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(125))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
512 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(124))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
513 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(1))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
514 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(0))); |
56052 | 515 |
} |
516 |
} |
|
517 |
||
518 |
@Test |
|
56263 | 519 |
public void sendMethodsThrowIOE2() throws Exception { |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
520 |
try (DummyWebSocketServer server = Support.serverWithCannedData(0x88, 0x00)) { |
56052 | 521 |
server.open(); |
522 |
CompletableFuture<Void> onCloseCalled = new CompletableFuture<>(); |
|
523 |
CompletableFuture<Void> canClose = new CompletableFuture<>(); |
|
524 |
||
525 |
WebSocket ws = newHttpClient() |
|
526 |
.newWebSocketBuilder() |
|
527 |
.buildAsync(server.getURI(), new WebSocket.Listener() { |
|
528 |
@Override |
|
529 |
public CompletionStage<?> onClose(WebSocket webSocket, |
|
530 |
int statusCode, |
|
531 |
String reason) { |
|
56263 | 532 |
System.out.printf("onClose(%s, '%s')%n", statusCode, reason); |
56052 | 533 |
onCloseCalled.complete(null); |
534 |
return canClose; |
|
535 |
} |
|
536 |
||
537 |
@Override |
|
538 |
public void onError(WebSocket webSocket, Throwable error) { |
|
539 |
System.out.println("onError(" + error + ")"); |
|
56263 | 540 |
onCloseCalled.completeExceptionally(error); |
56052 | 541 |
} |
542 |
}) |
|
543 |
.join(); |
|
544 |
||
545 |
onCloseCalled.join(); // Wait for onClose to be called |
|
56263 | 546 |
canClose.complete(null); // Signal to the WebSocket it can close the output |
56052 | 547 |
TimeUnit.SECONDS.sleep(5); // Give canClose some time to reach the WebSocket |
56263 | 548 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
549 |
assertFails(IOE, ws.sendClose(WebSocket.NORMAL_CLOSURE, "ok")); |
56052 | 550 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
551 |
assertFails(IOE, ws.sendText("", true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
552 |
assertFails(IOE, ws.sendText("", false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
553 |
assertFails(IOE, ws.sendText("abc", true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
554 |
assertFails(IOE, ws.sendText("abc", false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
555 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(0), true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
556 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(0), false)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
557 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(1), true)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
558 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(1), false)); |
56052 | 559 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
560 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(125))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
561 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(124))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
562 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(1))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
563 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(0))); |
56052 | 564 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
565 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(125))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
566 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(124))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
567 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(1))); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
568 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(0))); |
56052 | 569 |
} |
570 |
} |
|
56058 | 571 |
|
572 |
@Test |
|
56263 | 573 |
public void simpleAggregatingBinaryMessages() throws IOException { |
574 |
List<byte[]> expected = List.of("alpha", "beta", "gamma", "delta") |
|
575 |
.stream() |
|
576 |
.map(s -> s.getBytes(StandardCharsets.US_ASCII)) |
|
577 |
.collect(Collectors.toList()); |
|
578 |
int[] binary = new int[]{ |
|
579 |
0x82, 0x05, 0x61, 0x6c, 0x70, 0x68, 0x61, // [alpha] |
|
580 |
0x02, 0x02, 0x62, 0x65, // [be |
|
581 |
0x80, 0x02, 0x74, 0x61, // ta] |
|
582 |
0x02, 0x01, 0x67, // [g |
|
583 |
0x00, 0x01, 0x61, // a |
|
584 |
0x00, 0x00, // |
|
585 |
0x00, 0x00, // |
|
586 |
0x00, 0x01, 0x6d, // m |
|
587 |
0x00, 0x01, 0x6d, // m |
|
588 |
0x80, 0x01, 0x61, // a] |
|
589 |
0x8a, 0x00, // <PONG> |
|
590 |
0x02, 0x04, 0x64, 0x65, 0x6c, 0x74, // [delt |
|
591 |
0x00, 0x01, 0x61, // a |
|
592 |
0x80, 0x00, // ] |
|
593 |
0x88, 0x00 // <CLOSE> |
|
594 |
}; |
|
595 |
CompletableFuture<List<byte[]>> actual = new CompletableFuture<>(); |
|
596 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
597 |
try (DummyWebSocketServer server = Support.serverWithCannedData(binary)) { |
56263 | 598 |
server.open(); |
599 |
||
600 |
WebSocket.Listener listener = new WebSocket.Listener() { |
|
601 |
||
602 |
List<byte[]> collectedBytes = new ArrayList<>(); |
|
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
603 |
ByteBuffer binary = ByteBuffer.allocate(1024); |
56263 | 604 |
|
605 |
@Override |
|
606 |
public CompletionStage<?> onBinary(WebSocket webSocket, |
|
607 |
ByteBuffer message, |
|
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
608 |
boolean last) { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
609 |
System.out.printf("onBinary(%s, %s)%n", message, last); |
56263 | 610 |
webSocket.request(1); |
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
611 |
|
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
612 |
append(message); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
613 |
if (last) { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
614 |
binary.flip(); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
615 |
byte[] bytes = new byte[binary.remaining()]; |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
616 |
binary.get(bytes); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
617 |
binary.clear(); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
618 |
processWholeBinary(bytes); |
56263 | 619 |
} |
620 |
return null; |
|
621 |
} |
|
622 |
||
623 |
private void append(ByteBuffer message) { |
|
624 |
if (binary.remaining() < message.remaining()) { |
|
625 |
assert message.remaining() > 0; |
|
626 |
int cap = (binary.capacity() + message.remaining()) * 2; |
|
627 |
ByteBuffer b = ByteBuffer.allocate(cap); |
|
628 |
b.put(binary.flip()); |
|
629 |
binary = b; |
|
630 |
} |
|
631 |
binary.put(message); |
|
632 |
} |
|
633 |
||
634 |
private void processWholeBinary(byte[] bytes) { |
|
635 |
String stringBytes = new String(bytes, StandardCharsets.UTF_8); |
|
636 |
System.out.println("processWholeBinary: " + stringBytes); |
|
637 |
collectedBytes.add(bytes); |
|
638 |
} |
|
639 |
||
640 |
@Override |
|
641 |
public CompletionStage<?> onClose(WebSocket webSocket, |
|
642 |
int statusCode, |
|
643 |
String reason) { |
|
644 |
actual.complete(collectedBytes); |
|
645 |
return null; |
|
646 |
} |
|
647 |
||
648 |
@Override |
|
649 |
public void onError(WebSocket webSocket, Throwable error) { |
|
650 |
actual.completeExceptionally(error); |
|
651 |
} |
|
652 |
}; |
|
653 |
||
654 |
newHttpClient().newWebSocketBuilder() |
|
655 |
.buildAsync(server.getURI(), listener) |
|
656 |
.join(); |
|
657 |
||
658 |
List<byte[]> a = actual.join(); |
|
659 |
System.out.println("joined"); |
|
660 |
assertEquals(a, expected); |
|
661 |
} |
|
662 |
} |
|
663 |
||
664 |
@Test |
|
665 |
public void simpleAggregatingTextMessages() throws IOException { |
|
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
666 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
667 |
List<String> expected = List.of("alpha", "beta", "gamma", "delta"); |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
668 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
669 |
int[] binary = new int[]{ |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
670 |
0x81, 0x05, 0x61, 0x6c, 0x70, 0x68, 0x61, // "alpha" |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
671 |
0x01, 0x02, 0x62, 0x65, // "be |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
672 |
0x80, 0x02, 0x74, 0x61, // ta" |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
673 |
0x01, 0x01, 0x67, // "g |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
674 |
0x00, 0x01, 0x61, // a |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
675 |
0x00, 0x00, // |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
676 |
0x00, 0x00, // |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
677 |
0x00, 0x01, 0x6d, // m |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
678 |
0x00, 0x01, 0x6d, // m |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
679 |
0x80, 0x01, 0x61, // a" |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
680 |
0x8a, 0x00, // <PONG> |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
681 |
0x01, 0x04, 0x64, 0x65, 0x6c, 0x74, // "delt |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
682 |
0x00, 0x01, 0x61, // a |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
683 |
0x80, 0x00, // " |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
684 |
0x88, 0x00 // <CLOSE> |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
685 |
}; |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
686 |
CompletableFuture<List<String>> actual = new CompletableFuture<>(); |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
687 |
|
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
688 |
try (DummyWebSocketServer server = Support.serverWithCannedData(binary)) { |
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
689 |
server.open(); |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
690 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
691 |
WebSocket.Listener listener = new WebSocket.Listener() { |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
692 |
|
56263 | 693 |
List<String> collectedStrings = new ArrayList<>(); |
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
694 |
StringBuilder text = new StringBuilder(); |
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
695 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
696 |
@Override |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
697 |
public CompletionStage<?> onText(WebSocket webSocket, |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
698 |
CharSequence message, |
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
699 |
boolean last) { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
700 |
System.out.printf("onText(%s, %s)%n", message, last); |
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
701 |
webSocket.request(1); |
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
702 |
text.append(message); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
703 |
if (last) { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
704 |
String str = text.toString(); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
705 |
text.setLength(0); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
706 |
processWholeText(str); |
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
707 |
} |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
708 |
return null; |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
709 |
} |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
710 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
711 |
private void processWholeText(String string) { |
56130
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
712 |
System.out.println(string); |
56263 | 713 |
collectedStrings.add(string); |
56130
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
714 |
} |
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
715 |
|
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
716 |
@Override |
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
717 |
public CompletionStage<?> onClose(WebSocket webSocket, |
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
718 |
int statusCode, |
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
719 |
String reason) { |
56263 | 720 |
actual.complete(collectedStrings); |
56130
c99ed32a4d12
http-client-branch: (WebSocket) fixing sloppy commit
prappo
parents:
56129
diff
changeset
|
721 |
return null; |
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
722 |
} |
56263 | 723 |
|
724 |
@Override |
|
725 |
public void onError(WebSocket webSocket, Throwable error) { |
|
726 |
actual.completeExceptionally(error); |
|
727 |
} |
|
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
728 |
}; |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
729 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
730 |
newHttpClient().newWebSocketBuilder() |
56263 | 731 |
.buildAsync(server.getURI(), listener) |
732 |
.join(); |
|
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
733 |
|
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
734 |
List<String> a = actual.join(); |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
735 |
assertEquals(a, expected); |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
736 |
} |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
737 |
} |
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
738 |
|
56263 | 739 |
/* |
740 |
* Exercises the scenario where requests for more messages are made prior to |
|
741 |
* completing the returned CompletionStage instances. |
|
742 |
*/ |
|
56129
fe88abe462c9
http-client-branch: (WebSocket) added test which aggregates text messages through StringBuilder
prappo
parents:
56089
diff
changeset
|
743 |
@Test |
56263 | 744 |
public void aggregatingTextMessages() throws IOException { |
56058 | 745 |
|
746 |
List<String> expected = List.of("alpha", "beta", "gamma", "delta"); |
|
747 |
||
748 |
int[] binary = new int[]{ |
|
749 |
0x81, 0x05, 0x61, 0x6c, 0x70, 0x68, 0x61, // "alpha" |
|
750 |
0x01, 0x02, 0x62, 0x65, // "be |
|
751 |
0x80, 0x02, 0x74, 0x61, // ta" |
|
752 |
0x01, 0x01, 0x67, // "g |
|
753 |
0x00, 0x01, 0x61, // a |
|
754 |
0x00, 0x00, // |
|
755 |
0x00, 0x00, // |
|
756 |
0x00, 0x01, 0x6d, // m |
|
757 |
0x00, 0x01, 0x6d, // m |
|
758 |
0x80, 0x01, 0x61, // a" |
|
759 |
0x8a, 0x00, // <PONG> |
|
760 |
0x01, 0x04, 0x64, 0x65, 0x6c, 0x74, // "delt |
|
761 |
0x00, 0x01, 0x61, // a |
|
762 |
0x80, 0x00, // " |
|
763 |
0x88, 0x00 // <CLOSE> |
|
764 |
}; |
|
765 |
CompletableFuture<List<String>> actual = new CompletableFuture<>(); |
|
766 |
||
767 |
||
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
768 |
try (DummyWebSocketServer server = Support.serverWithCannedData(binary)) { |
56058 | 769 |
server.open(); |
770 |
||
771 |
WebSocket.Listener listener = new WebSocket.Listener() { |
|
772 |
||
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
773 |
List<CharSequence> parts = new ArrayList<>(); |
56263 | 774 |
/* |
775 |
* A CompletableFuture which will complete once the current |
|
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
776 |
* message has been fully assembled. Until then the listener |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
777 |
* returns this instance for every call. |
56263 | 778 |
*/ |
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
779 |
CompletableFuture<?> currentCf = new CompletableFuture<>(); |
56058 | 780 |
List<String> collected = new ArrayList<>(); |
781 |
||
782 |
@Override |
|
783 |
public CompletionStage<?> onText(WebSocket webSocket, |
|
784 |
CharSequence message, |
|
56320
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
785 |
boolean last) { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
786 |
parts.add(message); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
787 |
if (!last) { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
788 |
webSocket.request(1); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
789 |
} else { |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
790 |
this.currentCf.thenRun(() -> webSocket.request(1)); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
791 |
CompletableFuture<?> refCf = this.currentCf; |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
792 |
processWholeMessage(new ArrayList<>(parts), refCf); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
793 |
currentCf = new CompletableFuture<>(); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
794 |
parts.clear(); |
f82729ca8660
http-client-branch: (WebSocket) removed MessagePart
prappo
parents:
56318
diff
changeset
|
795 |
return refCf; |
56058 | 796 |
} |
797 |
return currentCf; |
|
798 |
} |
|
799 |
||
800 |
@Override |
|
801 |
public CompletionStage<?> onClose(WebSocket webSocket, |
|
802 |
int statusCode, |
|
803 |
String reason) { |
|
804 |
actual.complete(collected); |
|
805 |
return null; |
|
806 |
} |
|
807 |
||
56263 | 808 |
@Override |
809 |
public void onError(WebSocket webSocket, Throwable error) { |
|
810 |
actual.completeExceptionally(error); |
|
811 |
} |
|
812 |
||
56058 | 813 |
public void processWholeMessage(List<CharSequence> data, |
814 |
CompletableFuture<?> cf) { |
|
815 |
StringBuilder b = new StringBuilder(); |
|
816 |
data.forEach(b::append); |
|
817 |
String s = b.toString(); |
|
818 |
System.out.println(s); |
|
819 |
cf.complete(null); |
|
820 |
collected.add(s); |
|
821 |
} |
|
822 |
}; |
|
56263 | 823 |
|
824 |
newHttpClient().newWebSocketBuilder() |
|
825 |
.buildAsync(server.getURI(), listener) |
|
826 |
.join(); |
|
56058 | 827 |
|
828 |
List<String> a = actual.join(); |
|
829 |
assertEquals(a, expected); |
|
830 |
} |
|
831 |
} |
|
56303
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
832 |
|
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
833 |
/* |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
834 |
* The server sends Ping messages. The WebSocket replies to these messages |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
835 |
* automatically. According to RFC 6455 a WebSocket client is free to reply |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
836 |
* only to the most recent Pings. |
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
837 |
*/ |
56303
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
838 |
@Test(dataProvider = "nPings") |
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
839 |
public void automaticPongs(int nPings) throws Exception { |
56303
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
840 |
// big enough to not bother with resize |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
841 |
ByteBuffer buffer = ByteBuffer.allocate(65536); |
56303
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
842 |
Frame.HeaderWriter w = new Frame.HeaderWriter(); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
843 |
for (int i = 0; i < nPings; i++) { |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
844 |
w.fin(true) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
845 |
.opcode(Frame.Opcode.PING) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
846 |
.noMask() |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
847 |
.payloadLen(4) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
848 |
.write(buffer); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
849 |
buffer.putInt(i); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
850 |
} |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
851 |
w.fin(true) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
852 |
.opcode(Frame.Opcode.CLOSE) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
853 |
.noMask() |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
854 |
.payloadLen(2) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
855 |
.write(buffer); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
856 |
buffer.putChar((char) 1000); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
857 |
buffer.flip(); |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
858 |
try (DummyWebSocketServer server = Support.serverWithCannedData(buffer.array())) { |
56303
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
859 |
MockListener listener = new MockListener(); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
860 |
server.open(); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
861 |
WebSocket ws = newHttpClient() |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
862 |
.newWebSocketBuilder() |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
863 |
.buildAsync(server.getURI(), listener) |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
864 |
.join(); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
865 |
List<MockListener.Invocation> inv = listener.invocations(); |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
866 |
assertEquals(inv.size(), nPings + 2); // onOpen + onClose + n*onPing |
56314
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
867 |
|
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
868 |
ByteBuffer data = server.read(); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
869 |
Frame.Reader reader = new Frame.Reader(); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
870 |
|
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
871 |
Frame.Consumer consumer = new Frame.Consumer() { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
872 |
|
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
873 |
ByteBuffer number = ByteBuffer.allocate(4); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
874 |
Frame.Masker masker = new Frame.Masker(); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
875 |
int i = -1; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
876 |
boolean closed; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
877 |
|
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
878 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
879 |
public void fin(boolean value) { assertTrue(value); } |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
880 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
881 |
public void rsv1(boolean value) { assertFalse(value); } |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
882 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
883 |
public void rsv2(boolean value) { assertFalse(value); } |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
884 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
885 |
public void rsv3(boolean value) { assertFalse(value); } |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
886 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
887 |
public void opcode(Frame.Opcode value) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
888 |
if (value == Frame.Opcode.CLOSE) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
889 |
closed = true; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
890 |
return; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
891 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
892 |
assertEquals(value, Frame.Opcode.PONG); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
893 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
894 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
895 |
public void mask(boolean value) { assertTrue(value); } |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
896 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
897 |
public void payloadLen(long value) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
898 |
if (!closed) |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
899 |
assertEquals(value, 4); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
900 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
901 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
902 |
public void maskingKey(int value) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
903 |
masker.mask(value); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
904 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
905 |
|
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
906 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
907 |
public void payloadData(ByteBuffer src) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
908 |
masker.transferMasking(src, number); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
909 |
if (closed) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
910 |
return; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
911 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
912 |
number.flip(); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
913 |
int n = number.getInt(); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
914 |
System.out.printf("pong number=%s%n", n); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
915 |
number.clear(); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
916 |
if (i >= n) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
917 |
fail(String.format("i=%s, n=%s", i, n)); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
918 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
919 |
i = n; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
920 |
} |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
921 |
|
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
922 |
@Override |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
923 |
public void endFrame() { } |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
924 |
}; |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
925 |
while (data.hasRemaining()) { |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
926 |
reader.readFrame(data, consumer); |
f92e7a8a189f
http-client-branch: (WebSocket) open tests; internal queue cap (close); logging;
prappo
parents:
56307
diff
changeset
|
927 |
} |
56303
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
928 |
} |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
929 |
} |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
930 |
|
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
931 |
@DataProvider(name = "nPings") |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
932 |
public Object[][] nPings() { |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
933 |
return new Object[][]{{1}, {2}, {4}, {8}, {9}, {1023}}; |
a82058c084ef
http-client-branch: (WebSocket) swapping automatic pong replies
prappo
parents:
56294
diff
changeset
|
934 |
} |
56318
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
935 |
|
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
936 |
@DataProvider(name = "booleans") |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
937 |
public Object[][] booleans() { |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
938 |
return new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}}; |
2a96e88888b2
http-client-branch: (WebSocket) API changes + test;
prappo
parents:
56317
diff
changeset
|
939 |
} |
56052 | 940 |
} |