use of io.netty.handler.codec.http2.DefaultHttp2Headers 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.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyClientHandlerTest method bdpPingAllowedAfterSendingData.
@Test
public void bdpPingAllowedAfterSendingData() throws Exception {
// gRPC servers limit PINGs based on what they _send_. Some servers limit PINGs based on what is
// _received_.
flowControlWindow = 64 * 1024;
manualSetUp();
createStream();
handler().setAutoTuneFlowControl(true);
ByteBuf content = Unpooled.buffer(64 * 1024 + 1024);
content.writerIndex(content.capacity());
ChannelFuture future = enqueue(new SendGrpcFrameCommand(streamTransportState, content, false));
// flow control limits send
assertFalse(future.isDone());
Http2Headers headers = new DefaultHttp2Headers().status(STATUS_OK).set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC);
channelRead(headersFrame(3, headers));
channelRead(dataFrame(3, false, content()));
verifyWrite().writePing(eq(ctx()), eq(false), eq(1234L), any(ChannelPromise.class));
channelRead(pingFrame(true, 1234));
channelRead(dataFrame(3, false, content()));
verifyWrite(times(2)).writePing(eq(ctx()), eq(false), eq(1234L), any(ChannelPromise.class));
channelRead(pingFrame(true, 1234));
channelRead(dataFrame(3, false, content()));
// No ping was sent
verifyWrite(times(2)).writePing(eq(ctx()), eq(false), eq(1234L), any(ChannelPromise.class));
channelRead(windowUpdate(0, 2024));
channelRead(windowUpdate(3, 2024));
assertTrue(future.isDone());
assertTrue(future.isSuccess());
// But now one is sent
channelRead(dataFrame(3, false, content()));
verifyWrite(times(3)).writePing(eq(ctx()), eq(false), eq(1234L), any(ChannelPromise.class));
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyClientHandlerTest method setUp.
/**
* Set up for test.
*/
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
StreamListener.MessageProducer producer = (StreamListener.MessageProducer) invocation.getArguments()[0];
InputStream message;
while ((message = producer.next()) != null) {
streamListenerMessageQueue.add(message);
}
return null;
}
}).when(streamListener).messagesAvailable(ArgumentMatchers.<StreamListener.MessageProducer>any());
lifecycleManager = new ClientTransportLifecycleManager(listener);
// it'll be null which will be testing if we behave correctly when it's not present.
if (setKeepaliveManagerFor.contains(testNameRule.getMethodName())) {
mockKeepAliveManager = mock(KeepAliveManager.class);
}
initChannel(new GrpcHttp2ClientHeadersDecoder(GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE));
streamTransportState = new TransportStateImpl(handler(), channel().eventLoop(), DEFAULT_MAX_MESSAGE_SIZE, transportTracer);
streamTransportState.setListener(streamListener);
grpcHeaders = new DefaultHttp2Headers().scheme(HTTPS).authority(as("www.fake.com")).path(as("/fakemethod")).method(HTTP_METHOD).add(as("auth"), as("sometoken")).add(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).add(TE_HEADER, TE_TRAILERS);
// Simulate receipt of initial remote settings.
ByteBuf serializedSettings = serializeSettings(new Http2Settings());
channelRead(serializedSettings);
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyClientHandlerTest method makeStream.
@Override
protected void makeStream() throws Exception {
createStream();
// The tests in NettyServerHandlerTest expect the header to already be read, since they work on
// both client- and server-side.
Http2Headers headers = new DefaultHttp2Headers().status(STATUS_OK).set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC);
ByteBuf headersFrame = headersFrame(3, headers);
channelRead(headersFrame);
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyServerHandlerTest method createStream.
private void createStream() throws Exception {
Http2Headers headers = new DefaultHttp2Headers().method(HTTP_METHOD).set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).set(TE_HEADER, TE_TRAILERS).path(new AsciiString("/foo/bar"));
ByteBuf headersFrame = headersFrame(STREAM_ID, headers);
channelRead(headersFrame);
ArgumentCaptor<NettyServerStream> streamCaptor = ArgumentCaptor.forClass(NettyServerStream.class);
ArgumentCaptor<String> methodCaptor = ArgumentCaptor.forClass(String.class);
verify(transportListener).streamCreated(streamCaptor.capture(), methodCaptor.capture(), any(Metadata.class));
stream = streamCaptor.getValue();
}
Aggregations