Search in sources :

Example 31 with DefaultHttp2Headers

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);
}
Also used : DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 32 with DefaultHttp2Headers

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));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) Metadata(io.grpc.Metadata) ChannelPromise(io.netty.channel.ChannelPromise) Test(org.junit.Test)

Example 33 with DefaultHttp2Headers

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();
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Metadata(io.grpc.Metadata) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 34 with DefaultHttp2Headers

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();
}
Also used : Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Metadata(io.grpc.Metadata) AsciiString(io.netty.util.AsciiString) ByteBuf(io.netty.buffer.ByteBuf)

Example 35 with DefaultHttp2Headers

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);
}
Also used : DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) GrpcHttp2ClientHeadersDecoder(io.grpc.netty.GrpcHttp2HeadersDecoder.GrpcHttp2ClientHeadersDecoder) Http2Settings(io.netty.handler.codec.http2.Http2Settings) KeepAliveManager(io.grpc.internal.KeepAliveManager) ByteBuf(io.netty.buffer.ByteBuf) Before(org.junit.Before)

Aggregations

Test (org.junit.Test)36 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)32 AsciiString (io.netty.util.AsciiString)32 ByteBuf (io.netty.buffer.ByteBuf)23 Http2Headers (io.netty.handler.codec.http2.Http2Headers)23 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)17 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)12 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)11 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 Metadata (io.grpc.Metadata)7 ChannelFuture (io.netty.channel.ChannelFuture)7 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)5 Channel (io.netty.channel.Channel)5 Http2Settings (io.netty.handler.codec.http2.Http2Settings)5 ChannelInitializer (io.netty.channel.ChannelInitializer)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 EventLoopGroup (io.netty.channel.EventLoopGroup)4