use of io.vertx.core.net.impl.NetSocketInternal in project vert.x by eclipse.
the class NetTest method testNetSocketInternalBuffer.
@Test
public void testNetSocketInternalBuffer() throws Exception {
server.connectHandler(so -> {
NetSocketInternal soi = (NetSocketInternal) so;
soi.handler(msg -> {
ByteBuf byteBuf = msg.getByteBuf();
assertFalse(byteBuf.isDirect());
assertEquals(1, byteBuf.refCnt());
assertFalse(byteBuf.release());
assertEquals(1, byteBuf.refCnt());
soi.write(msg);
});
});
startServer();
client.connect(testAddress, onSuccess(so -> {
NetSocketInternal soi = (NetSocketInternal) so;
soi.write(Buffer.buffer("Hello World"));
soi.handler(msg -> {
ByteBuf byteBuf = msg.getByteBuf();
assertFalse(byteBuf.isDirect());
assertEquals(1, byteBuf.refCnt());
assertFalse(byteBuf.release());
assertEquals(1, byteBuf.refCnt());
assertEquals("Hello World", msg.toString());
testComplete();
});
}));
await();
}
use of io.vertx.core.net.impl.NetSocketInternal in project vert.x by eclipse.
the class NetTest method testNetSocketInternalDirectBuffer.
@Test
public void testNetSocketInternalDirectBuffer() throws Exception {
waitFor(2);
server.connectHandler(so -> {
NetSocketInternal soi = (NetSocketInternal) so;
soi.messageHandler(msg -> {
ByteBuf byteBuf = (ByteBuf) msg;
assertTrue(byteBuf.isDirect());
assertEquals(1, byteBuf.refCnt());
soi.writeMessage(msg).onSuccess(v -> {
assertEquals(0, byteBuf.refCnt());
complete();
});
});
});
startServer();
client.connect(testAddress, onSuccess(so -> {
NetSocketInternal soi = (NetSocketInternal) so;
soi.write(Buffer.buffer("Hello World"));
// soi.messageHandler(msg -> fail("Unexpected"));
soi.messageHandler(msg -> {
ByteBuf byteBuf = (ByteBuf) msg;
assertTrue(byteBuf.isDirect());
assertEquals(1, byteBuf.refCnt());
assertEquals("Hello World", byteBuf.toString(StandardCharsets.UTF_8));
assertTrue(byteBuf.release());
assertEquals(0, byteBuf.refCnt());
complete();
});
}));
await();
}
use of io.vertx.core.net.impl.NetSocketInternal in project vert.x by eclipse.
the class NetTest method testNetClientInternal_.
private void testNetClientInternal_(HttpServerOptions options, boolean expectSSL) throws Exception {
waitFor(2);
HttpServer server = vertx.createHttpServer(options);
server.requestHandler(req -> {
req.response().end("Hello World");
});
CountDownLatch latch = new CountDownLatch(1);
server.listen(onSuccess(v -> {
latch.countDown();
}));
awaitLatch(latch);
client.connect(1234, "localhost", onSuccess(so -> {
NetSocketInternal soInt = (NetSocketInternal) so;
assertEquals(expectSSL, soInt.isSsl());
ChannelHandlerContext chctx = soInt.channelHandlerContext();
ChannelPipeline pipeline = chctx.pipeline();
pipeline.addBefore("handler", "http", new HttpClientCodec());
AtomicInteger status = new AtomicInteger();
soInt.handler(buff -> fail());
soInt.messageHandler(obj -> {
switch(status.getAndIncrement()) {
case 0:
assertTrue(obj instanceof HttpResponse);
HttpResponse resp = (HttpResponse) obj;
assertEquals(200, resp.status().code());
break;
case 1:
assertTrue(obj instanceof LastHttpContent);
ByteBuf content = ((LastHttpContent) obj).content();
assertEquals(!expectSSL, content.isDirect());
assertEquals(1, content.refCnt());
String val = content.toString(StandardCharsets.UTF_8);
assertTrue(content.release());
assertEquals("Hello World", val);
complete();
break;
default:
fail();
}
});
soInt.writeMessage(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/somepath"), onSuccess(v -> complete()));
}));
await();
}
use of io.vertx.core.net.impl.NetSocketInternal in project vert.x by eclipse.
the class NetTest method testNetServerInternal_.
private void testNetServerInternal_(HttpClientOptions clientOptions, boolean expectSSL) throws Exception {
waitFor(2);
server.connectHandler(so -> {
NetSocketInternal internal = (NetSocketInternal) so;
assertEquals(expectSSL, internal.isSsl());
ChannelHandlerContext chctx = internal.channelHandlerContext();
ChannelPipeline pipeline = chctx.pipeline();
pipeline.addBefore("handler", "http", new HttpServerCodec());
internal.handler(buff -> fail());
internal.messageHandler(obj -> {
if (obj instanceof LastHttpContent) {
DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.copiedBuffer("Hello World", StandardCharsets.UTF_8));
response.headers().set(HttpHeaderNames.CONTENT_LENGTH, "11");
internal.writeMessage(response, onSuccess(v -> complete()));
}
});
});
startServer(SocketAddress.inetSocketAddress(1234, "localhost"));
HttpClient client = vertx.createHttpClient(clientOptions);
client.request(io.vertx.core.http.HttpMethod.GET, 1234, "localhost", "/somepath", onSuccess(req -> {
req.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
resp.body(onSuccess(body -> {
assertEquals("Hello World", body.toString());
complete();
}));
}));
}));
await();
}
Aggregations