12
12
*/
13
13
package com .ning .http .client .ws ;
14
14
15
- import com .ning .http .client .AsyncHttpClient ;
16
- import com .ning .http .client .ws .WebSocket ;
17
- import com .ning .http .client .ws .WebSocketCloseCodeReasonListener ;
18
- import com .ning .http .client .ws .WebSocketListener ;
19
- import com .ning .http .client .ws .WebSocketTextListener ;
20
- import com .ning .http .client .ws .WebSocketUpgradeHandler ;
15
+ import static org .testng .Assert .assertEquals ;
16
+ import static org .testng .Assert .assertNotNull ;
17
+ import static org .testng .Assert .assertTrue ;
21
18
22
19
import org .testng .annotations .Test ;
23
20
21
+ import com .ning .http .client .AsyncHttpClient ;
22
+
24
23
import java .util .concurrent .CountDownLatch ;
24
+ import java .util .concurrent .ExecutionException ;
25
25
import java .util .concurrent .atomic .AtomicReference ;
26
26
27
- import static org .testng .Assert .assertEquals ;
28
- import static org .testng .Assert .assertNotNull ;
29
- import static org .testng .Assert .assertTrue ;
30
-
31
27
public abstract class CloseCodeReasonMessageTest extends TextMessageTest {
32
28
33
29
@ Test (timeOut = 60000 )
@@ -94,13 +90,41 @@ public void onError(Throwable t) {
94
90
}
95
91
}
96
92
93
+ @ Test (timeOut = 60000 , expectedExceptions = { ExecutionException .class })
94
+ public void getWebSocketThrowsException () throws Throwable {
95
+ final CountDownLatch latch = new CountDownLatch (1 );
96
+ try (AsyncHttpClient client = getAsyncHttpClient (null )) {
97
+ client .prepareGet ("http://apache.org" ).execute (new WebSocketUpgradeHandler .Builder ().addWebSocketListener (new WebSocketTextListener () {
98
+
99
+ @ Override
100
+ public void onMessage (String message ) {
101
+ }
102
+
103
+ @ Override
104
+ public void onOpen (com .ning .http .client .ws .WebSocket websocket ) {
105
+ }
106
+
107
+ @ Override
108
+ public void onClose (com .ning .http .client .ws .WebSocket websocket ) {
109
+ }
110
+
111
+ @ Override
112
+ public void onError (Throwable t ) {
113
+ latch .countDown ();
114
+ }
115
+ }).build ()).get ();
116
+ }
117
+
118
+ latch .await ();
119
+ }
120
+
97
121
@ Test (timeOut = 60000 )
98
122
public void wrongStatusCode () throws Throwable {
99
123
try (AsyncHttpClient client = getAsyncHttpClient (null )) {
100
124
final CountDownLatch latch = new CountDownLatch (1 );
101
125
final AtomicReference <Throwable > throwable = new AtomicReference <>();
102
126
103
- WebSocket websocket = client .prepareGet ("http://apache.org/" ).execute (new WebSocketUpgradeHandler .Builder ().addWebSocketListener (new WebSocketTextListener () {
127
+ client .prepareGet ("http://apache.org/" ).execute (new WebSocketUpgradeHandler .Builder ().addWebSocketListener (new WebSocketTextListener () {
104
128
105
129
@ Override
106
130
public void onMessage (String message ) {
@@ -119,7 +143,7 @@ public void onError(Throwable t) {
119
143
throwable .set (t );
120
144
latch .countDown ();
121
145
}
122
- }).build ()). get () ;
146
+ }).build ());
123
147
124
148
latch .await ();
125
149
assertNotNull (throwable .get ());
@@ -133,7 +157,7 @@ public void wrongProtocolCode() throws Throwable {
133
157
final CountDownLatch latch = new CountDownLatch (1 );
134
158
final AtomicReference <Throwable > throwable = new AtomicReference <>();
135
159
136
- WebSocket websocket = client .prepareGet ("ws://www.google.com/" ).execute (new WebSocketUpgradeHandler .Builder ().addWebSocketListener (new WebSocketTextListener () {
160
+ client .prepareGet ("ws://www.google.com/" ).execute (new WebSocketUpgradeHandler .Builder ().addWebSocketListener (new WebSocketTextListener () {
137
161
138
162
@ Override
139
163
public void onMessage (String message ) {
@@ -152,7 +176,7 @@ public void onError(Throwable t) {
152
176
throwable .set (t );
153
177
latch .countDown ();
154
178
}
155
- }).build ()). get () ;
179
+ }).build ());
156
180
157
181
latch .await ();
158
182
assertNotNull (throwable .get ());
0 commit comments