Search in sources :

Example 51 with OperationSnapshot

use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.

the class ProtoOperationTransformersTest method testMetadataTransformer.

@Test
public void testMetadataTransformer() {
    MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
    Money inputMoney = Money.newBuilder().setCurrencyCode("UAH").build();
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.newBuilder().setName("Barcelona").setMetadata(inputMoney).setDone(true).setResponse("Gary").setError(0, "no error").build();
    Truth.assertThat(transformer.apply(operationSnapshot)).isEqualTo(inputMoney);
}
Also used : Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) Test(org.junit.Test)

Example 52 with OperationSnapshot

use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.

the class ProtoOperationTransformersTest method testAnyMetadataTransformer_mismatchedTypes.

@Test
public void testAnyMetadataTransformer_mismatchedTypes() {
    MetadataTransformer<Money> transformer = MetadataTransformer.create(Money.class);
    Status status = Status.newBuilder().setCode(Code.OK.getNumber()).build();
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setMetadata(Any.pack(Color.getDefaultInstance())).setError(status).build());
    Exception exception = assertThrows(UnknownException.class, () -> transformer.apply(operationSnapshot));
    Truth.assertThat(exception).hasMessageThat().contains("encountered a problem unpacking it");
}
Also used : Status(com.google.rpc.Status) Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) UnknownException(com.google.api.gax.rpc.UnknownException) UnavailableException(com.google.api.gax.rpc.UnavailableException) Test(org.junit.Test)

Example 53 with OperationSnapshot

use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.

the class ProtoOperationTransformersTest method testAnyResponseTransformer_exception.

@Test
public void testAnyResponseTransformer_exception() {
    ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
    Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
    Status status = Status.newBuilder().setCode(Code.UNAVAILABLE.getNumber()).build();
    OperationSnapshot operationSnapshot = HttpJsonOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(inputMoney)).setError(status).build());
    Exception exception = assertThrows(UnavailableException.class, () -> transformer.apply(operationSnapshot));
    Truth.assertThat(exception).hasMessageThat().contains("failed with status = HttpJsonStatusCode{statusCode=UNAVAILABLE}");
}
Also used : Status(com.google.rpc.Status) Money(com.google.type.Money) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) UnknownException(com.google.api.gax.rpc.UnknownException) UnavailableException(com.google.api.gax.rpc.UnavailableException) Test(org.junit.Test)

Example 54 with OperationSnapshot

use of com.google.api.gax.longrunning.OperationSnapshot in project java-bigtable by googleapis.

the class BigtableTableAdminClientTest method mockOperationResult.

private <ReqT, RespT, MetaT> void mockOperationResult(OperationCallable<ReqT, RespT, MetaT> callable, ReqT request, RespT response, MetaT metadata) {
    OperationSnapshot operationSnapshot = FakeOperationSnapshot.newBuilder().setDone(true).setErrorCode(GrpcStatusCode.of(Code.OK)).setName("fake-name").setResponse(response).setMetadata(metadata).build();
    OperationFuture<RespT, MetaT> operationFuture = OperationFutures.immediateOperationFuture(operationSnapshot);
    Mockito.when(callable.futureCall(request)).thenReturn(operationFuture);
}
Also used : OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot)

Example 55 with OperationSnapshot

use of com.google.api.gax.longrunning.OperationSnapshot in project java-bigtable by googleapis.

the class BigtableInstanceAdminClientTest method mockOperationResult.

private <ReqT, RespT, MetaT> void mockOperationResult(OperationCallable<ReqT, RespT, MetaT> callable, ReqT request, RespT response) {
    OperationSnapshot operationSnapshot = FakeOperationSnapshot.newBuilder().setDone(true).setErrorCode(GrpcStatusCode.of(Code.OK)).setName("fake-name").setResponse(response).build();
    OperationFuture<RespT, MetaT> operationFuture = OperationFutures.immediateOperationFuture(operationSnapshot);
    Mockito.when(callable.futureCall(request)).thenReturn(operationFuture);
}
Also used : OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot)

Aggregations

OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)55 Test (org.junit.Test)44 FakeOperationSnapshot (com.google.api.gax.rpc.testing.FakeOperationSnapshot)28 Color (java.awt.Color)23 Currency (java.util.Currency)23 Money (com.google.type.Money)13 UnavailableException (com.google.api.gax.rpc.UnavailableException)7 UnknownException (com.google.api.gax.rpc.UnknownException)6 Status (com.google.rpc.Status)6 FakeStatusCode (com.google.api.gax.rpc.testing.FakeStatusCode)4 ExecutionException (java.util.concurrent.ExecutionException)4 FakeApiClock (com.google.api.gax.core.FakeApiClock)2 FakeApiMessage (com.google.api.gax.httpjson.testing.FakeApiMessage)2 TimedRetryAlgorithm (com.google.api.gax.retrying.TimedRetryAlgorithm)2 ApiCallContext (com.google.api.gax.rpc.ApiCallContext)2 ApiException (com.google.api.gax.rpc.ApiException)2 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)2 CancellationException (java.util.concurrent.CancellationException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 BatchingSettings (com.google.api.gax.batching.BatchingSettings)1