use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testWriteHandlerFailure.
@Test
public void testWriteHandlerFailure() {
server = vertx.createHttpServer().webSocketHandler(ServerWebSocket::pause).listen(DEFAULT_HTTP_PORT, onSuccess(v1 -> {
Buffer buffer = TestUtils.randomBuffer(1024);
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri", onSuccess(ws -> {
while (!ws.writeQueueFull()) {
ws.write(buffer);
}
ws.write(buffer, onFailure(err -> {
testComplete();
}));
((WebSocketInternal) ws).channelHandlerContext().close();
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testReportProtocolViolationOnClient.
@Test
public void testReportProtocolViolationOnClient() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).requestHandler(req -> {
getUpgradedNetSocket(req, "/some/path").onComplete(onSuccess(sock -> {
// Let's write an invalid frame
Buffer buff = Buffer.buffer();
// Violates protocol with V13 (final control frame)
buff.appendByte((byte) (0x8)).appendByte((byte) 0);
sock.write(buff);
}));
});
server.listen(onSuccess(s -> {
WebSocketConnectOptions options = new WebSocketConnectOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setURI("/some/path").setVersion(WebsocketVersion.V13);
client = vertx.createHttpClient();
client.webSocket(options, onSuccess(ws -> {
AtomicReference<Throwable> failure = new AtomicReference<>();
ws.closeHandler(v -> {
assertNotNull(failure.get());
testComplete();
});
ws.exceptionHandler(failure::set);
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class HttpRequestStreamTest method testReadStreamPauseResume.
@Test
public void testReadStreamPauseResume() {
String path = "/some/path";
this.server = vertx.createHttpServer(new HttpServerOptions().setAcceptBacklog(10).setPort(DEFAULT_HTTP_PORT));
ReadStream<HttpServerRequest> httpStream = server.requestStream();
AtomicBoolean paused = new AtomicBoolean();
httpStream.handler(req -> {
assertFalse(paused.get());
HttpServerResponse response = req.response();
response.setStatusCode(200).end();
response.close();
});
server.listen(listenAR -> {
assertTrue(listenAR.succeeded());
paused.set(true);
httpStream.pause();
netClient = vertx.createNetClient(new NetClientOptions().setConnectTimeout(1000));
netClient.connect(DEFAULT_HTTP_PORT, "localhost", socketAR -> {
assertTrue(socketAR.succeeded());
NetSocket socket = socketAR.result();
socket.write("GET / HTTP/1.1\r\n\r\n");
Buffer buffer = Buffer.buffer();
socket.handler(buffer::appendBuffer);
socket.closeHandler(v -> {
assertEquals(0, buffer.length());
paused.set(false);
httpStream.resume();
client = vertx.createHttpClient(new HttpClientOptions());
client.request(new RequestOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setURI(path)).onComplete(onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
testComplete();
}));
}));
});
});
});
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_HOST in project vert.x by eclipse.
the class WebSocketTest method testWriteFromConnectHandler.
private void testWriteFromConnectHandler(WebsocketVersion version) throws Exception {
String path = "/some/path";
Buffer buff = Buffer.buffer("AAA");
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
assertEquals(path, ws.path());
ws.writeFrame(WebSocketFrame.binaryFrame(buff, true));
});
server.listen(onSuccess(s -> {
WebSocketConnectOptions options = new WebSocketConnectOptions().setPort(DEFAULT_HTTP_PORT).setHost(DEFAULT_HTTP_HOST).setURI(path).setVersion(version);
client = vertx.createHttpClient();
client.webSocket(options, onSuccess(ws -> {
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 testPausedBeforeClosed.
@Test
public void testPausedBeforeClosed() {
waitFor(2);
Buffer expected = TestUtils.randomBuffer(128);
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.handler(buffer -> {
assertFalse(paused.get());
assertEquals(expected, buffer);
complete();
});
ws.endHandler(v -> {
assertFalse(paused.get());
complete();
});
}).listen(onSuccess(v -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/someuri", onSuccess(ws -> {
ws.write(expected);
ws.close();
}));
}));
await();
}
Aggregations