Search in sources :

Example 61 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project grakn by graknlabs.

the class GrpcGraknService method delete.

@Override
public void delete(DeleteRequest request, StreamObserver<DeleteResponse> responseObserver) {
    try {
        runAndConvertGraknExceptions(() -> {
            try (GraknTx tx = executor.execute(request.getOpen())) {
                tx.admin().delete();
            }
            responseObserver.onNext(GrpcUtil.deleteResponse());
            responseObserver.onCompleted();
        });
    } catch (StatusRuntimeException e) {
        responseObserver.onError(e);
    }
}
Also used : GraknTx(ai.grakn.GraknTx) StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 62 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project core-java by SpineEventEngine.

the class RequestValidator method feedToResponse.

private static void feedToResponse(InvalidRequestException cause, StreamObserver<?> responseObserver) {
    final StatusRuntimeException validationException = invalidArgumentWithCause(cause);
    responseObserver.onError(validationException);
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException)

Example 63 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpannerExceptionFactoryTest method abortWithRetryInfo.

@Test
public void abortWithRetryInfo() {
    Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
    Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
    Metadata trailers = new Metadata();
    RetryInfo retryInfo = RetryInfo.newBuilder().setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L)).build();
    trailers.put(key, retryInfo);
    SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers));
    assertThat(e).isInstanceOf(AbortedException.class);
    assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(1001L);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) RetryInfo(com.google.rpc.RetryInfo) Test(org.junit.Test)

Example 64 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class TransactionRunnerImplTest method createRetryException.

private StatusRuntimeException createRetryException() {
    Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance());
    Status status = Status.fromCodeValue(Status.Code.ABORTED.value());
    Metadata trailers = new Metadata();
    RetryInfo retryInfo = RetryInfo.newBuilder().setRetryDelay(Duration.newBuilder().setNanos(1000000).setSeconds(1L)).build();
    trailers.put(key, retryInfo);
    return new StatusRuntimeException(status, trailers);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) RetryInfo(com.google.rpc.RetryInfo)

Example 65 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class SpannerExceptionFactoryTest method http2InternalErrorIsRetryable.

@Test
public void http2InternalErrorIsRetryable() {
    Status status = Status.fromCodeValue(Status.Code.INTERNAL.value()).withDescription("HTTP/2 error code: INTERNAL_ERROR");
    SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status));
    assertThat(e.isRetryable()).isTrue();
}
Also used : Status(io.grpc.Status) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)131 Test (org.junit.Test)110 ApiException (com.google.api.gax.grpc.ApiException)74 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 ArrayList (java.util.ArrayList)11 Metadata (io.grpc.Metadata)10 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 StreamObserver (io.grpc.stub.StreamObserver)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 HelloReply (io.grpc.examples.helloworld.HelloReply)4 HelloRequest (io.grpc.examples.helloworld.HelloRequest)4