use of com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable 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.FakeSimpleApi.StashCallable in project gax-java by googleapis.
the class UnaryCallableTest method callWithContext.
@Test
public void callWithContext() throws Exception {
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);
StashCallable<Integer, Integer> stashCallable = new StashCallable<>(1);
UnaryCallable<Integer, Integer> callable = stashCallable.withDefaultCallContext(FakeCallContext.createDefault());
Integer response = callable.call(2, context);
assertEquals(Integer.valueOf(1), response);
FakeCallContext actualContext = (FakeCallContext) stashCallable.getContext();
assertSame(channel, actualContext.getChannel());
assertSame(credentials, actualContext.getCredentials());
assertSame(retrySettings, actualContext.getRetrySettings());
assertThat(actualContext.getRetryableCodes()).containsExactlyElementsIn(retryableCodes);
}
use of com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable in project gax-java by googleapis.
the class AuthCallableTest method testAuth.
@Test
public void testAuth() throws InterruptedException, ExecutionException, CancellationException {
StashCallable<Integer, Integer> stash = new StashCallable<>(42);
Truth.assertThat(stash.getContext()).isNull();
UnaryCallSettings<Integer, Integer> callSettings = UnaryCallSettings.<Integer, Integer>newUnaryCallSettingsBuilder().build();
UnaryCallable<Integer, Integer> callable = FakeCallableFactory.createUnaryCallable(stash, callSettings, clientContext.toBuilder().setCredentials(Mockito.mock(Credentials.class)).build());
Truth.assertThat(callable.futureCall(0).get()).isEqualTo(42);
Truth.assertThat(stash.getContext()).isNotNull();
FakeCallContext callContext = (FakeCallContext) stash.getContext();
Truth.assertThat(callContext.getCredentials()).isNotNull();
}
Aggregations