use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ClientTest method testConnectionDecodeError.
@Test
public void testConnectionDecodeError() throws Exception {
waitFor(3);
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("200"), 0, false, ctx.newPromise());
enc.frameWriter().writeRstStream(ctx, 10, 0, ctx.newPromise());
ctx.flush();
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
Context ctx = vertx.getOrCreateContext();
client.close();
ctx.runOnContext(v -> {
client = vertx.createHttpClient(createBaseClientOptions());
client.connectionHandler(conn -> {
conn.exceptionHandler(err -> {
assertSame(ctx, Vertx.currentContext());
if (err instanceof Http2Exception) {
complete();
}
});
});
client.request(new RequestOptions().setMethod(HttpMethod.PUT).setHost(DEFAULT_HTTPS_HOST).setPort(DEFAULT_HTTPS_PORT).setURI(DEFAULT_TEST_URI)).onComplete(onSuccess(req -> {
req.response(onSuccess(resp -> {
resp.exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof Http2Exception) {
complete();
}
});
})).exceptionHandler(err -> {
assertOnIOContext(ctx);
if (err instanceof Http2Exception) {
complete();
}
}).sendHead();
}));
});
await();
} finally {
s.channel().close().sync();
}
}
use of io.netty.handler.codec.http2.Http2EventAdapter in project vert.x by eclipse.
the class Http2ClientTest method testStreamPriorityChange.
@Test
public void testStreamPriorityChange() throws Exception {
StreamPriority requestStreamPriority = new StreamPriority().setDependency(123).setWeight((short) 45).setExclusive(true);
StreamPriority requestStreamPriority2 = new StreamPriority().setDependency(223).setWeight((short) 145).setExclusive(false);
StreamPriority responseStreamPriority = new StreamPriority().setDependency(153).setWeight((short) 75).setExclusive(false);
StreamPriority responseStreamPriority2 = new StreamPriority().setDependency(253).setWeight((short) 175).setExclusive(true);
waitFor(5);
ServerBootstrap bootstrap = createH2Server((decoder, encoder) -> new Http2EventAdapter() {
@Override
public void onHeadersRead(ChannelHandlerContext ctx, int streamId, Http2Headers headers, int streamDependency, short weight, boolean exclusive, int padding, boolean endStream) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(requestStreamPriority.getDependency(), streamDependency);
assertEquals(requestStreamPriority.getWeight(), weight);
assertEquals(requestStreamPriority.isExclusive(), exclusive);
assertFalse(endStream);
complete();
});
}
@Override
public void onPriorityRead(ChannelHandlerContext ctx, int streamId, int streamDependency, short weight, boolean exclusive) throws Http2Exception {
vertx.runOnContext(v -> {
assertEquals(requestStreamPriority2.getDependency(), streamDependency);
assertEquals(requestStreamPriority2.getWeight(), weight);
assertEquals(requestStreamPriority2.isExclusive(), exclusive);
complete();
});
}
@Override
public int onDataRead(ChannelHandlerContext ctx, int streamId, ByteBuf data, int padding, boolean endOfStream) throws Http2Exception {
if (endOfStream) {
encoder.writeHeaders(ctx, streamId, new DefaultHttp2Headers().status("200"), responseStreamPriority.getDependency(), responseStreamPriority.getWeight(), responseStreamPriority.isExclusive(), 0, false, ctx.newPromise());
ctx.flush();
encoder.writePriority(ctx, streamId, responseStreamPriority2.getDependency(), responseStreamPriority2.getWeight(), responseStreamPriority2.isExclusive(), ctx.newPromise());
ctx.flush();
encoder.writeData(ctx, streamId, Buffer.buffer("hello").getByteBuf(), 0, true, ctx.newPromise());
ctx.flush();
vertx.runOnContext(v -> {
complete();
});
}
return super.onDataRead(ctx, streamId, data, padding, endOfStream);
}
});
ChannelFuture s = bootstrap.bind(DEFAULT_HTTPS_HOST, DEFAULT_HTTPS_PORT).sync();
try {
client.request(new RequestOptions().setPort(DEFAULT_HTTPS_PORT).setHost(DEFAULT_HTTPS_HOST).setURI("/somepath")).onComplete(onSuccess(req -> {
req.response(onSuccess(resp -> {
assertEquals(responseStreamPriority, resp.request().getStreamPriority());
Context ctx = vertx.getOrCreateContext();
assertOnIOContext(ctx);
resp.streamPriorityHandler(streamPriority -> {
assertOnIOContext(ctx);
assertEquals(responseStreamPriority2, streamPriority);
assertEquals(responseStreamPriority2, resp.request().getStreamPriority());
complete();
});
resp.endHandler(v -> {
assertOnIOContext(ctx);
assertEquals(responseStreamPriority2, resp.request().getStreamPriority());
complete();
});
})).setStreamPriority(requestStreamPriority);
req.sendHead(h -> {
req.setStreamPriority(requestStreamPriority2);
req.end();
});
}));
await();
} finally {
s.channel().close().sync();
}
}
Aggregations