Search in sources :

Example 36 with AsciiString

use of io.netty.util.AsciiString 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 37 with AsciiString

use of io.netty.util.AsciiString in project grpc-java by grpc.

the class NettyClientStreamTest method invalidInboundHeadersCancelStream.

@Test
public void invalidInboundHeadersCancelStream() throws Exception {
    stream().transportState().setId(STREAM_ID);
    Http2Headers headers = grpcResponseHeaders();
    headers.set("random", "4");
    headers.remove(CONTENT_TYPE_HEADER);
    // Remove once b/16290036 is fixed.
    headers.status(new AsciiString("500"));
    stream().transportState().transportHeadersReceived(headers, false);
    verify(listener, never()).closed(any(Status.class), any(Metadata.class));
    // We are now waiting for 100 bytes of error context on the stream, cancel has not yet been
    // sent
    verify(channel, never()).writeAndFlush(any(CancelClientStreamCommand.class));
    stream().transportState().transportDataReceived(Unpooled.buffer(100).writeZero(100), false);
    verify(channel, never()).writeAndFlush(any(CancelClientStreamCommand.class));
    stream().transportState().transportDataReceived(Unpooled.buffer(1000).writeZero(1000), false);
    // Now verify that cancel is sent and an error is reported to the listener
    verify(writeQueue).enqueue(any(CancelClientStreamCommand.class), eq(true));
    ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
    ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
    verify(listener).closed(captor.capture(), metadataCaptor.capture());
    assertEquals(Status.UNKNOWN.getCode(), captor.getValue().getCode());
    assertEquals("4", metadataCaptor.getValue().get(Metadata.Key.of("random", Metadata.ASCII_STRING_MARSHALLER)));
}
Also used : Status(io.grpc.Status) Http2Headers(io.netty.handler.codec.http2.Http2Headers) DefaultHttp2Headers(io.netty.handler.codec.http2.DefaultHttp2Headers) AsciiString(io.netty.util.AsciiString) Metadata(io.grpc.Metadata) Test(org.junit.Test)

Example 38 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class DefaultHttpHeadersTest method testAsciiStringKeyRetrievedAsString.

@Test
public void testAsciiStringKeyRetrievedAsString() {
    final HttpHeaders headers = new DefaultHttpHeaders(false);
    // Test adding AsciiString key and retrieving it using a String key
    final String cacheControl = "no-cache";
    headers.add(HttpHeaderNames.CACHE_CONTROL, cacheControl);
    final String value = headers.getAsString(HttpHeaderNames.CACHE_CONTROL);
    assertNotNull(value);
    assertEquals(cacheControl, value);
    final String value2 = headers.getAsString(HttpHeaderNames.CACHE_CONTROL.toString());
    assertNotNull(value2);
    assertEquals(cacheControl, value2);
}
Also used : AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 39 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class DefaultHttpHeadersTest method testStringKeyRetrievedAsAsciiString.

@Test
public void testStringKeyRetrievedAsAsciiString() {
    final HttpHeaders headers = new DefaultHttpHeaders(false);
    // Test adding String key and retrieving it using a AsciiString key
    final String connection = "keep-alive";
    headers.add(of("Connection"), connection);
    // Passes
    final String value = headers.getAsString(HttpHeaderNames.CONNECTION.toString());
    assertNotNull(value);
    assertEquals(connection, value);
    // Passes
    final String value2 = headers.getAsString(HttpHeaderNames.CONNECTION);
    assertNotNull(value2);
    assertEquals(connection, value2);
}
Also used : AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 40 with AsciiString

use of io.netty.util.AsciiString in project netty by netty.

the class StompHeadersTest method testHeadersCaseSensitive.

@Test
public void testHeadersCaseSensitive() {
    DefaultStompHeaders headers = new DefaultStompHeaders();
    AsciiString foo = new AsciiString("foo");
    AsciiString value = new AsciiString("value");
    headers.add(foo, value);
    assertNull(headers.get("Foo"));
    assertEquals(value, headers.get(foo));
    assertEquals(value, headers.get(foo.toString()));
}
Also used : AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Aggregations

AsciiString (io.netty.util.AsciiString)73 Test (org.junit.Test)43 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)27 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)26 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)25 ByteBuf (io.netty.buffer.ByteBuf)18 ChannelPromise (io.netty.channel.ChannelPromise)15 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)12 Http2CodecUtil.getEmbeddedHttp2Exception (io.netty.handler.codec.http2.Http2CodecUtil.getEmbeddedHttp2Exception)12 Http2Runnable (io.netty.handler.codec.http2.Http2TestUtil.Http2Runnable)12 FullHttpMessage (io.netty.handler.codec.http.FullHttpMessage)11 Http2Headers (io.netty.handler.codec.http2.Http2Headers)9 Metadata (io.grpc.Metadata)8 ChannelFuture (io.netty.channel.ChannelFuture)4 Status (io.grpc.Status)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 Setup (org.openjdk.jmh.annotations.Setup)3 DefaultHttpRequest (io.netty.handler.codec.http.DefaultHttpRequest)2