Search in sources :

Example 1 with RetryInfo

use of com.google.rpc.RetryInfo in project google-cloud-java by GoogleCloudPlatform.

the class SpannerExceptionFactoryTest method abortWithRetryInfo.

@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);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) RetryInfo(com.google.rpc.RetryInfo) Test(org.junit.Test)

Example 2 with RetryInfo

use of com.google.rpc.RetryInfo in project google-cloud-java by GoogleCloudPlatform.

the class TransactionRunnerImplTest method createRetryException.

private StatusRuntimeException createRetryException() {
    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);
    return new StatusRuntimeException(status, trailers);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) RetryInfo(com.google.rpc.RetryInfo)

Example 3 with RetryInfo

use of com.google.rpc.RetryInfo in project google-cloud-java by GoogleCloudPlatform.

the class SpannerExceptionFactoryTest method abortWithoutDuration.

@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);
}
Also used : Status(io.grpc.Status) Metadata(io.grpc.Metadata) StatusRuntimeException(io.grpc.StatusRuntimeException) RetryInfo(com.google.rpc.RetryInfo) Test(org.junit.Test)

Aggregations

RetryInfo (com.google.rpc.RetryInfo)3 Metadata (io.grpc.Metadata)3 Status (io.grpc.Status)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 Test (org.junit.Test)2