use of io.grpc.Decompressor in project grpc-java by grpc.
the class ForwardingClientStreamTest method setDecompressorRegistryTest.
@Test
public void setDecompressorRegistryTest() {
DecompressorRegistry decompressor = DecompressorRegistry.emptyInstance().with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "some-encoding";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return is;
}
}, true);
forward.setDecompressorRegistry(decompressor);
verify(mock).setDecompressorRegistry(same(decompressor));
}
use of io.grpc.Decompressor in project vertx-grpc by eclipse-vertx.
the class VertxClientCall method start.
@Override
public void start(Listener<ResponseT> responseListener, Metadata headers) {
listener = responseListener;
fut = client.request(server, methodDescriptor);
fut.onComplete(ar1 -> {
if (ar1.succeeded()) {
request = ar1.result();
Utils.writeMetadata(headers, request.headers());
if (encoding != null) {
request.encoding(encoding);
}
Future<GrpcClientResponse<RequestT, ResponseT>> responseFuture = request.response();
responseFuture.onComplete(ar2 -> {
if (ar2.succeeded()) {
grpcResponse = ar2.result();
String respEncoding = grpcResponse.encoding();
Decompressor decompressor = DecompressorRegistry.getDefaultInstance().lookupDecompressor(respEncoding);
BridgeMessageDecoder<ResponseT> decoder = new BridgeMessageDecoder<>(methodDescriptor.getResponseMarshaller(), decompressor);
Metadata responseHeaders = Utils.readMetadata(grpcResponse.headers());
if (exec == null) {
responseListener.onHeaders(responseHeaders);
} else {
exec.execute(() -> {
responseListener.onHeaders(responseHeaders);
});
}
readAdapter.init(grpcResponse, decoder);
} else {
Throwable err = ar2.cause();
if (err instanceof StreamResetException) {
StreamResetException reset = (StreamResetException) err;
switch((int) reset.getCode()) {
case 8:
doClose(Status.CANCELLED, new Metadata());
break;
default:
System.out.println("handle me");
break;
}
} else {
System.out.println("handle me");
}
}
});
writeAdapter.init(request, new BridgeMessageEncoder<>(methodDescriptor.getRequestMarshaller(), compressor));
}
});
}
use of io.grpc.Decompressor in project grpc-java by grpc.
the class ClientCallImplTest method prepareHeaders_acceptedMessageEncodingsAdded.
@Test
public void prepareHeaders_acceptedMessageEncodingsAdded() {
Metadata m = new Metadata();
DecompressorRegistry customRegistry = DecompressorRegistry.emptyInstance().with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "a";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, true).with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "b";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, true).with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "c";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, // not advertised
false);
ClientCallImpl.prepareHeaders(m, customRegistry, Codec.Identity.NONE, false);
Iterable<String> acceptedEncodings = ACCEPT_ENCODING_SPLITTER.split(new String(m.get(GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY), GrpcUtil.US_ASCII));
// Order may be different, since decoder priorities have not yet been implemented.
assertEquals(ImmutableSet.of("b", "a"), ImmutableSet.copyOf(acceptedEncodings));
}
use of io.grpc.Decompressor in project grpc-java by grpc.
the class ClientCallImplTest method prepareHeaders_acceptedMessageAndContentEncodingsAdded.
@Test
public void prepareHeaders_acceptedMessageAndContentEncodingsAdded() {
Metadata m = new Metadata();
DecompressorRegistry customRegistry = DecompressorRegistry.emptyInstance().with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "a";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, true).with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "b";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, true).with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "c";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, // not advertised
false);
ClientCallImpl.prepareHeaders(m, customRegistry, Codec.Identity.NONE, true);
Iterable<String> acceptedMessageEncodings = ACCEPT_ENCODING_SPLITTER.split(new String(m.get(GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY), GrpcUtil.US_ASCII));
// Order may be different, since decoder priorities have not yet been implemented.
assertEquals(ImmutableSet.of("b", "a"), ImmutableSet.copyOf(acceptedMessageEncodings));
Iterable<String> acceptedContentEncodings = ACCEPT_ENCODING_SPLITTER.split(new String(m.get(GrpcUtil.CONTENT_ACCEPT_ENCODING_KEY), GrpcUtil.US_ASCII));
assertEquals(ImmutableSet.of("gzip"), ImmutableSet.copyOf(acceptedContentEncodings));
}
use of io.grpc.Decompressor in project grpc-java by grpc.
the class ClientCallImplTest method prepareHeaders_acceptedEncodingsAdded.
@Test
public void prepareHeaders_acceptedEncodingsAdded() {
Metadata m = new Metadata();
DecompressorRegistry customRegistry = DecompressorRegistry.emptyInstance().with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "a";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, true).with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "b";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, true).with(new Decompressor() {
@Override
public String getMessageEncoding() {
return "c";
}
@Override
public InputStream decompress(InputStream is) throws IOException {
return null;
}
}, // not advertised
false);
ClientCallImpl.prepareHeaders(m, customRegistry, Codec.Identity.NONE, statsTraceCtx);
Iterable<String> acceptedEncodings = ACCEPT_ENCODING_SPLITTER.split(new String(m.get(GrpcUtil.MESSAGE_ACCEPT_ENCODING_KEY), GrpcUtil.US_ASCII));
// Order may be different, since decoder priorities have not yet been implemented.
assertEquals(ImmutableSet.of("b", "a"), ImmutableSet.copyOf(acceptedEncodings));
}
Aggregations