本文整理了Java中io.grpc.Status.fromCodeValue()
方法的一些代码示例,展示了Status.fromCodeValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.fromCodeValue()
方法的具体详情如下:
包路径:io.grpc.Status
类名称:Status
方法名:fromCodeValue
[英]Return a Status given a canonical error Code value.
[中]返回给定规范错误代码值的状态。
代码示例来源:origin: googleapis/google-cloud-java
/** 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()));
}
代码示例来源:origin: line/armeria
grpcResponse.trailingHeaders() : grpcResponse.headers();
final String grpcStatusCode = trailers.get(GrpcHeaderNames.GRPC_STATUS);
final Status grpcStatus = Status.fromCodeValue(Integer.parseInt(grpcStatusCode));
代码示例来源:origin: googleapis/google-cloud-java
@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);
}
代码示例来源:origin: googleapis/google-cloud-java
@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();
}
代码示例来源:origin: googleapis/google-cloud-java
@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();
}
代码示例来源:origin: googleapis/google-cloud-java
@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();
}
代码示例来源:origin: googleapis/google-cloud-java
@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();
}
代码示例来源:origin: googleapis/google-cloud-java
@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);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@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);
}
代码示例来源:origin: line/armeria
@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));
}
代码示例来源:origin: googleapis/google-cloud-java
@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);
}
代码示例来源:origin: googleapis/google-cloud-java
Status status =
change.hasCause()
? Status.fromCodeValue(change.getCause().getCode())
: Status.CANCELLED;
closeStream(
代码示例来源:origin: line/armeria
Status status = Status.fromCodeValue(Integer.valueOf(grpcStatus));
if (status.getCode() == Status.OK.getCode()) {
代码示例来源:origin: line/armeria
obs.onError(Status.fromCodeValue(req.getResponseStatus().getCode())
.withDescription(req.getResponseStatus().getMessage())
.asRuntimeException());
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
private static Code getGrpcCode(Status status) {
return status == null ? null : io.grpc.Status.fromCodeValue(status.getCode()).getCode();
}
代码示例来源:origin: googleapis/gax-java
@Override
public StatusCode getErrorCode() {
return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode());
}
代码示例来源:origin: com.google.api/gax-grpc
@Override
public StatusCode getErrorCode() {
return GrpcStatusCode.of(Status.fromCodeValue(operation.getError().getCode()).getCode());
}
代码示例来源:origin: com.google.cloud/google-cloud-bigtable
/** 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()));
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
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());
}
代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client
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();
}
内容来源于网络,如有侵权,请联系作者删除!