use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testPausedDuringClose.
@Test
public void testPausedDuringClose() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
AtomicBoolean paused = new AtomicBoolean(true);
ws.pause();
ws.closeHandler(v1 -> {
paused.set(false);
vertx.runOnContext(v2 -> {
ws.resume();
});
});
ws.endHandler(v -> {
assertFalse(paused.get());
testComplete();
});
}).listen(onSuccess(v -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri", onSuccess(ws -> {
ws.close();
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testNormalWSDeflateFrameCompressionNegotiation.
@Test
public // Test normal negotiation of WebSocket compression
void testNormalWSDeflateFrameCompressionNegotiation() throws Exception {
String path = "/some/path";
Buffer buff = Buffer.buffer("AAA");
// Server should have basic compression enabled by default,
// client needs to ask for it
server = vertx.createHttpServer(new HttpServerOptions().setPort(HttpTestBase.DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
assertEquals("upgrade", ws.headers().get("Connection"));
assertEquals("deflate-frame", ws.headers().get("sec-websocket-extensions"));
ws.writeFrame(WebSocketFrame.binaryFrame(buff, true));
});
server.listen(ar -> {
assertTrue(ar.succeeded());
HttpClientOptions options = new HttpClientOptions();
options.setTryUsePerFrameWebSocketCompression(true);
client = vertx.createHttpClient(options);
client.webSocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, path, onSuccess(ws -> {
final Buffer received = Buffer.buffer();
ws.handler(data -> {
received.appendBuffer(data);
if (received.length() == buff.length()) {
assertEquals(buff, received);
ws.close();
testComplete();
}
});
}));
});
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testWriteMessage.
private void testWriteMessage(int size, WebsocketVersion version) {
client = vertx.createHttpClient();
waitFor(2);
String path = "/some/path";
byte[] expected = TestUtils.randomByteArray(size);
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
AtomicInteger count = new AtomicInteger();
ws.writeBinaryMessage(Buffer.buffer(expected), onSuccess(v -> {
assertEquals(1, count.incrementAndGet());
complete();
}));
ws.close();
});
server.listen(onSuccess(s -> {
WebSocketConnectOptions options = new WebSocketConnectOptions().setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT).setURI(path).setVersion(version);
client.webSocket(options, onSuccess(ws -> {
Buffer actual = Buffer.buffer();
ws.handler(actual::appendBuffer);
ws.closeHandler(v -> {
assertArrayEquals(expected, actual.getBytes(0, actual.length()));
complete();
});
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testNoRequestHandler.
@Test
public void testNoRequestHandler() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
vertx.createHttpServer().webSocketHandler(ws -> fail()).listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(v -> latch.countDown()));
awaitLatch(latch);
client = vertx.createHttpClient();
client.request(new RequestOptions().setHost(DEFAULT_HTTP_HOST).setPort(DEFAULT_HTTP_PORT)).onComplete(onSuccess(req -> {
req.send(onSuccess(resp -> {
resp.endHandler(v -> {
assertEquals(400, resp.statusCode());
testComplete();
});
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testWSWriteStream.
private void testWSWriteStream(WebsocketVersion version) throws Exception {
String host = DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT;
String scheme = "http";
String path = "/some/path";
String query = "handshake=bar&wibble=eek";
String uri = path + "?" + query;
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
assertEquals(host, ws.host());
assertEquals(scheme, ws.scheme());
assertEquals(uri, ws.uri());
assertEquals(path, ws.path());
assertEquals(query, ws.query());
assertEquals("upgrade", ws.headers().get("Connection"));
ws.handler(data -> {
ws.write(data);
});
});
server.listen(onSuccess(s -> {
int bsize = 100;
int sends = 10;
WebSocketConnectOptions options = new WebSocketConnectOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setURI(path + "?" + query).setVersion(version);
client = vertx.createHttpClient();
client.webSocket(options, onSuccess(ws -> {
final Buffer received = Buffer.buffer();
ws.handler(data -> {
received.appendBuffer(data);
if (received.length() == bsize * sends) {
ws.close();
testComplete();
}
});
final Buffer sent = Buffer.buffer();
for (int i = 0; i < sends; i++) {
Buffer buff = Buffer.buffer(TestUtils.randomByteArray(bsize));
ws.write(buff);
sent.appendBuffer(buff);
}
}));
}));
await();
}
Aggregations