Search in sources :

Example 1 with StashCallable

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());
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) StashCallable(com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable) Test(org.junit.Test)

Example 2 with StashCallable

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);
}
Also used : RetrySettings(com.google.api.gax.retrying.RetrySettings) FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) StashCallable(com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable) Test(org.junit.Test)

Example 3 with StashCallable

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();
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) Credentials(com.google.auth.Credentials) StashCallable(com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable) Test(org.junit.Test)

Aggregations

FakeCallContext (com.google.api.gax.rpc.testing.FakeCallContext)3 StashCallable (com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable)3 Test (org.junit.Test)3 Credentials (com.google.auth.Credentials)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)1 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)1