use of io.netty.channel.ChannelHandlerContext in project vert.x by eclipse.
the class Http2ClientTest method testInvalidServerResponse.
@Test
public void testInvalidServerResponse() throws Exception {
ServerBootstrap bootstrap = createH2Server((dec, enc) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
enc.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("xyz"), 0, false, ctx.newPromise());
ctx.flush();
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
Context ctx = vertx.getOrCreateContext();
ctx.runOnContext(v -> {
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
fail();
}).connectionHandler(conn -> {
conn.exceptionHandler(err -> {
fail();
});
}).exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof NumberFormatException) {
testComplete();
}
}).end();
});
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.channel.ChannelHandlerContext in project vert.x by eclipse.
the class Http2ClientTest method testConnectionWindowSize.
@Test
public void testConnectionWindowSize() throws Exception {
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(65535, windowSizeIncrement);
testComplete();
});
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
client.close();
client = vertx.createHttpClient(new HttpClientOptions(clientOptions).setHttp2ConnectionWindowSize(65535 * 2));
client.get(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, "/somepath", resp -> {
}).exceptionHandler(this::fail).end();
await();
}
use of io.netty.channel.ChannelHandlerContext in project vert.x by eclipse.
the class Http2ServerTest method testUpdateConnectionWindowSize.
@Test
public void testUpdateConnectionWindowSize() throws Exception {
server.connectionHandler(conn -> {
assertEquals(65535, conn.getWindowSize());
conn.setWindowSize(65535 + 10000);
assertEquals(65535 + 10000, conn.getWindowSize());
conn.setWindowSize(65535 + 65535);
assertEquals(65535 + 65535, conn.getWindowSize());
}).requestHandler(req -> {
req.response().end();
});
startServer();
TestClient client = new TestClient();
ChannelFuture fut = client.connect(DEFAULT_HTTPS_PORT, DEFAULT_HTTPS_HOST, request -> {
request.decoder.frameListener(new Http2EventAdapter() {
@Override
public void onWindowUpdateRead(ChannelHandlerContext ctx, int streamId, int windowSizeIncrement) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(65535, windowSizeIncrement);
testComplete();
});
}
});
});
fut.sync();
await();
}
use of io.netty.channel.ChannelHandlerContext 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.ChannelHandlerContext 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