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;
}
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"));
}
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));
}
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);
}
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();
}
Aggregations