use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testFutureCallPollDoneWithError.
@Test
public void testFutureCallPollDoneWithError() throws Exception {
String opName = "testFutureCallPollDoneWithError";
Currency meta = Currency.getInstance("UAH");
Color resp = getColor(1.0f);
OperationSnapshot initialOperation = getOperation(opName, resp, null, meta, false, "Already exists error");
UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
StatusCode errorCode = FakeStatusCode.of(StatusCode.Code.ALREADY_EXISTS);
OperationSnapshot resultOperation = getOperation(opName, null, errorCode, meta, true, "Already exists error");
LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, resultOperation);
OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, initialContext, longRunningClient);
OperationFuture<Color, Currency> future = callable.futureCall(2, FakeCallContext.createDefault());
String errorMessage = "Operation with name \"" + opName + "\" failed with status = " + errorCode + " and message = " + "Already exists error";
assertFutureFailMetaSuccess(future, meta, FakeStatusCode.of(StatusCode.Code.ALREADY_EXISTS), errorMessage);
assertThat(executor.getIterationsCount()).isEqualTo(0);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testFutureCallPollRPCTimeout.
@Test
public void testFutureCallPollRPCTimeout() throws Exception {
String opName = "testFutureCallPollRPCTimeout";
pollingAlgorithm = OperationTimedPollAlgorithm.create(FAST_RECHECKING_SETTINGS.toBuilder().setInitialRpcTimeout(Duration.ofMillis(100)).setMaxRpcTimeout(Duration.ofSeconds(1)).setRpcTimeoutMultiplier(2).setTotalTimeout(Duration.ofSeconds(5L)).build(), clock);
callSettings = callSettings.toBuilder().setPollingAlgorithm(pollingAlgorithm).build();
Color resp = getColor(0.5f);
Currency meta1 = Currency.getInstance("UAH");
Currency meta2 = Currency.getInstance("USD");
OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
OperationSnapshot resultOperation1 = getOperation(opName, null, null, meta1, false);
OperationSnapshot resultOperation2 = getOperation(opName, null, null, meta1, false);
OperationSnapshot resultOperation3 = getOperation(opName, resp, null, meta2, true);
UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
LongRunningClient longRunningClient = Mockito.mock(LongRunningClient.class);
@SuppressWarnings("unchecked") UnaryCallable<String, OperationSnapshot> getOpCallable = Mockito.mock(UnaryCallable.class);
ArgumentCaptor<ApiCallContext> callContextCaptor = ArgumentCaptor.forClass(ApiCallContext.class);
Mockito.when(longRunningClient.getOperationCallable()).thenReturn(getOpCallable);
Mockito.when(getOpCallable.futureCall(Mockito.<String>any(), callContextCaptor.capture())).thenReturn(ApiFutures.immediateFuture(resultOperation1)).thenReturn(ApiFutures.immediateFuture(resultOperation2)).thenReturn(ApiFutures.immediateFuture(resultOperation3));
OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, initialContext, longRunningClient);
callable.futureCall(2, FakeCallContext.createDefault()).get(10, TimeUnit.SECONDS);
List<Duration> actualTimeouts = Lists.newArrayList();
for (ApiCallContext callContext : callContextCaptor.getAllValues()) {
actualTimeouts.add(callContext.getTimeout());
}
List<Duration> expectedTimeouts = Lists.newArrayList(Duration.ofMillis(100), Duration.ofMillis(200), Duration.ofMillis(400));
assertThat(actualTimeouts).isEqualTo(expectedTimeouts);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method setUp.
@Before
public void setUp() throws IOException {
initialChannel = mock(FakeChannel.class);
pollTransportChannel = mock(TransportChannel.class);
TransportChannelProvider operationsChannelProvider = mock(TransportChannelProvider.class);
when(operationsChannelProvider.getTransportChannel()).thenReturn(pollTransportChannel);
clock = new FakeApiClock(0L);
executor = RecordingScheduler.create(clock);
pollingAlgorithm = OperationTimedPollAlgorithm.create(FAST_RECHECKING_SETTINGS, clock);
UnaryCallSettings<Integer, OperationSnapshot> initialCallSettings = UnaryCallSettings.<Integer, OperationSnapshot>newUnaryCallSettingsBuilder().setRetrySettings(FAST_RETRY_SETTINGS.toBuilder().setMaxAttempts(1).build()).build();
callSettings = OperationCallSettings.<Integer, Color, Currency>newBuilder().setInitialCallSettings(initialCallSettings).setResponseTransformer(new ResponseTransformer()).setMetadataTransformer(new MetadataTransformer()).setPollingAlgorithm(pollingAlgorithm).build();
initialContext = getClientContext(initialChannel, executor);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testCall.
@Test
public void testCall() {
Color resp = getColor(1.0f);
Currency meta = Currency.getInstance("UAH");
OperationSnapshot resultOperation = getOperation("testCall", 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);
Color response = callable.call(2, FakeCallContext.createDefault());
Truth.assertThat(response).isEqualTo(resp);
assertThat(executor.getIterationsCount()).isEqualTo(0);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testFutureCallPollCancelOnTimeoutExceeded.
@Test
public void testFutureCallPollCancelOnTimeoutExceeded() throws Exception {
String opName = "testFutureCallPollCancelOnPollingTimeoutExceeded";
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);
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(5);
}
Aggregations