use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT 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();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT in project vert.x by eclipse.
the class JsonTest method testHttp.
@Test
public void testHttp() {
Vertx vertx = Vertx.vertx();
try {
vertx.createHttpServer().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, "/").compose(req -> req.send().compose(HttpClientResponse::body)).onComplete(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 testNormalWSPermessageDeflateCompressionNegotiation.
@Test
public // Test normal negotiation of WebSocket compression
void testNormalWSPermessageDeflateCompressionNegotiation() 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(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
assertEquals("upgrade", ws.headers().get("Connection"));
assertEquals("permessage-deflate;client_max_window_bits", ws.headers().get("sec-websocket-extensions"));
ws.writeFrame(WebSocketFrame.binaryFrame(buff, true));
});
server.listen(ar -> {
assertTrue(ar.succeeded());
HttpClientOptions options = new HttpClientOptions();
options.setTryUsePerMessageWebSocketCompression(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_PORT in project vert.x by eclipse.
the class WebSocketTest method testClientWebSocketShouldBeClosedWhenTheClosedHandlerIsCalled.
@Test
public void testClientWebSocketShouldBeClosedWhenTheClosedHandlerIsCalled() {
server = vertx.createHttpServer(new HttpServerOptions().setPort(DEFAULT_HTTP_PORT)).webSocketHandler(ws -> {
vertx.setTimer(1000, id -> {
ws.close();
});
});
server.listen(onSuccess(s -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/someuri", onSuccess(ws -> {
CheckingSender sender = new CheckingSender(vertx.getOrCreateContext(), ws);
sender.send();
ws.closeHandler(v -> {
Throwable failure = sender.close();
if (failure != null) {
fail(failure);
} else {
testComplete();
}
});
}));
}));
await();
}
use of io.vertx.core.http.HttpTestBase.DEFAULT_HTTP_PORT in project vert.x by eclipse.
the class WebSocketTest method testClientWebSocketReceivePingExceedsMaxFrameSize.
@Test
public void testClientWebSocketReceivePingExceedsMaxFrameSize() {
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 -> {
}).listen(onSuccess(v -> {
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();
}
});
try {
ws.writeFrame(new WebSocketFrameImpl(WebSocketFrameType.PING, ping1.copy().getByteBuf(), false));
ws.writeFrame(new WebSocketFrameImpl(WebSocketFrameType.PING, ping2.copy().getByteBuf(), true));
} catch (Throwable t) {
fail(t);
}
}));
}));
await();
}
Aggregations