Search in sources :

Example 31 with AsciiString

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

the class MethodDescriptorBenchmark method transportSpecific.

/** Foo bar. */
@Benchmark
@BenchmarkMode(Mode.SampleTime)
@OutputTimeUnit(TimeUnit.NANOSECONDS)
public AsciiString transportSpecific() {
    AsciiString path;
    if ((path = (AsciiString) imd.geRawMethodName(method)) != null) {
        path = new AsciiString("/" + method.getFullMethodName());
        imd.setRawMethodName(method, path);
    }
    return path;
}
Also used : AsciiString(io.netty.util.AsciiString) BenchmarkMode(org.openjdk.jmh.annotations.BenchmarkMode) Benchmark(org.openjdk.jmh.annotations.Benchmark) OutputTimeUnit(org.openjdk.jmh.annotations.OutputTimeUnit)

Example 32 with AsciiString

use of io.netty.util.AsciiString in project vert.x by eclipse.

the class ConversionHelperTest method testToJsonObject.

@Test
public void testToJsonObject() {
    Map<String, Object> map = new HashMap<>();
    map.put("string", "the_string");
    map.put("integer", 4);
    map.put("boolean", true);
    map.put("charsequence", new AsciiString("the_charsequence"));
    map.put("biginteger", new BigInteger("1234567"));
    map.put("binary", Buffer.buffer("hello"));
    map.put("object", Collections.singletonMap("nested", 4));
    map.put("array", Arrays.asList(1, 2, 3));
    JsonObject json = (JsonObject) ConversionHelper.toObject(map);
    assertEquals(8, json.size());
    assertEquals("the_string", json.getString("string"));
    assertEquals(4, (int) json.getInteger("integer"));
    assertEquals(true, json.getBoolean("boolean"));
    assertEquals("the_charsequence", json.getString("charsequence"));
    assertEquals(1234567, (int) json.getInteger("biginteger"));
    assertEquals("hello", new String(json.getBinary("binary")));
    assertEquals(new JsonObject().put("nested", 4), json.getJsonObject("object"));
    assertEquals(new JsonArray().add(1).add(2).add(3), json.getJsonArray("array"));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) HashMap(java.util.HashMap) AsciiString(io.netty.util.AsciiString) BigInteger(java.math.BigInteger) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 33 with AsciiString

use of io.netty.util.AsciiString in project vert.x by eclipse.

the class ConversionHelperTest method testToJsonArray.

@Test
public void testToJsonArray() {
    List<Object> list = new ArrayList<>();
    list.add("the_string");
    list.add(4);
    list.add(true);
    list.add(new AsciiString("the_charsequence"));
    list.add(new BigInteger("1234567"));
    list.add(Buffer.buffer("hello"));
    list.add(Collections.singletonMap("nested", 4));
    list.add(Arrays.asList(1, 2, 3));
    JsonArray json = (JsonArray) ConversionHelper.toObject(list);
    assertEquals(8, json.size());
    assertEquals("the_string", json.getString(0));
    assertEquals(4, (int) json.getInteger(1));
    assertEquals(true, json.getBoolean(2));
    assertEquals("the_charsequence", json.getString(3));
    assertEquals(1234567, (int) json.getInteger(4));
    assertEquals("hello", new String(json.getBinary(5)));
    assertEquals(new JsonObject().put("nested", 4), json.getJsonObject(6));
    assertEquals(new JsonArray().add(1).add(2).add(3), json.getJsonArray(7));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) ArrayList(java.util.ArrayList) AsciiString(io.netty.util.AsciiString) BigInteger(java.math.BigInteger) JsonObject(io.vertx.core.json.JsonObject) JsonObject(io.vertx.core.json.JsonObject) AsciiString(io.netty.util.AsciiString) Test(org.junit.Test)

Example 34 with AsciiString

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

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

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