Search in sources :

Example 21 with StatusException

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());
    }
}
Also used : Status(io.grpc.Status) StatusException(io.grpc.StatusException) InetSocketAddress(java.net.InetSocketAddress) SinkWriterImpl(io.grpc.protobuf.services.BinlogHelper.SinkWriterImpl) GrpcLogEntry(io.grpc.binarylog.v1.GrpcLogEntry) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 22 with StatusException

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);
}
Also used : StatusException(io.grpc.StatusException) Test(org.junit.Test)

Example 23 with StatusException

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));
}
Also used : StatusException(io.grpc.StatusException) Test(org.junit.Test)

Example 24 with StatusException

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();
}
Also used : Status(io.grpc.Status) StatusException(io.grpc.StatusException) Test(org.junit.jupiter.api.Test)

Example 25 with StatusException

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();
}
Also used : Status(io.grpc.Status) StatusException(io.grpc.StatusException) Test(org.junit.jupiter.api.Test)

Aggregations

StatusException (io.grpc.StatusException)45 Test (org.junit.Test)20 Status (io.grpc.Status)9 IOException (java.io.IOException)9 StatusException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusException)9 ExecutionException (java.util.concurrent.ExecutionException)8 PinpointGrpcServer (com.navercorp.pinpoint.collector.receiver.grpc.PinpointGrpcServer)6 Metadata (io.grpc.Metadata)6 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)5 HealthCheckResponse (io.grpc.health.v1.HealthCheckResponse)4 TrackingObjectPoolForTest (io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest)4 TimeoutException (java.util.concurrent.TimeoutException)4 StatusRuntimeException (io.grpc.StatusRuntimeException)3 InetSocketAddress (java.net.InetSocketAddress)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)3 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)3 AgentInfo (com.navercorp.pinpoint.collector.cluster.AgentInfo)2 PCmdMessage (com.navercorp.pinpoint.grpc.trace.PCmdMessage)2 PCmdRequest (com.navercorp.pinpoint.grpc.trace.PCmdRequest)2 PCmdResponse (com.navercorp.pinpoint.grpc.trace.PCmdResponse)2