Search in sources :

Example 1 with ErrorInfo

use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.

the class TestResetSignal method newCheckedException.

public static CheckedApiException newCheckedException() {
    ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("RESET").setDomain("pubsublite.googleapis.com").build();
    Status status = Status.newBuilder().setCode(Code.ABORTED.ordinal()).addDetails(Any.pack(errorInfo)).build();
    return new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.ABORTED);
}
Also used : Status(com.google.rpc.Status) ErrorInfo(com.google.rpc.ErrorInfo) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException)

Example 2 with ErrorInfo

use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.

the class ResetSignalTest method isResetSignal_notRetryable.

@Test
public void isResetSignal_notRetryable() {
    ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("RESET").setDomain("pubsublite.googleapis.com").build();
    Status status = Status.newBuilder().setCode(Code.FAILED_PRECONDITION.ordinal()).addDetails(Any.pack(errorInfo)).build();
    CheckedApiException exception = new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.FAILED_PRECONDITION);
    assertThat(ResetSignal.isResetSignal(exception)).isFalse();
}
Also used : Status(com.google.rpc.Status) ErrorInfo(com.google.rpc.ErrorInfo) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) Test(org.junit.Test)

Example 3 with ErrorInfo

use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.

the class ResetSignalTest method isResetSignal_wrongReason.

@Test
public void isResetSignal_wrongReason() {
    ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("OTHER").setDomain("pubsublite.googleapis.com").build();
    Status status = Status.newBuilder().setCode(Code.ABORTED.ordinal()).addDetails(Any.pack(errorInfo)).build();
    CheckedApiException exception = new CheckedApiException(StatusProto.toStatusRuntimeException(status), Code.ABORTED);
    assertThat(ResetSignal.isResetSignal(exception)).isFalse();
}
Also used : Status(com.google.rpc.Status) ErrorInfo(com.google.rpc.ErrorInfo) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) Test(org.junit.Test)

Example 4 with ErrorInfo

use of com.google.rpc.ErrorInfo in project java-pubsub by googleapis.

the class StreamingSubscriberConnectionTest method getMockStatusException.

private StatusException getMockStatusException(Map<String, String> metadata) {
    ErrorInfo errorInfo = ErrorInfo.newBuilder().putAllMetadata(metadata).build();
    Status status = Status.newBuilder().setCode(StatusCode.Code.OK.ordinal()).addDetails(Any.pack(errorInfo)).build();
    return StatusProto.toStatusException(status);
}
Also used : Status(com.google.rpc.Status) ErrorInfo(com.google.rpc.ErrorInfo)

Example 5 with ErrorInfo

use of com.google.rpc.ErrorInfo in project java-pubsub by googleapis.

the class StreamingSubscriberConnection method getMetadataMapFromThrowable.

private Map<String, String> getMetadataMapFromThrowable(Throwable t) throws InvalidProtocolBufferException {
    // This converts a Throwable (from a "OK" grpc response) to a map of metadata
    // will be of the format:
    // {
    // "ACK-ID-1": "PERMANENT_*",
    // "ACK-ID-2": "TRANSIENT_*"
    // }
    com.google.rpc.Status status = StatusProto.fromThrowable(t);
    Map<String, String> metadataMap = new HashMap<>();
    if (status != null) {
        for (Any any : status.getDetailsList()) {
            if (any.is(ErrorInfo.class)) {
                ErrorInfo errorInfo = any.unpack(ErrorInfo.class);
                metadataMap = errorInfo.getMetadataMap();
            }
        }
    }
    return metadataMap;
}
Also used : com.google.api.gax.rpc(com.google.api.gax.rpc) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ErrorInfo(com.google.rpc.ErrorInfo) Any(com.google.protobuf.Any)

Aggregations

ErrorInfo (com.google.rpc.ErrorInfo)8 Status (com.google.rpc.Status)5 Test (org.junit.Test)5 CheckedApiException (com.google.cloud.pubsublite.internal.CheckedApiException)4 Metadata (io.grpc.Metadata)2 com.google.api.gax.rpc (com.google.api.gax.rpc)1 SpannerException (com.google.cloud.spanner.SpannerException)1 AdminRequestsLimitExceededRetryAlgorithm (com.google.cloud.spanner.spi.v1.GapicSpannerRpc.AdminRequestsLimitExceededRetryAlgorithm)1 Any (com.google.protobuf.Any)1 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)1 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)1 GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)1 OptimizeRestoredDatabaseMetadata (com.google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata)1 RestoreDatabaseMetadata (com.google.spanner.admin.database.v1.RestoreDatabaseMetadata)1 UpdateDatabaseDdlMetadata (com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata)1 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)1 IOException (java.io.IOException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1