Search in sources :

Example 6 with ErrorInfo

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));
}
Also used : GetDatabaseRequest(com.google.spanner.admin.database.v1.GetDatabaseRequest) ErrorInfo(com.google.rpc.ErrorInfo) CreateBackupMetadata(com.google.spanner.admin.database.v1.CreateBackupMetadata) Metadata(io.grpc.Metadata) OptimizeRestoredDatabaseMetadata(com.google.spanner.admin.database.v1.OptimizeRestoredDatabaseMetadata) UpdateDatabaseDdlMetadata(com.google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata) CreateDatabaseMetadata(com.google.spanner.admin.database.v1.CreateDatabaseMetadata) RestoreDatabaseMetadata(com.google.spanner.admin.database.v1.RestoreDatabaseMetadata) Test(org.junit.Test)

Example 7 with ErrorInfo

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

Example 8 with ErrorInfo

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();
}
Also used : Status(com.google.rpc.Status) ErrorInfo(com.google.rpc.ErrorInfo) CheckedApiException(com.google.cloud.pubsublite.internal.CheckedApiException) Test(org.junit.Test)

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