use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT in project vert.x by eclipse.
the class WebSocketTest method testServerWebSocketShouldBeClosedWhenTheClosedHandlerIsCalled.
@Test
public void testServerWebSocketShouldBeClosedWhenTheClosedHandlerIsCalled() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
CheckingSender sender = new CheckingSender(vertx.getOrCreateContext(), ws);
sender.send();
ws.closeHandler(v -> {
Throwable failure = sender.close();
if (failure != null) {
fail(failure);
} else {
testComplete();
}
});
});
server.listen(onSuccess(s -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/someuri", onSuccess(ws -> {
vertx.setTimer(1000, id -> {
ws.close();
});
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT in project vert.x by eclipse.
the class HAProxyTest method testHttpWithoutHAProxySupport.
@Test
public void testHttpWithoutHAProxySupport() {
Vertx vertx = Vertx.vertx();
try {
vertx.createHttpServer(new HttpServerOptions().setUseProxyProtocol(true)).requestHandler(req -> {
req.response().end("hello");
}).listen(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, onSuccess(s -> {
HttpClient client = vertx.createHttpClient();
client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/", onSuccess(req -> {
req.send(onSuccess(resp -> {
resp.body(onSuccess(body -> {
assertEquals("hello", body.toString());
testComplete();
}));
}));
}));
}));
await();
} finally {
vertx.close();
}
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT 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_PORT 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_PORT in project vert.x by eclipse.
the class WebSocketTest method testClientWebSocketReceivePongExceedsMaxFrameSize.
@Test
public void testClientWebSocketReceivePongExceedsMaxFrameSize() {
String pingBody = randomAlphaString(113);
Integer maxFrameSize = 64;
Buffer ping1 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(0, maxFrameSize));
Buffer ping2 = Buffer.buffer(Buffer.buffer(pingBody.getBytes()).getBytes(maxFrameSize, pingBody.length()));
server = vertx.createHttpServer(new HttpServerOptions().setIdleTimeout(1).setPort(DEFAULT_HTTP_PORT).setHost(HttpTestBase.DEFAULT_HTTP_HOST).setMaxWebSocketFrameSize(maxFrameSize));
server.webSocketHandler(ws -> {
try {
ws.writeFrame(new WebSocketFrameImpl(WebSocketFrameType.PONG, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(WebSocketFrameType.PONG, ping2.copy().getByteBuf(), true));
} catch (Throwable t) {
fail(t);
}
}).listen(onSuccess(s -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", onSuccess(ws -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
}));
}));
await();
}
Aggregations