Search in sources :

Example 1 with AdminRequestsLimitExceededRetryAlgorithm

use of com.google.cloud.spanner.spi.v1.GapicSpannerRpc.AdminRequestsLimitExceededRetryAlgorithm in project java-spanner by googleapis.

the class GapicSpannerRpcTest method testAdminRequestsLimitExceededRetryAlgorithm.

@Test
public void testAdminRequestsLimitExceededRetryAlgorithm() {
    AdminRequestsLimitExceededRetryAlgorithm<Long> alg = new AdminRequestsLimitExceededRetryAlgorithm<>();
    assertThat(alg.shouldRetry(null, 1L)).isFalse();
    ErrorInfo info = ErrorInfo.newBuilder().putMetadata("quota_limit", "AdminMethodQuotaPerMinutePerProject").build();
    Metadata.Key<ErrorInfo> key = Metadata.Key.of(info.getDescriptorForType().getFullName() + Metadata.BINARY_HEADER_SUFFIX, ProtoLiteUtils.metadataMarshaller(info));
    Metadata trailers = new Metadata();
    trailers.put(key, info);
    SpannerException adminRateExceeded = SpannerExceptionFactory.newSpannerException(Status.RESOURCE_EXHAUSTED.withDescription("foo").asRuntimeException(trailers));
    assertThat(alg.shouldRetry(adminRateExceeded, null)).isTrue();
    SpannerException numDatabasesExceeded = SpannerExceptionFactory.newSpannerException(Status.RESOURCE_EXHAUSTED.withDescription("Too many databases on instance").asRuntimeException());
    assertThat(alg.shouldRetry(numDatabasesExceeded, null)).isFalse();
    assertThat(alg.shouldRetry(new Exception("random exception"), null)).isFalse();
}
Also used : ErrorInfo(com.google.rpc.ErrorInfo) Metadata(io.grpc.Metadata) ResultSetMetadata(com.google.spanner.v1.ResultSetMetadata) SpannerException(com.google.cloud.spanner.SpannerException) AdminRequestsLimitExceededRetryAlgorithm(com.google.cloud.spanner.spi.v1.GapicSpannerRpc.AdminRequestsLimitExceededRetryAlgorithm) IOException(java.io.IOException) SpannerException(com.google.cloud.spanner.SpannerException) Test(org.junit.Test)

Aggregations

SpannerException (com.google.cloud.spanner.SpannerException)1 AdminRequestsLimitExceededRetryAlgorithm (com.google.cloud.spanner.spi.v1.GapicSpannerRpc.AdminRequestsLimitExceededRetryAlgorithm)1 ErrorInfo (com.google.rpc.ErrorInfo)1 ResultSetMetadata (com.google.spanner.v1.ResultSetMetadata)1 Metadata (io.grpc.Metadata)1 IOException (java.io.IOException)1 Test (org.junit.Test)1