author | chegar |
Sat, 17 Mar 2018 18:01:01 +0000 | |
branch | http-client-branch |
changeset 56317 | 52a9f6b74e43 |
child 56318 | 2a96e88888b2 |
permissions | -rw-r--r-- |
56317
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
1 |
/* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
4 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
8 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
13 |
* accompanied this code). |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
14 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
18 |
* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
21 |
* questions. |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
22 |
*/ |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
23 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
24 |
/* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
25 |
* @test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
26 |
* @build DummyWebSocketServer |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
27 |
* @run testng/othervm |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
28 |
* -Djdk.internal.httpclient.websocket.debug=true |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
29 |
* ImmediateAbort |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
30 |
*/ |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
31 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
32 |
import java.io.IOException; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
33 |
import java.net.http.WebSocket; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
34 |
import java.nio.ByteBuffer; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
35 |
import java.nio.channels.SocketChannel; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
36 |
import java.util.Arrays; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
37 |
import java.util.concurrent.CompletableFuture; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
38 |
import java.util.concurrent.CompletionStage; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
39 |
import java.util.concurrent.TimeUnit; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
40 |
import java.util.concurrent.TimeoutException; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
41 |
import org.testng.annotations.Test; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
42 |
import static java.net.http.HttpClient.newHttpClient; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
43 |
import static java.net.http.WebSocket.NORMAL_CLOSURE; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
44 |
import static org.testng.Assert.assertEquals; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
45 |
import static org.testng.Assert.assertThrows; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
46 |
import static org.testng.Assert.assertTrue; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
47 |
import static org.testng.Assert.fail; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
48 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
49 |
public class ImmediateAbort { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
50 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
51 |
private static final Class<NullPointerException> NPE = NullPointerException.class; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
52 |
private static final Class<IllegalArgumentException> IAE = IllegalArgumentException.class; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
53 |
private static final Class<IOException> IOE = IOException.class; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
54 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
55 |
/* |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
56 |
* Examines WebSocket behaviour after a call to abort() |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
57 |
*/ |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
58 |
@Test |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
59 |
public void immediateAbort() throws Exception { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
60 |
try (DummyWebSocketServer server = serverWithCannedData(0x81, 0x00, 0x88, 0x00)) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
61 |
server.open(); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
62 |
CompletableFuture<Void> messageReceived = new CompletableFuture<>(); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
63 |
WebSocket.Listener listener = new WebSocket.Listener() { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
64 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
65 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
66 |
public void onOpen(WebSocket webSocket) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
67 |
/* no initial request */ |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
68 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
69 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
70 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
71 |
public CompletionStage<?> onText(WebSocket webSocket, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
72 |
CharSequence message, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
73 |
WebSocket.MessagePart part) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
74 |
messageReceived.complete(null); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
75 |
return null; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
76 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
77 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
78 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
79 |
public CompletionStage<?> onBinary(WebSocket webSocket, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
80 |
ByteBuffer message, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
81 |
WebSocket.MessagePart part) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
82 |
messageReceived.complete(null); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
83 |
return null; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
84 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
85 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
86 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
87 |
public CompletionStage<?> onPing(WebSocket webSocket, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
88 |
ByteBuffer message) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
89 |
messageReceived.complete(null); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
90 |
return null; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
91 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
92 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
93 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
94 |
public CompletionStage<?> onPong(WebSocket webSocket, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
95 |
ByteBuffer message) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
96 |
messageReceived.complete(null); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
97 |
return null; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
98 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
99 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
100 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
101 |
public CompletionStage<?> onClose(WebSocket webSocket, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
102 |
int statusCode, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
103 |
String reason) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
104 |
messageReceived.complete(null); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
105 |
return null; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
106 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
107 |
}; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
108 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
109 |
WebSocket ws = newHttpClient() |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
110 |
.newWebSocketBuilder() |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
111 |
.buildAsync(server.getURI(), listener) |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
112 |
.join(); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
113 |
for (int i = 0; i < 3; i++) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
114 |
System.out.printf("iteration #%s%n", i); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
115 |
// after the first abort() each consecutive one must be a no-op, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
116 |
// moreover, query methods should continue to return consistent, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
117 |
// permanent values |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
118 |
for (int j = 0; j < 3; j++) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
119 |
System.out.printf("abort #%s%n", j); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
120 |
ws.abort(); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
121 |
assertTrue(ws.isInputClosed()); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
122 |
assertTrue(ws.isOutputClosed()); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
123 |
assertEquals(ws.getSubprotocol(), ""); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
124 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
125 |
// at this point valid requests MUST be a no-op: |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
126 |
for (int j = 0; j < 3; j++) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
127 |
System.out.printf("request #%s%n", j); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
128 |
ws.request(1); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
129 |
ws.request(2); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
130 |
ws.request(8); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
131 |
ws.request(Integer.MAX_VALUE); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
132 |
ws.request(Long.MAX_VALUE); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
133 |
// invalid requests MUST throw IAE: |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
134 |
assertThrows(IAE, () -> ws.request(Integer.MIN_VALUE)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
135 |
assertThrows(IAE, () -> ws.request(Long.MIN_VALUE)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
136 |
assertThrows(IAE, () -> ws.request(-1)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
137 |
assertThrows(IAE, () -> ws.request(0)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
138 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
139 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
140 |
// even though there is a bunch of messages readily available on the |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
141 |
// wire we shouldn't have received any of them as we aborted before |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
142 |
// the first request |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
143 |
try { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
144 |
messageReceived.get(10, TimeUnit.SECONDS); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
145 |
fail(); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
146 |
} catch (TimeoutException expected) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
147 |
System.out.println("Finished waiting"); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
148 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
149 |
for (int i = 0; i < 3; i++) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
150 |
System.out.printf("send #%s%n", i); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
151 |
assertFails(IOE, ws.sendText("text!", false)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
152 |
assertFails(IOE, ws.sendText("text!", true)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
153 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(16), false)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
154 |
assertFails(IOE, ws.sendBinary(ByteBuffer.allocate(16), true)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
155 |
assertFails(IOE, ws.sendPing(ByteBuffer.allocate(16))); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
156 |
assertFails(IOE, ws.sendPong(ByteBuffer.allocate(16))); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
157 |
assertFails(IOE, ws.sendClose(NORMAL_CLOSURE, "a reason")); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
158 |
assertThrows(NPE, () -> ws.sendText(null, false)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
159 |
assertThrows(NPE, () -> ws.sendText(null, true)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
160 |
assertThrows(NPE, () -> ws.sendBinary(null, false)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
161 |
assertThrows(NPE, () -> ws.sendBinary(null, true)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
162 |
assertThrows(NPE, () -> ws.sendPing(null)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
163 |
assertThrows(NPE, () -> ws.sendPong(null)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
164 |
assertThrows(NPE, () -> ws.sendClose(NORMAL_CLOSURE, null)); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
165 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
166 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
167 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
168 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
169 |
private static void assertFails(Class<? extends Throwable> clazz, |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
170 |
CompletionStage<?> stage) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
171 |
Support.assertCompletesExceptionally(clazz, stage); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
172 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
173 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
174 |
private static DummyWebSocketServer serverWithCannedData(int... data) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
175 |
byte[] copy = new byte[data.length]; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
176 |
for (int i = 0; i < data.length; i++) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
177 |
copy[i] = (byte) data[i]; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
178 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
179 |
return serverWithCannedData(copy); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
180 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
181 |
|
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
182 |
private static DummyWebSocketServer serverWithCannedData(byte... data) { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
183 |
byte[] copy = Arrays.copyOf(data, data.length); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
184 |
return new DummyWebSocketServer() { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
185 |
@Override |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
186 |
protected void serve(SocketChannel channel) throws IOException { |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
187 |
ByteBuffer closeMessage = ByteBuffer.wrap(copy); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
188 |
channel.write(closeMessage); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
189 |
super.serve(channel); |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
190 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
191 |
}; |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
192 |
} |
52a9f6b74e43
http-client-branch: split large WebSocket test into three
chegar
parents:
diff
changeset
|
193 |
} |