use of io.netty.buffer.ByteBuf in project grpc-java by grpc.
the class NettyClientHandlerTest method receiveMaxConcurrentStreams.
private void receiveMaxConcurrentStreams(int max) throws Exception {
ByteBuf serializedSettings = serializeSettings(new Http2Settings().maxConcurrentStreams(max));
channelRead(serializedSettings);
}
use of io.netty.buffer.ByteBuf in project grpc-java by grpc.
the class NettyClientHandlerTest method ping.
@Test
public void ping() throws Exception {
PingCallbackImpl callback1 = new PingCallbackImpl();
sendPing(callback1);
// add'l ping will be added as listener to outstanding operation
PingCallbackImpl callback2 = new PingCallbackImpl();
sendPing(callback2);
ArgumentCaptor<ByteBuf> captor = ArgumentCaptor.forClass(ByteBuf.class);
verifyWrite().writePing(eq(ctx()), eq(false), captor.capture(), any(ChannelPromise.class));
// getting a bad ack won't cause the callback to be invoked
ByteBuf pingPayload = captor.getValue();
// to compute bad payload, read the good payload and subtract one
ByteBuf badPingPayload = Unpooled.copyLong(pingPayload.slice().readLong() - 1);
channelRead(pingFrame(true, badPingPayload));
// operation not complete because ack was wrong
assertEquals(0, callback1.invocationCount);
assertEquals(0, callback2.invocationCount);
nanoTime += 10101;
// reading the proper response should complete the future
channelRead(pingFrame(true, pingPayload));
assertEquals(1, callback1.invocationCount);
assertEquals(10101, callback1.roundTripTime);
assertNull(callback1.failureCause);
// callback2 piggy-backed on same operation
assertEquals(1, callback2.invocationCount);
assertEquals(10101, callback2.roundTripTime);
assertNull(callback2.failureCause);
// now that previous ping is done, next request starts a new operation
callback1 = new PingCallbackImpl();
sendPing(callback1);
assertEquals(0, callback1.invocationCount);
}
use of io.netty.buffer.ByteBuf in project grpc-java by grpc.
the class NettyClientHandlerTest method inboundShouldForwardToStream.
@Test
public void inboundShouldForwardToStream() throws Exception {
createStream();
// Read a headers frame first.
Http2Headers headers = new DefaultHttp2Headers().status(STATUS_OK).set(CONTENT_TYPE_HEADER, CONTENT_TYPE_GRPC).set(as("magic"), as("value"));
ByteBuf headersFrame = headersFrame(3, headers);
channelRead(headersFrame);
ArgumentCaptor<Metadata> captor = ArgumentCaptor.forClass(Metadata.class);
verify(streamListener).headersRead(captor.capture());
assertEquals("value", captor.getValue().get(Metadata.Key.of("magic", Metadata.ASCII_STRING_MARSHALLER)));
streamTransportState.requestMessagesFromDeframer(1);
// Create a data frame and then trigger the handler to read it.
ByteBuf frame = grpcDataFrame(3, false, contentAsArray());
channelRead(frame);
ArgumentCaptor<InputStream> isCaptor = ArgumentCaptor.forClass(InputStream.class);
verify(streamListener).messageRead(isCaptor.capture());
assertArrayEquals(ByteBufUtil.getBytes(content()), ByteStreams.toByteArray(isCaptor.getValue()));
isCaptor.getValue().close();
}
use of io.netty.buffer.ByteBuf in project grpc-java by grpc.
the class GrpcHttp2HeadersDecoderTest method decode_emptyHeaders.
@Test
public void decode_emptyHeaders() throws Http2Exception {
Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
ByteBuf encodedHeaders = Unpooled.buffer();
encoder.encodeHeaders(1, /* randomly chosen */
new DefaultHttp2Headers(false), encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
encodedHeaders);
assertEquals(0, decodedHeaders.size());
assertThat(decodedHeaders.toString(), containsString("[]"));
}
use of io.netty.buffer.ByteBuf in project grpc-java by grpc.
the class NettyHandlerTestBase method windowShouldNotExceedMaxWindowSize.
@Test
public void windowShouldNotExceedMaxWindowSize() throws Exception {
makeStream();
AbstractNettyHandler handler = (AbstractNettyHandler) handler();
handler.setAutoTuneFlowControl(true);
Http2Stream connectionStream = connection().connectionStream();
Http2LocalFlowController localFlowController = connection().local().flowController();
int maxWindow = handler.flowControlPing().maxWindow();
handler.flowControlPing().setDataSizeSincePing(maxWindow);
int payload = handler.flowControlPing().payload();
ByteBuf buffer = handler.ctx().alloc().buffer(8);
buffer.writeLong(payload);
channelRead(pingFrame(true, buffer));
assertEquals(maxWindow, localFlowController.initialWindowSize(connectionStream));
}
Aggregations