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();
}
Aggregations