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