use of com.google.api.gax.rpc.testing.FakeCallContext in project gax-java by googleapis.
the class OperationCallableImplTest method callCancelWithContext.
@Test
public void callCancelWithContext() 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);
callable.cancel(operationFuture.getName(), context).get();
Truth.assertThat(stashCallable.wasCancelCalled()).isTrue();
FakeCallContext actualContext = (FakeCallContext) stashCallable.getCancelContext();
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 ServerStreamingCallableTest method testServerStreamingCallWithContext.
@Test
public void testServerStreamingCallWithContext() {
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());
@SuppressWarnings("unchecked") ResponseObserver<Integer> observer = Mockito.mock(StateCheckingResponseObserver.class);
Integer request = 1;
callable.call(request, observer, context);
Truth.assertThat(stashCallable.getActualObserver()).isSameInstanceAs(observer);
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 ServerStreamingCallableTest method testAllElementCallWithContext.
@Test
public void testAllElementCallWithContext() {
FakeChannel channel = new FakeChannel();
Credentials credentials = Mockito.mock(Credentials.class);
ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
UnaryCallable<Integer, List<Integer>> firstCallable = stashCallable.all().withDefaultCallContext(FakeCallContext.createDefault());
Integer request = 1;
firstCallable.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 ServerStreamingCallableTest method testFirstElementCallWithContext.
@Test
public void testFirstElementCallWithContext() {
FakeChannel channel = new FakeChannel();
Credentials credentials = Mockito.mock(Credentials.class);
ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials);
ServerStreamingStashCallable<Integer, Integer> stashCallable = new ServerStreamingStashCallable<>();
UnaryCallable<Integer, Integer> firstCallable = stashCallable.first().withDefaultCallContext(FakeCallContext.createDefault());
Integer request = 1;
firstCallable.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 StreamingCallableTest method testClientStreamingCallWithContext.
@Test
@SuppressWarnings("unchecked")
public void testClientStreamingCallWithContext() {
FakeChannel channel = new FakeChannel();
Credentials credentials = Mockito.mock(Credentials.class);
RetrySettings retrySettings = Mockito.mock(RetrySettings.class);
Set<StatusCode.Code> retryableCodes = ImmutableSet.of(StatusCode.Code.INTERNAL, StatusCode.Code.UNAVAILABLE, StatusCode.Code.DEADLINE_EXCEEDED);
ApiCallContext context = FakeCallContext.createDefault().withChannel(channel).withCredentials(credentials).withRetrySettings(retrySettings).withRetryableCodes(retryableCodes);
ClientStreamingStashCallable<Integer, Integer> stashCallable = new ClientStreamingStashCallable<>();
ApiStreamObserver<Integer> observer = Mockito.mock(ApiStreamObserver.class);
ClientStreamingCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
callable.clientStreamingCall(observer, context);
assertSame(observer, stashCallable.getActualObserver());
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
assertSame(channel, actualContext.getChannel());
assertSame(credentials, actualContext.getCredentials());
assertSame(retrySettings, actualContext.getRetrySettings());
assertSame(retryableCodes, actualContext.getRetryableCodes());
}
Aggregations