/** Convert an entry's status from a protobuf to an {@link ApiException}. */ private ApiException createEntryError(com.google.rpc.Status protoStatus) { io.grpc.Status grpcStatus = io.grpc.Status.fromCodeValue(protoStatus.getCode()) .withDescription(protoStatus.getMessage()); StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode()); return ApiExceptionFactory.createException( grpcStatus.asRuntimeException(), gaxStatusCode, retryableCodes.contains(gaxStatusCode.getCode())); }
grpcResponse.trailingHeaders() : grpcResponse.headers(); final String grpcStatusCode = trailers.get(GrpcHeaderNames.GRPC_STATUS); final Status grpcStatus = Status.fromCodeValue(Integer.parseInt(grpcStatusCode));
@Test public void abortWithoutRetryInfo() { Status status = Status.fromCodeValue(Status.Code.ABORTED.value()); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status)); assertThat(e).isInstanceOf(AbortedException.class); assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(-1L); }
@Test public void runResourceExhaustedNoRetry() throws Exception { try { runTransaction( new StatusRuntimeException(Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value()))); fail("Expected exception"); } catch (SpannerException e) { // expected. } verify(txn).rollback(); }
@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(); }
@Test public void connectionClosedIsRetryable() { Status status = Status.fromCodeValue(Status.Code.INTERNAL.value()) .withDescription("Connection closed with unknown cause"); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status)); assertThat(e.isRetryable()).isTrue(); }
@Test public void resourceExhausted() { Status status = Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value()) .withDescription("Memory pushback"); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status)); assertThat(e.isRetryable()).isFalse(); }
@Test public void abortWithoutDuration() { Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance()); Status status = Status.fromCodeValue(Status.Code.ABORTED.value()); Metadata trailers = new Metadata(); trailers.put(key, RetryInfo.getDefaultInstance()); SpannerException e = SpannerExceptionFactory.newSpannerException(new StatusRuntimeException(status, trailers)); assertThat(e).isInstanceOf(AbortedException.class); assertThat(((AbortedException) e).getRetryDelayInMillis()).isEqualTo(-1L); } }
@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); }
@Override public void onNext(StreamingOutputCallRequest request) { if (request.hasResponseStatus()) { dispatcher.cancel(); responseObserver.onError(Status.fromCodeValue(request.getResponseStatus().getCode()) .withDescription( request.getResponseStatus().getMessage()) .asRuntimeException()); return; } dispatcher.enqueue(toChunkQueue(request)); }
@Test public void resourceExhaustedWithBackoff() { Status status = Status.fromCodeValue(Status.Code.RESOURCE_EXHAUSTED.value()) .withDescription("Memory pushback"); Metadata trailers = new Metadata(); Metadata.Key<RetryInfo> key = ProtoUtils.keyForProto(RetryInfo.getDefaultInstance()); 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.isRetryable()).isTrue(); assertThat(e.getRetryDelayInMillis()).isEqualTo(1001); }
Status status = change.hasCause() ? Status.fromCodeValue(change.getCause().getCode()) : Status.CANCELLED; closeStream(
Status status = Status.fromCodeValue(Integer.valueOf(grpcStatus)); if (status.getCode() == Status.OK.getCode()) {
obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode()) .withDescription(req.getResponseStatus().getMessage()) .asRuntimeException());
private static Code getGrpcCode(Status status) { return status == null ? null : io.grpc.Status.fromCodeValue(status.getCode()).getCode(); }
@Override public StatusCode getErrorCode() { return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode()); }
@Override public StatusCode getErrorCode() { return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode()); }
/** Convert an entry's status from a protobuf to an {@link ApiException}. */ private ApiException createEntryError(com.google.rpc.Status protoStatus) { io.grpc.Status grpcStatus = io.grpc.Status.fromCodeValue(protoStatus.getCode()) .withDescription(protoStatus.getMessage()); StatusCode gaxStatusCode = GrpcStatusCode.of(grpcStatus.getCode()); return ApiExceptionFactory.createException( grpcStatus.asRuntimeException(), gaxStatusCode, retryableCodes.contains(gaxStatusCode.getCode())); }
private static Status toStatus(com.google.rpc.Status statusProto) { Status status = Status.fromCodeValue(statusProto.getCode()); checkArgument(status.getCode().value() == statusProto.getCode(), "invalid status code"); return status.withDescription(statusProto.getMessage()); }
private static StatusRuntimeException toException(Status status) { io.grpc.Status grpcStatus = io.grpc.Status .fromCodeValue(status.getCode()) .withDescription(status.getMessage()); for (Any detail : status.getDetailsList()) { grpcStatus = grpcStatus.augmentDescription(detail.toString()); } return grpcStatus.asRuntimeException(); }