File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
main/java/org/asynchttpclient/ws
test/java/org/asynchttpclient/ws Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -91,11 +91,11 @@ public final WebSocket onCompleted() throws Exception {
91
91
for (WebSocketListener listener : listeners ) {
92
92
listener .onError (e );
93
93
}
94
- return null ;
94
+ throw e ;
95
95
}
96
96
97
97
if (webSocket == null ) {
98
- throw new IllegalStateException ( "WebSocket is null " );
98
+ throw new NullPointerException ( "webSocket " );
99
99
}
100
100
return webSocket ;
101
101
}
Original file line number Diff line number Diff line change 27
27
import org .testng .annotations .Test ;
28
28
29
29
import java .util .concurrent .CountDownLatch ;
30
+ import java .util .concurrent .ExecutionException ;
30
31
import java .util .concurrent .atomic .AtomicReference ;
31
32
32
33
public abstract class CloseCodeReasonMessageTest extends AbstractBasicTest {
@@ -100,6 +101,34 @@ public void onError(Throwable t) {
100
101
}
101
102
}
102
103
104
+ @ Test (timeOut = 60000 , expectedExceptions = { ExecutionException .class })
105
+ public void getWebSocketThrowsException () throws Throwable {
106
+ final CountDownLatch latch = new CountDownLatch (1 );
107
+ try (AsyncHttpClient client = getAsyncHttpClient (null )) {
108
+ client .prepareGet ("http://apache.org" ).execute (new WebSocketUpgradeHandler .Builder ().addWebSocketListener (new WebSocketTextListener () {
109
+
110
+ @ Override
111
+ public void onMessage (String message ) {
112
+ }
113
+
114
+ @ Override
115
+ public void onOpen (WebSocket websocket ) {
116
+ }
117
+
118
+ @ Override
119
+ public void onClose (WebSocket websocket ) {
120
+ }
121
+
122
+ @ Override
123
+ public void onError (Throwable t ) {
124
+ latch .countDown ();
125
+ }
126
+ }).build ()).get ();
127
+ }
128
+
129
+ latch .await ();
130
+ }
131
+
103
132
@ Test (timeOut = 60000 )
104
133
public void wrongStatusCode () throws Throwable {
105
134
try (AsyncHttpClient c = getAsyncHttpClient (null )) {
@@ -125,7 +154,7 @@ public void onError(Throwable t) {
125
154
throwable .set (t );
126
155
latch .countDown ();
127
156
}
128
- }).build ()). get () ;
157
+ }).build ());
129
158
130
159
latch .await ();
131
160
assertNotNull (throwable .get ());
@@ -158,7 +187,7 @@ public void onError(Throwable t) {
158
187
throwable .set (t );
159
188
latch .countDown ();
160
189
}
161
- }).build ()). get () ;
190
+ }).build ());
162
191
163
192
latch .await ();
164
193
assertNotNull (throwable .get ());
You can’t perform that action at this time.
0 commit comments