use of com.google.api.gax.rpc.testing.FakeCallContext in project gax-java by googleapis.
the class OperationCallableImplTest method callResumeWithContext.
@Test
public void callResumeWithContext() throws Exception {
FakeChannel channel = new FakeChannel();
Credentials credentials = Mockito.mock(Credentials.class);
ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
OperationStashCallable stashCallable = new OperationStashCallable();
OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
OperationFuture<String, Long> operationFuture = callable.futureCall(45);
String response = callable.resumeFutureCall(operationFuture.getName(), context).get();
Truth.assertThat(response).isEqualTo("45");
FakeCallContext actualContext = (FakeCallContext) stashCallable.getResumeContext();
Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
use of com.google.api.gax.rpc.testing.FakeCallContext in project gax-java by googleapis.
the class UnaryCallableTest method simpleCall.
@Test
public void simpleCall() throws Exception {
StashCallable<Integer, Integer> stashCallable = new StashCallable<>(1);
Integer response = stashCallable.call(2, FakeCallContext.createDefault());
assertEquals(Integer.valueOf(1), response);
FakeCallContext callContext = (FakeCallContext) stashCallable.getContext();
assertNull(callContext.getChannel());
assertNull(callContext.getCredentials());
}
use of com.google.api.gax.rpc.testing.FakeCallContext in project gax-java by googleapis.
the class ServerStreamingCallableTest method testIteratedServerStreamingCallWithContext.
@Test
public void testIteratedServerStreamingCallWithContext() {
FakeChannel channel = new FakeChannel();
Credentials credentials = Mockito.mock(Credentials.class);
ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
ServerStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
Integer request = 1;
callable.call(request, context);
Truth.assertThat(stashCallable.getActualRequest()).isSameInstanceAs(request);
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
use of com.google.api.gax.rpc.testing.FakeCallContext in project gax-java by googleapis.
the class OperationCallableImplTest method mockGetOpSnapshotCallable.
private <RequestT> UnaryCallable<RequestT, OperationSnapshot> mockGetOpSnapshotCallable(final StatusCode.Code returnStatusCode, final OperationSnapshot... results) {
return new UnaryCallable<RequestT, OperationSnapshot>() {
private int index = 0;
@Override
public ApiFuture<OperationSnapshot> futureCall(RequestT request, ApiCallContext context) {
FakeCallContext fakeCallContext = (FakeCallContext) context;
if (fakeCallContext != null && fakeCallContext.getTimeout() != null && fakeCallContext.getTimeout().isZero()) {
throw new DeadlineExceededException("Invalid timeout of 0 s", null, FakeStatusCode.of(StatusCode.Code.DEADLINE_EXCEEDED), true);
}
OperationSnapshot response = results[index];
if (index < results.length - 1) {
index += 1;
}
return newFuture(returnStatusCode, response);
}
};
}
use of com.google.api.gax.rpc.testing.FakeCallContext in project gax-java by googleapis.
the class OperationCallableImplTest method callWithContext.
@Test
public void callWithContext() {
FakeChannel channel = new FakeChannel();
Credentials credentials = Mockito.mock(Credentials.class);
ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
OperationStashCallable stashCallable = new OperationStashCallable();
OperationCallable<Integer, String, Long> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
String response = callable.call(2, context);
Truth.assertThat(response).isEqualTo("2");
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
Truth.assertThat(actualContext.getChannel()).isSameInstanceAs(channel);
Truth.assertThat(actualContext.getCredentials()).isSameInstanceAs(credentials);
}
Aggregations