use of io.netty.handler.codec.http2.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyServerStreamTest method closeWithErrorBeforeClientHalfCloseShouldSucceed.
@Test
public void closeWithErrorBeforeClientHalfCloseShouldSucceed() throws Exception {
ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(new AsciiString("200")).set(new AsciiString("content-type"), new AsciiString("application/grpc")).set(new AsciiString("grpc-status"), new AsciiString("1")));
// Error is sent on wire and ends the stream
stream().close(Status.CANCELLED, trailers);
ArgumentCaptor<SendResponseHeadersCommand> sendHeadersCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
verify(writeQueue).enqueue(sendHeadersCap.capture(), eq(true));
SendResponseHeadersCommand sendHeaders = sendHeadersCap.getValue();
assertThat(sendHeaders.stream()).isSameAs(stream.transportState());
assertThat(ImmutableListMultimap.copyOf(sendHeaders.headers())).containsExactlyEntriesIn(expectedHeaders);
assertThat(sendHeaders.endOfStream()).isTrue();
verifyZeroInteractions(serverListener);
// Sending complete. Listener gets closed()
stream().transportState().complete();
verify(serverListener).closed(Status.OK);
verifyZeroInteractions(serverListener);
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyServerStreamTest method writeMessageShouldSendResponse.
@Test
public void writeMessageShouldSendResponse() throws Exception {
ListMultimap<CharSequence, CharSequence> expectedHeaders = ImmutableListMultimap.copyOf(new DefaultHttp2Headers().status(Utils.STATUS_OK).set(Utils.CONTENT_TYPE_HEADER, Utils.CONTENT_TYPE_GRPC));
stream.writeHeaders(new Metadata());
ArgumentCaptor<SendResponseHeadersCommand> sendHeadersCap = ArgumentCaptor.forClass(SendResponseHeadersCommand.class);
verify(writeQueue).enqueue(sendHeadersCap.capture(), eq(true));
SendResponseHeadersCommand sendHeaders = sendHeadersCap.getValue();
assertThat(sendHeaders.stream()).isSameAs(stream.transportState());
assertThat(ImmutableListMultimap.copyOf(sendHeaders.headers())).containsExactlyEntriesIn(expectedHeaders);
assertThat(sendHeaders.endOfStream()).isFalse();
byte[] msg = smallMessage();
stream.writeMessage(new ByteArrayInputStream(msg));
stream.flush();
verify(writeQueue).enqueue(eq(new SendGrpcFrameCommand(stream.transportState(), messageFrame(MESSAGE), false)), isA(ChannelPromise.class), eq(true));
}
use of io.netty.handler.codec.http2.DefaultHttp2Headers in project grpc-java by grpc.
the class NettyServerHandlerTest method headersSupportExtensionContentType.
@Test
public void headersSupportExtensionContentType() throws Exception {
Http2Headers headers = new DefaultHttp2Headers().method(HTTP_METHOD).set(CONTENT_TYPE_HEADER, new AsciiString("application/grpc+json", UTF_8)).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();
}
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();
}
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);
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(), DEFAULT_MAX_MESSAGE_SIZE);
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);
}
Aggregations