use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testHandlerFailure.
private void testHandlerFailure(boolean data, BiConsumer<RuntimeException, HttpServer> configurator) throws Exception {
RuntimeException failure = new RuntimeException();
io.vertx.core.http.Http2Settings settings = TestUtils.randomHttp2Settings();
server.close();
server = vertx.createHttpServer(serverOptions.setInitialSettings(settings));
configurator.accept(failure, server);
Context ctx = vertx.getOrCreateContext();
ctx.exceptionHandler(err -> {
assertSame(err, failure);
testComplete();
});
startServer(ctx);
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, !data, request.context.newPromise());
if (data) {
request.encoder.writeData(request.context, id, Buffer.buffer("hello").getByteBuf(), 0, true, request.context.newPromise());
}
});
fut.sync();
await();
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testShutdownOverride.
@Test
public void testShutdownOverride() throws Exception {
AtomicLong shutdown = new AtomicLong();
Handler<HttpServerRequest> requestHandler = req -> {
HttpConnection conn = req.connection();
shutdown.set(System.currentTimeMillis());
conn.shutdown(10000);
vertx.setTimer(300, v -> {
conn.shutdown(300);
});
};
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.channel.closeFuture().addListener(v1 -> {
vertx.runOnContext(v2 -> {
assertTrue(shutdown.get() - System.currentTimeMillis() < 1200);
testComplete();
});
});
Http2ConnectionEncoder encoder = request.encoder;
int id = request.nextStreamId();
encoder.writeHeaders(request.context, id, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testServerSendGoAway.
private void testServerSendGoAway(Handler<HttpServerRequest> requestHandler, int expectedError) throws Exception {
server.requestHandler(requestHandler);
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(expectedError, errorCode);
complete();
});
}
});
Http2ConnectionEncoder encoder = request.encoder;
int id1 = request.nextStreamId();
encoder.writeHeaders(request.context, id1, GET("/"), 0, true, request.context.newPromise());
int id2 = request.nextStreamId();
encoder.writeHeaders(request.context, id2, GET("/"), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testInvalidPostFileUpload.
@Test
public void testInvalidPostFileUpload() throws Exception {
server.requestHandler(req -> {
req.setExpectMultipart(true);
AtomicInteger errCount = new AtomicInteger();
req.exceptionHandler(err -> {
errCount.incrementAndGet();
});
req.endHandler(v -> {
assertTrue(errCount.get() > 0);
testComplete();
});
});
startServer();
String contentType = "multipart/form-data; boundary=a4e41223-a527-49b6-ac1c-315d76be757e";
String contentLength = "225";
String body = "--a4e41223-a527-49b6-ac1c-315d76be757e\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"tmp-0.txt\"\r\n" + "Content-Type: image/gif; charset=ABCD\r\n" + "Content-Length: 12\r\n" + "\r\n" + "some-content\r\n" + "--a4e41223-a527-49b6-ac1c-315d76be757e--\r\n";
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, POST("/form").set("content-type", contentType).set("content-length", contentLength), 0, false, request.context.newPromise());
request.encoder.writeData(request.context, id, Buffer.buffer(body).getByteBuf(), 0, true, request.context.newPromise());
request.context.flush();
});
fut.sync();
await();
}
use of io.netty.channel.ChannelFuture in project vert.x by eclipse.
the class Http2ServerTest method testServerSettings.
@Test
public void testServerSettings() throws Exception {
waitFor(2);
io.vertx.core.http.Http2Settings expectedSettings = TestUtils.randomHttp2Settings();
expectedSettings.setHeaderTableSize((int) io.vertx.core.http.Http2Settings.DEFAULT_HEADER_TABLE_SIZE);
server.close();
server = vertx.createHttpServer(serverOptions);
Context otherContext = vertx.getOrCreateContext();
server.connectionHandler(conn -> {
otherContext.runOnContext(v -> {
conn.updateSettings(expectedSettings, ar -> {
assertSame(otherContext, Vertx.currentContext());
io.vertx.core.http.Http2Settings ackedSettings = conn.settings();
assertEquals(expectedSettings.getMaxHeaderListSize(), ackedSettings.getMaxHeaderListSize());
assertEquals(expectedSettings.getMaxFrameSize(), ackedSettings.getMaxFrameSize());
assertEquals(expectedSettings.getInitialWindowSize(), ackedSettings.getInitialWindowSize());
assertEquals(expectedSettings.getMaxConcurrentStreams(), ackedSettings.getMaxConcurrentStreams());
assertEquals(expectedSettings.getHeaderTableSize(), ackedSettings.getHeaderTableSize());
assertEquals(expectedSettings.get(''), ackedSettings.get(7));
complete();
});
});
});
server.requestHandler(req -> {
fail();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2FrameAdapter() {
AtomicInteger count = new AtomicInteger();
@Override
public void onSettingsRead(ChannelHandlerContext ctx, Http2Settings newSettings) throws Http2Exception {
vertx.runOnContext(v -> {
switch(count.getAndIncrement()) {
case 0:
break;
case 1:
assertEquals((Long) expectedSettings.getMaxHeaderListSize(), newSettings.maxHeaderListSize());
assertEquals((Integer) expectedSettings.getMaxFrameSize(), newSettings.maxFrameSize());
assertEquals((Integer) expectedSettings.getInitialWindowSize(), newSettings.initialWindowSize());
assertEquals((Long) expectedSettings.getMaxConcurrentStreams(), newSettings.maxConcurrentStreams());
assertEquals(null, newSettings.headerTableSize());
complete();
break;
default:
fail();
}
});
}
});
});
fut.sync();
await();
}
Aggregations