本文整理了Java中io.grpc.Status.getDescription()
方法的一些代码示例,展示了Status.getDescription()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Status.getDescription()
方法的具体详情如下:
包路径:io.grpc.Status
类名称:Status
方法名:getDescription
[英]A description of this status for human consumption.
[中]用于人类消费的这种状态的描述。
代码示例来源:origin: line/armeria
@Test
public void error_thrown_unary() throws Exception {
final StatusRuntimeException t = (StatusRuntimeException) catchThrowable(
() -> blockingClient.unaryThrowsError(REQUEST_MESSAGE));
assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED);
assertThat(t.getStatus().getDescription()).isEqualTo("call aborted");
checkRequestLog((rpcReq, rpcRes, grpcStatus) -> {
assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/UnaryThrowsError");
assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE);
assertThat(grpcStatus).isNotNull();
assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED);
assertThat(grpcStatus.getDescription()).isEqualTo("call aborted");
});
}
代码示例来源:origin: line/armeria
@Test
public void error_withMessage() throws Exception {
final StatusRuntimeException t = (StatusRuntimeException) catchThrowable(
() -> blockingClient.errorWithMessage(REQUEST_MESSAGE));
assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED);
assertThat(t.getStatus().getDescription()).isEqualTo("aborted call");
checkRequestLog((rpcReq, rpcRes, grpcStatus) -> {
assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/ErrorWithMessage");
assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE);
assertThat(grpcStatus).isNotNull();
assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED);
assertThat(grpcStatus.getDescription()).isEqualTo("aborted call");
});
}
代码示例来源:origin: line/armeria
@Test
public void error_noMessage() throws Exception {
final StatusRuntimeException t = (StatusRuntimeException) catchThrowable(
() -> blockingClient.errorNoMessage(REQUEST_MESSAGE));
assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED);
assertThat(t.getStatus().getDescription()).isNull();
checkRequestLog((rpcReq, rpcRes, grpcStatus) -> {
assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/ErrorNoMessage");
assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE);
assertThat(grpcStatus).isNotNull();
assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED);
assertThat(grpcStatus.getDescription()).isNull();
});
}
代码示例来源:origin: line/armeria
@Test
public void error_thrown_streamStub() throws Exception {
final StreamRecorder<SimpleResponse> response = StreamRecorder.create();
streamingClient.streamThrowsErrorInStub(response);
response.awaitCompletion();
final StatusRuntimeException t = (StatusRuntimeException) response.getError();
assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED);
assertThat(t.getStatus().getDescription()).isEqualTo("bad streaming stub");
checkRequestLogStatus(grpcStatus -> {
assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED);
assertThat(grpcStatus.getDescription()).isEqualTo("bad streaming stub");
});
}
代码示例来源:origin: line/armeria
@Test
public void error_thrown_streamMessage() throws Exception {
final StreamRecorder<SimpleResponse> response = StreamRecorder.create();
final StreamObserver<SimpleRequest> request = streamingClient.streamThrowsError(response);
request.onNext(REQUEST_MESSAGE);
response.awaitCompletion();
final StatusRuntimeException t = (StatusRuntimeException) response.getError();
assertThat(t.getStatus().getCode()).isEqualTo(Code.ABORTED);
assertThat(t.getStatus().getDescription()).isEqualTo("bad streaming message");
checkRequestLog((rpcReq, rpcRes, grpcStatus) -> {
assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/StreamThrowsError");
assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE);
assertThat(grpcStatus).isNotNull();
assertThat(grpcStatus.getCode()).isEqualTo(Code.ABORTED);
assertThat(grpcStatus.getDescription()).isEqualTo("bad streaming message");
});
}
代码示例来源:origin: line/armeria
static HttpHeaders statusToTrailers(ServiceRequestContext ctx, Status status, boolean headersSent) {
final HttpHeaders trailers;
if (headersSent) {
// Normal trailers.
trailers = new DefaultHttpHeaders();
} else {
// Trailers only response
trailers = new DefaultHttpHeaders(true, 3, true)
.status(HttpStatus.OK)
.set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto");
}
trailers.add(GrpcHeaderNames.GRPC_STATUS, Integer.toString(status.getCode().value()));
if (status.getDescription() != null) {
trailers.add(GrpcHeaderNames.GRPC_MESSAGE, StatusMessageEscaper.escape(status.getDescription()));
}
if (ctx.server().config().verboseResponses() && status.getCause() != null) {
final ThrowableProto proto = GrpcStatus.serializeThrowable(status.getCause());
trailers.add(GrpcHeaderNames.ARMERIA_GRPC_THROWABLEPROTO_BIN,
Base64.getEncoder().encodeToString(proto.toByteArray()));
}
return trailers;
}
代码示例来源:origin: line/armeria
final StatusRuntimeException e = (StatusRuntimeException) t;
assertThat(e.getStatus().getCode()).isEqualTo(Status.UNKNOWN.getCode());
assertThat(e.getStatus().getDescription()).isEqualTo(errorMessage);
verify(responseObserver, timeout(operationTimeoutMillis())).onError(captor.capture());
assertThat(Status.fromThrowable(captor.getValue()).getCode()).isEqualTo(Status.UNKNOWN.getCode());
assertThat(Status.fromThrowable(captor.getValue()).getDescription()).isEqualTo(errorMessage);
verifyNoMoreInteractions(responseObserver);
assertThat(grpcStatus).isNotNull();
assertThat(grpcStatus.getCode()).isEqualTo(Code.UNKNOWN);
assertThat(grpcStatus.getDescription()).isEqualTo(errorMessage);
});
代码示例来源:origin: line/armeria
@Test
public void nonAsciiStatusMessage() {
String statusMessage = "ほげほげ";
assertThatThrownBy(() -> blockingStub.unaryCall(
SimpleRequest.newBuilder()
.setResponseStatus(EchoStatus.newBuilder()
.setCode(2)
.setMessage(statusMessage))
.build())).isInstanceOfSatisfying(
StatusRuntimeException.class,
e -> assertThat(e.getStatus().getDescription()).isEqualTo(statusMessage));
}
代码示例来源:origin: hyperledger/fabric-sdk-java
Status sreStatus = sre.getStatus();
if (EVENTHUB_RECONNECTION_WARNING_RATE > 1 && reconnectCount % EVENTHUB_RECONNECTION_WARNING_RATE == 1) {
logger.warn(format("%s :StatusRuntimeException Status %s. Description %s ", EventHub.this, sreStatus + "", sreStatus.getDescription()));
} else {
logger.trace(format("%s :StatusRuntimeException Status %s. Description %s ", EventHub.this, sreStatus + "", sreStatus.getDescription()));
代码示例来源:origin: hyperledger/fabric-sdk-java
StatusRuntimeException sre = (StatusRuntimeException) t;
Status status = sre.getStatus();
logger.error(format("%s grpc status Code:%s, Description %s, ", toString(), status.getDescription(), status.getCode() + ""), sre.getCause());
代码示例来源:origin: zeebe-io/zeebe
public ClientStatusException(Status status, Throwable cause) {
super(status.getDescription(), cause);
this.status = status;
}
代码示例来源:origin: io.grpc/grpc-core
private String printShortStatus(Status status) {
StringBuilder buffer = new StringBuilder();
buffer.append(status.getCode());
if (status.getDescription() != null) {
buffer.append("(").append(status.getDescription()).append(")");
}
return buffer.toString();
}
}
代码示例来源:origin: stephenh/mirror
private static String niceToString(Status status) {
// the default Status.toString has a stack trace in it, which is ugly
return MoreObjects
.toStringHelper(status)
.add("code", status.getCode().name())
.add("description", status.getDescription())
.add("cause", status.getCause() != null ? status.getCause().getMessage() : null)
.toString();
}
代码示例来源:origin: io.grpc/grpc-core
private void addStatusToTrailers(Metadata trailers, Status status) {
trailers.discardAll(InternalStatus.CODE_KEY);
trailers.discardAll(InternalStatus.MESSAGE_KEY);
trailers.put(InternalStatus.CODE_KEY, status);
if (status.getDescription() != null) {
trailers.put(InternalStatus.MESSAGE_KEY, status.getDescription());
}
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
private void addStatusToTrailers(Metadata trailers, Status status) {
trailers.discardAll(InternalStatus.CODE_KEY);
trailers.discardAll(InternalStatus.MESSAGE_KEY);
trailers.put(InternalStatus.CODE_KEY, status);
if (status.getDescription() != null) {
trailers.put(InternalStatus.MESSAGE_KEY, status.getDescription());
}
}
代码示例来源:origin: ai.grakn/grakn-test-tools
public static Matcher<StatusRuntimeException> hasStatus(Status status) {
Matcher<Status> hasCode = hasProperty("code", is(status.getCode()));
Matcher<Status> statusMatcher;
String description = status.getDescription();
if (description == null) {
statusMatcher = hasCode;
} else {
Matcher<Status> hasDescription = hasProperty("description", is(description));
statusMatcher = allOf(hasCode, hasDescription);
}
return allOf(isA(StatusRuntimeException.class), hasProperty("status", statusMatcher));
}
代码示例来源:origin: etcd-io/jetcd
private static EtcdException fromStatus(Status status) {
return newEtcdException(
ErrorCode.fromGrpcStatus(status),
status.getDescription(),
status.getCause()
);
}
}
代码示例来源:origin: io.etcd/jetcd-common
private static EtcdException fromStatus(Status status) {
return newEtcdException(
ErrorCode.fromGrpcStatus(status),
status.getDescription(),
status.getCause()
);
}
}
代码示例来源:origin: com.coreos/jetcd-common
private static EtcdException fromStatus(Status status) {
return newEtcdException(
ErrorCode.fromGrpcStatus(status),
status.getDescription(),
status.getCause()
);
}
}
代码示例来源:origin: ai.grakn/grakn-grpc
private static RuntimeException convertStatusRuntimeException(StatusRuntimeException error) {
Status status = error.getStatus();
Metadata trailers = error.getTrailers();
ErrorType errorType = trailers.get(ErrorType.KEY);
if (errorType != null) {
String message = status.getDescription();
return errorType.toException(message);
} else {
return error;
}
}
内容来源于网络,如有侵权,请联系作者删除!