Search in sources :

Example 41 with OperationSnapshot

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

the class OperationCallableImplTest method testFutureCallInitialDoneWrongType.

@Test
public void testFutureCallInitialDoneWrongType() throws Exception {
    String opName = "testFutureCallInitialDoneWrongType";
    Currency resp = Currency.getInstance("USD");
    Currency meta = Currency.getInstance("UAH");
    OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, true);
    UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, resultOperation);
    LongRunningClient longRunningClient = new UnsupportedOperationApi();
    OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, initialContext, longRunningClient);
    OperationFuture<Color, Currency> future = callable.futureCall(2, FakeCallContext.createDefault());
    assertFutureFailMetaSuccess(future, meta, FakeStatusCode.of(StatusCode.Code.OK), "type mismatch: expected java.awt.Color, found java.util.Currency");
    assertThat(executor.getIterationsCount()).isEqualTo(0);
}
Also used : Currency(java.util.Currency) Color(java.awt.Color) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) Test(org.junit.Test)

Example 42 with OperationSnapshot

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

the class OperationCallableImplTest method testFutureCallPollCancelOnLongTimeoutExceeded.

@Test
public void testFutureCallPollCancelOnLongTimeoutExceeded() throws Exception {
    final int iterationsCount = 1000;
    String opName = "testFutureCallPollCancelOnLongTimeoutExceeded";
    OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
    OperationSnapshot[] pollOperations = new OperationSnapshot[iterationsCount];
    for (int i = 0; i < iterationsCount; i++) {
        pollOperations[i] = getOperation(opName, null, null, null, false);
    }
    UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
    LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, pollOperations);
    pollingAlgorithm = OperationTimedPollAlgorithm.create(FAST_RECHECKING_SETTINGS.toBuilder().setTotalTimeout(Duration.ofMillis(1000L)).build(), clock);
    callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build();
    OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, initialContext, longRunningClient);
    OperationFuture<Color, Currency> future = callable.futureCall(2, FakeCallContext.createDefault());
    assertFutureCancelMetaCancel(future);
    assertThat(executor.getIterationsCount()).isEqualTo(iterationsCount);
}
Also used : Color(java.awt.Color) Currency(java.util.Currency) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) Test(org.junit.Test)

Example 43 with OperationSnapshot

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

the class OperationCallableImplTest method testFutureCallInitialCancel.

@Test
public void testFutureCallInitialCancel() throws Exception {
    String opName = "testFutureCallInitialCancel";
    OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
    OperationSnapshot resultOperation = getOperation(opName, null, null, null, false);
    UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
    LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, resultOperation);
    OperationCallableImpl<Integer, Color, Currency> callableImpl = Callables.longRunningOperationImpl(initialCallable, callSettings, initialContext, longRunningClient);
    OperationFutureImpl<Color, Currency> future = callableImpl.futureCall(new ListenableFutureToApiFuture<>(Futures.<OperationSnapshot>immediateCancelledFuture()), FakeCallContext.createDefault());
    Exception exception = null;
    try {
        future.get(3, TimeUnit.SECONDS);
    } catch (CancellationException e) {
        exception = e;
    }
    assertThat(exception).isNotNull();
    assertThat(future.isDone()).isTrue();
    assertThat(future.isCancelled()).isTrue();
    assertThat(future.getInitialFuture().isDone()).isTrue();
    assertThat(future.getInitialFuture().isCancelled()).isTrue();
    assertFutureCancelMetaCancel(future);
    assertThat(executor.getIterationsCount()).isEqualTo(0);
}
Also used : CancellationException(java.util.concurrent.CancellationException) Color(java.awt.Color) Currency(java.util.Currency) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 44 with OperationSnapshot

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

the class OperationCallableImplTest method testFutureCallInitialDone.

@Test
public void testFutureCallInitialDone() throws Exception {
    String opName = "testFutureCallInitialDone";
    Color resp = getColor(0.5f);
    Currency meta = Currency.getInstance("UAH");
    OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, true);
    UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, resultOperation);
    LongRunningClient longRunningClient = new UnsupportedOperationApi();
    OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, initialContext, longRunningClient);
    OperationFuture<Color, Currency> future = callable.futureCall(2, FakeCallContext.createDefault());
    assertFutureSuccessMetaSuccess(opName, future, resp, meta);
    assertThat(executor.getIterationsCount()).isEqualTo(0);
}
Also used : Color(java.awt.Color) Currency(java.util.Currency) OperationSnapshot(com.google.api.gax.longrunning.OperationSnapshot) FakeOperationSnapshot(com.google.api.gax.rpc.testing.FakeOperationSnapshot) Test(org.junit.Test)

Example 45 with OperationSnapshot

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

the class ProtoOperationTransformersTest method testAnyResponseTransformer.

@Test
public void testAnyResponseTransformer() {
    ResponseTransformer<Money> transformer = ResponseTransformer.create(Money.class);
    Money inputMoney = Money.newBuilder().setCurrencyCode("USD").build();
    OperationSnapshot operationSnapshot = GrpcOperationSnapshot.create(Operation.newBuilder().setResponse(Any.pack(inputMoney)).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)

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