use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class BinlogHelperTest method logTrailer.
@Test
public void logTrailer() throws Exception {
long seq = 1;
InetAddress address = InetAddress.getByName("127.0.0.1");
int port = 12345;
InetSocketAddress peerAddress = new InetSocketAddress(address, port);
long callId = 1000;
Status statusDescription = Status.INTERNAL.withDescription("my description");
GrpcLogEntry.Builder builder = metadataToProtoTestHelper(EventType.EVENT_TYPE_SERVER_TRAILER, nonEmptyMetadata, 10).toBuilder().setTimestamp(timestamp).setSequenceIdWithinCall(seq).setLogger(Logger.LOGGER_CLIENT).setCallId(callId).setPeer(BinlogHelper.socketToProto(peerAddress));
builder.getTrailerBuilder().setStatusCode(Status.INTERNAL.getCode().value()).setStatusMessage("my description");
GrpcLogEntry base = builder.build();
{
sinkWriterImpl.logTrailer(seq, statusDescription, nonEmptyMetadata, Logger.LOGGER_CLIENT, callId, peerAddress);
verify(sink).write(base);
}
// logger is server
{
sinkWriterImpl.logTrailer(seq, statusDescription, nonEmptyMetadata, Logger.LOGGER_SERVER, callId, /*peerAddress=*/
null);
verify(sink).write(base.toBuilder().clearPeer().setLogger(Logger.LOGGER_SERVER).build());
}
// peerAddress is null
{
sinkWriterImpl.logTrailer(seq, statusDescription, nonEmptyMetadata, Logger.LOGGER_CLIENT, callId, /*peerAddress=*/
null);
verify(sink).write(base.toBuilder().clearPeer().build());
}
// status code is present but description is null
{
sinkWriterImpl.logTrailer(seq, // strip the description
statusDescription.getCode().toStatus(), nonEmptyMetadata, Logger.LOGGER_CLIENT, callId, peerAddress);
verify(sink).write(base.toBuilder().setTrailer(base.getTrailer().toBuilder().clearStatusMessage()).build());
}
// status proto always logged if present (com.google.rpc.Status),
{
int zeroHeaderBytes = 0;
SinkWriterImpl truncatingWriter = new SinkWriterImpl(sink, timeProvider, zeroHeaderBytes, MESSAGE_LIMIT);
com.google.rpc.Status statusProto = com.google.rpc.Status.newBuilder().addDetails(Any.pack(StringValue.newBuilder().setValue("arbitrarypayload").build())).setCode(Status.INTERNAL.getCode().value()).setMessage("status detail string").build();
StatusException statusException = StatusProto.toStatusException(statusProto, nonEmptyMetadata);
truncatingWriter.logTrailer(seq, statusException.getStatus(), statusException.getTrailers(), Logger.LOGGER_CLIENT, callId, peerAddress);
verify(sink).write(base.toBuilder().setTrailer(builder.getTrailerBuilder().setStatusMessage("status detail string").setStatusDetails(ByteString.copyFrom(statusProto.toByteArray())).setMetadata(io.grpc.binarylog.v1.Metadata.getDefaultInstance())).build());
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class StatusProtoTest method fromThrowableWithNestedStatusException.
@Test
public void fromThrowableWithNestedStatusException() {
StatusException se = StatusProto.toStatusException(STATUS_PROTO);
Throwable nestedSe = new Throwable(se);
com.google.rpc.Status extractedStatusProto = StatusProto.fromThrowable(se);
com.google.rpc.Status extractedStatusProtoFromNestedSe = StatusProto.fromThrowable(nestedSe);
assertEquals(extractedStatusProto, extractedStatusProtoFromNestedSe);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project grpc-java by grpc.
the class StatusProtoTest method toStatusExceptionWithMetadata_shouldIncludeMetadata.
@Test
public void toStatusExceptionWithMetadata_shouldIncludeMetadata() throws Exception {
StatusException se = StatusProto.toStatusException(STATUS_PROTO, metadata);
com.google.rpc.Status extractedStatusProto = StatusProto.fromThrowable(se);
assertEquals(STATUS_PROTO.getCode(), se.getStatus().getCode().value());
assertEquals(STATUS_PROTO.getMessage(), se.getStatus().getDescription());
assertEquals(STATUS_PROTO, extractedStatusProto);
assertNotNull(se.getTrailers());
assertEquals(METADATA_VALUE, se.getTrailers().get(METADATA_KEY));
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project jetcd by coreos.
the class UtilTest method testAuthErrorIsNotRetryable.
@Test
public void testAuthErrorIsNotRetryable() {
Status authErrorStatus = Status.UNAUTHENTICATED.withDescription("etcdserver: invalid auth token");
Status status = Status.fromThrowable(new StatusException(authErrorStatus));
assertThat(Errors.isRetryable(status)).isTrue();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException in project jetcd by coreos.
the class UtilTest method testUnavailableErrorIsRetryable.
@Test
public void testUnavailableErrorIsRetryable() {
Status status = Status.fromThrowable(new StatusException(Status.UNAVAILABLE));
assertThat(Errors.isRetryable(status)).isTrue();
}
Aggregations