use of io.grpc.examples.helloworld.GreeterGrpc.GreeterFutureStub in project grpc-java by grpc.
the class ErrorHandlingClient method futureCallCallback.
void futureCallCallback() {
GreeterFutureStub stub = GreeterGrpc.newFutureStub(channel);
ListenableFuture<HelloReply> response = stub.sayHello(HelloRequest.newBuilder().setName("Maggie").build());
final CountDownLatch latch = new CountDownLatch(1);
Futures.addCallback(response, new FutureCallback<HelloReply>() {
@Override
public void onSuccess(@Nullable HelloReply result) {
// Won't be called, since the server in this example always fails.
}
@Override
public void onFailure(Throwable t) {
Status status = Status.fromThrowable(t);
Verify.verify(status.getCode() == Status.Code.INTERNAL);
Verify.verify(status.getDescription().contains("Crybaby"));
// Cause is not transmitted over the wire..
latch.countDown();
}
}, directExecutor());
if (!Uninterruptibles.awaitUninterruptibly(latch, 1, TimeUnit.SECONDS)) {
throw new RuntimeException("timeout!");
}
}
use of io.grpc.examples.helloworld.GreeterGrpc.GreeterFutureStub in project grpc-java by grpc.
the class DetailErrorSample method futureCallCallback.
void futureCallCallback() {
GreeterFutureStub stub = GreeterGrpc.newFutureStub(channel);
ListenableFuture<HelloReply> response = stub.sayHello(HelloRequest.newBuilder().build());
final CountDownLatch latch = new CountDownLatch(1);
Futures.addCallback(response, new FutureCallback<HelloReply>() {
@Override
public void onSuccess(@Nullable HelloReply result) {
// Won't be called, since the server in this example always fails.
}
@Override
public void onFailure(Throwable t) {
verifyErrorReply(t);
latch.countDown();
}
}, directExecutor());
if (!Uninterruptibles.awaitUninterruptibly(latch, 1, TimeUnit.SECONDS)) {
throw new RuntimeException("timeout!");
}
}
use of io.grpc.examples.helloworld.GreeterGrpc.GreeterFutureStub in project grpc-java by grpc.
the class DetailErrorSample method futureCallDirect.
void futureCallDirect() {
GreeterFutureStub stub = GreeterGrpc.newFutureStub(channel);
ListenableFuture<HelloReply> response = stub.sayHello(HelloRequest.newBuilder().build());
try {
response.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} catch (ExecutionException e) {
verifyErrorReply(e.getCause());
}
}
use of io.grpc.examples.helloworld.GreeterGrpc.GreeterFutureStub in project grpc-java by grpc.
the class ErrorHandlingClient method futureCallDirect.
void futureCallDirect() {
GreeterFutureStub stub = GreeterGrpc.newFutureStub(channel);
ListenableFuture<HelloReply> response = stub.sayHello(HelloRequest.newBuilder().setName("Lisa").build());
try {
response.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
} catch (ExecutionException e) {
Status status = Status.fromThrowable(e.getCause());
Verify.verify(status.getCode() == Status.Code.INTERNAL);
Verify.verify(status.getDescription().contains("Xerxes"));
// Cause is not transmitted over the wire.
}
}
Aggregations