use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testNetSocketHandleReset.
@Test
public void testNetSocketHandleReset() throws Exception {
server.requestHandler(req -> {
NetSocket socket = req.netSocket();
AtomicInteger status = new AtomicInteger();
socket.exceptionHandler(err -> {
assertTrue(err instanceof StreamResetException);
StreamResetException ex = (StreamResetException) err;
assertEquals(0, ex.getCode());
assertEquals(0, status.getAndIncrement());
});
socket.endHandler(v -> {
fail();
});
socket.closeHandler(v -> {
assertEquals(1, status.getAndIncrement());
testComplete();
});
});
startServer();
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 count = 0;
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
int c = count++;
vertx.runOnContext(v -> {
assertEquals(0, c);
});
request.encoder.writeRstStream(ctx, streamId, 0, ctx.newPromise());
request.context.flush();
}
});
request.encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testServerResetClientStream.
@Test
public void testServerResetClientStream() throws Exception {
server.requestHandler(req -> {
req.handler(buf -> {
req.response().reset(8);
});
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onRstStreamRead(ChannelHandlerContext ctx, int streamId, long errorCode) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(8, errorCode);
testComplete();
});
}
});
Http2ConnectionEncoder encoder = request.encoder;
encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
encoder.writeData(request.context, id, Buffer.buffer("hello").getByteBuf(), 0, false, request.context.newPromise());
});
fut.sync();
await();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture 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 org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testConnectionDecodeError.
@Test
public void testConnectionDecodeError() throws Exception {
Context ctx = vertx.getOrCreateContext();
waitFor(6);
Future<Void> when = Future.future();
server.requestHandler(req -> {
req.exceptionHandler(err -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
req.response().exceptionHandler(err -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
req.response().closeHandler(v -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
req.response().endHandler(v -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
req.connection().exceptionHandler(err -> {
assertSame(ctx, Vertx.currentContext());
complete();
});
when.complete();
});
startServer(ctx);
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
Http2ConnectionEncoder encoder = request.encoder;
when.setHandler(ar -> {
encoder.frameWriter().writeRstStream(request.context, 10, 0, request.context.newPromise());
request.context.flush();
});
encoder.writeHeaders(request.context, id, GET("/"), 0, false, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of org.apache.flink.shaded.netty4.io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testStatusMessage.
@Test
public void testStatusMessage() throws Exception {
server.requestHandler(req -> {
HttpServerResponse resp = req.response();
resp.setStatusCode(404);
assertEquals("Not Found", resp.getStatusMessage());
resp.setStatusMessage("whatever");
assertEquals("whatever", resp.getStatusMessage());
testComplete();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
int id = request.nextStreamId();
request.encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
Aggregations