use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testFutureCancelImmediately.
@Test
public void testFutureCancelImmediately() throws Exception {
int iterationsCount = 3;
String opName = "testCancelImmediately";
Color resp = getColor(0.5f);
Currency meta = Currency.getInstance("UAH");
OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
OperationSnapshot[] pollOperations = new OperationSnapshot[iterationsCount];
for (int i = 0; i < iterationsCount; i++) {
pollOperations[i] = getOperation(opName, null, null, null, false);
}
pollOperations[iterationsCount - 1] = getOperation(opName, resp, null, meta, true);
LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, pollOperations);
CountDownLatch retryScheduledLatch = new CountDownLatch(1);
LatchCountDownScheduler scheduler = LatchCountDownScheduler.get(retryScheduledLatch, 0L, 20L);
ClientContext schedulerContext = getClientContext(initialChannel, scheduler);
OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, schedulerContext, longRunningClient);
OperationFuture<Color, Currency> future = callable.futureCall(2, FakeCallContext.createDefault());
while (!future.cancel(true) && !future.isDone()) {
LockSupport.parkNanos(1000L);
}
assertFutureCancelMetaCancel(future);
scheduler.shutdownNow();
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testFutureCallPollDoneOnFirst.
@Test
public void testFutureCallPollDoneOnFirst() throws Exception {
String opName = "testFutureCallPollDoneOnFirst";
Color resp = getColor(0.5f);
Currency meta = Currency.getInstance("UAH");
OperationSnapshot initialOperation = getOperation(opName, null, null, null, false);
OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, true);
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());
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 OperationCallableImplTest method testFutureCallPollError.
@Test
public void testFutureCallPollError() throws Exception {
String opName = "testFutureCallPollError";
Currency meta = Currency.getInstance("UAH");
Color resp = getColor(1.0f);
OperationSnapshot initialOperation = getOperation(opName, resp, null, meta, false);
UnaryCallable<Integer, OperationSnapshot> initialCallable = mockGetOpSnapshotCallable(StatusCode.Code.OK, initialOperation);
OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, false);
LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.ALREADY_EXISTS, resultOperation);
OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(initialCallable, callSettings, initialContext, longRunningClient);
OperationFuture<Color, Currency> future = callable.futureCall(2, FakeCallContext.createDefault());
assertFutureFailMetaFail(future, null, FakeStatusCode.of(StatusCode.Code.ALREADY_EXISTS));
assertThat(executor.getIterationsCount()).isEqualTo(0);
}
use of com.google.api.gax.longrunning.OperationSnapshot in project gax-java by googleapis.
the class OperationCallableImplTest method testResumeFutureCall.
@Test
public void testResumeFutureCall() throws Exception {
String opName = "testResumeFutureCall";
Color resp = getColor(0.5f);
Currency meta = Currency.getInstance("UAH");
OperationSnapshot resultOperation = getOperation(opName, resp, null, meta, true);
LongRunningClient longRunningClient = mockGetOperation(StatusCode.Code.OK, resultOperation);
ClientContext mockContext = getClientContext(new FakeChannel(), executor);
OperationCallable<Integer, Color, Currency> callable = FakeCallableFactory.createOperationCallable(getUnexpectedStartCallable(), callSettings, mockContext, longRunningClient);
OperationFuture<Color, Currency> future = callable.resumeFutureCall(opName);
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 OperationCallableImplTest method testInitialServerSideCancel.
@Test
public void testInitialServerSideCancel() throws Exception {
String opName = "testInitialServerSideCancel";
StatusCode errorCode = FakeStatusCode.of(StatusCode.Code.CANCELLED);
Currency meta = Currency.getInstance("UAH");
OperationSnapshot resultOperation = getOperation(opName, null, errorCode, 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());
String errorMessage = "Operation with name \"" + opName + "\" failed with status = " + errorCode + " and message = " + "null";
assertFutureFailMetaSuccess(future, meta, FakeStatusCode.of(StatusCode.Code.CANCELLED), errorMessage);
assertThat(executor.getIterationsCount()).isEqualTo(0);
}
Aggregations