use of com.google.rpc.ErrorInfo in project java-spanner by googleapis.
the class DatabaseAdminClientTest method testRetryOperationOnAdminMethodQuotaPerMinutePerProjectExceeded.
@Test
public void testRetryOperationOnAdminMethodQuotaPerMinutePerProjectExceeded() {
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);
mockDatabaseAdmin.addException(Status.RESOURCE_EXHAUSTED.withDescription("foo").asRuntimeException(trailers));
mockDatabaseAdmin.clearRequests();
Database database = client.getDatabase(INSTANCE_ID, DB_ID);
assertEquals(DB_ID, database.getId().getDatabase());
assertEquals(2, mockDatabaseAdmin.countRequestsOfType(GetDatabaseRequest.class));
}
use of com.google.rpc.ErrorInfo 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();
}
use of com.google.rpc.ErrorInfo in project java-pubsublite by googleapis.
the class ResetSignalTest method isResetSignal_wrongDomain.
@Test
public void isResetSignal_wrongDomain() {
ErrorInfo errorInfo = ErrorInfo.newBuilder().setReason("RESET").setDomain("other.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();
}
Aggregations