use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http1xTest method testAccessNetSocket.
@Test
public void testAccessNetSocket() throws Exception {
Buffer toSend = TestUtils.randomBuffer(1000);
server.requestHandler(req -> {
req.response().headers().set("HTTP/1.1", "101 Upgrade");
req.bodyHandler(data -> {
assertEquals(toSend, data);
req.response().end();
});
});
server.listen(onSuccess(s -> {
HttpClientRequest req = client.request(HttpMethod.GET, DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, DEFAULT_TEST_URI, resp -> {
resp.endHandler(v -> {
assertNotNull(resp.netSocket());
testComplete();
});
});
req.headers().set("content-length", String.valueOf(toSend.length()));
req.write(toSend);
}));
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ServerTest method testSendFile.
@Test
public void testSendFile() throws Exception {
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(1000 * 1000));
File tmp = createTempFile(expected);
testSendFile(expected, tmp.getAbsolutePath(), 0, expected.length());
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ServerTest method testSendPing.
@Test
public void testSendPing() throws Exception {
waitFor(2);
Buffer expected = TestUtils.randomBuffer(8);
Context ctx = vertx.getOrCreateContext();
server.close();
server.connectionHandler(conn -> {
conn.ping(expected, ar -> {
assertSame(ctx, Vertx.currentContext());
assertTrue(ar.succeeded());
assertEquals(expected, ar.result());
complete();
});
});
server.requestHandler(req -> fail());
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onPingRead(ChannelHandlerContext ctx, ByteBuf data) throws Http2Exception {
Buffer buffer = Buffer.buffer(data.copy());
vertx.runOnContext(v -> {
assertEquals(expected, buffer);
complete();
});
}
});
});
fut.sync();
await();
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ServerTest method testNetSocketSendFileRange.
@Test
public void testNetSocketSendFileRange() throws Exception {
Buffer expected = Buffer.buffer(TestUtils.randomAlphaString(1000 * 1000));
File tmp = createTempFile(expected);
int from = 200 * 1000;
int to = 700 * 1000;
testNetSocketSendFile(expected.slice(from, to), tmp.getAbsolutePath(), from, to - from);
}
use of io.vertx.core.buffer.Buffer in project vert.x by eclipse.
the class Http2ServerTest method testUnknownFrame.
@Test
public void testUnknownFrame() throws Exception {
Buffer expectedSend = TestUtils.randomBuffer(500);
Buffer expectedRecv = TestUtils.randomBuffer(500);
Context ctx = vertx.getOrCreateContext();
server.requestHandler(req -> {
req.customFrameHandler(frame -> {
assertOnIOContext(ctx);
assertEquals(10, frame.type());
assertEquals(253, frame.flags());
assertEquals(expectedSend, frame.payload());
req.response().writeCustomFrame(12, 134, expectedRecv).end();
});
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.decoder.frameListener(new Http2EventAdapter() {
int status = 0;
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
int s = status++;
vertx.runOnContext(v -> {
assertEquals(0, s);
});
}
@Override
public void onUnknownFrame(ChannelHandlerContext ctx, byte frameType, int streamId, Http2Flags flags, ByteBuf payload) {
int s = status++;
Buffer recv = Buffer.buffer(payload.copy());
vertx.runOnContext(v -> {
assertEquals(1, s);
assertEquals(12, frameType);
assertEquals(134, flags.value());
assertEquals(expectedRecv, recv);
});
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
int len = data.readableBytes();
int s = status++;
vertx.runOnContext(v -> {
assertEquals(2, s);
assertEquals(0, len);
assertTrue(endOfStream);
testComplete();
});
return data.readableBytes() + padding;
}
});
request.encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.encoder.writeFrame(request.context, (byte) 10, id, new Http2Flags((short) 253), expectedSend.getByteBuf(), request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
Aggregations