use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class TextMessageTest method echoTwoMessagesTest.
@Test(groups = "standalone")
public void echoTwoMessagesTest() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
final CountDownLatch latch = new CountDownLatch(2);
final AtomicReference<String> text = new AtomicReference<>("");
/* WebSocket websocket = */
c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketTextListener() {
@Override
public void onMessage(String message) {
text.set(text.get() + message);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
websocket.sendMessage("ECHO").sendMessage("ECHO");
}
@Override
public void onClose(WebSocket websocket) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).build()).get();
latch.await();
assertEquals(text.get(), "ECHOECHO");
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class TextMessageTest method onTimeoutCloseTest.
@Test(groups = "standalone", timeOut = 60000)
public void onTimeoutCloseTest() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> text = new AtomicReference<>("");
c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
text.set("OnClose");
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).build()).get();
latch.await();
assertEquals(text.get(), "OnClose");
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class TextMessageTest method onClose.
@Test(groups = "standalone", timeOut = 60000)
public void onClose() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> text = new AtomicReference<>("");
WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket) {
text.set("OnClose");
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).build()).get();
websocket.close();
latch.await();
assertEquals(text.get(), "OnClose");
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class WebSocketWriteCompleteListenerTest method sendTextMessageExpectFailure.
@Test(groups = "standalone", timeOut = 60000, expectedExceptions = ExecutionException.class)
public void sendTextMessageExpectFailure() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
WebSocket websocket = getWebSocket(c);
websocket.close();
closeFuture.get();
websocket.sendMessage("TEXT", resultHandler());
resultFuture.get(10, TimeUnit.SECONDS);
}
}
use of org.asynchttpclient.AsyncHttpClient in project async-http-client by AsyncHttpClient.
the class WebSocketWriteCompleteListenerTest method streamText.
@Test(groups = "standalone")
public void streamText() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
getWebSocket(c).stream("STREAM", true, resultHandler());
resultFuture.get();
}
}
Aggregations