use of io.vertx.core.http.impl.ws.WebSocketFrameImpl 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();
}
use of io.vertx.core.http.impl.ws.WebSocketFrameImpl in project vert.x by eclipse.
the class WebSocketTest method testServerWebSocketReceivePongExceedsMaxFrameSize.
@Test
public void testServerWebSocketReceivePongExceedsMaxFrameSize() {
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 -> {
List<Buffer> pongs = new ArrayList<>();
ws.pongHandler(pong -> {
pongs.add(pong);
if (pongs.size() == 2) {
assertEquals(pongs, Arrays.asList(ping1, ping2));
testComplete();
}
});
}).listen(v -> {
client = vertx.createHttpClient();
client.webSocket(DEFAULT_HTTP_PORT, HttpTestBase.DEFAULT_HTTP_HOST, "/", onSuccess(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);
}
}));
});
await();
}
Aggregations