Search in sources :

Example 11 with FakeCallContext

use of com.google.api.gax.rpc.testing.FakeCallContext 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 12 with FakeCallContext

use of com.google.api.gax.rpc.testing.FakeCallContext 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)12 Test (org.junit.Test)11 Credentials (com.google.auth.Credentials)10 FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)9 ServerStreamingStashCallable (com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable)4 OperationStashCallable (com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable)3 StashCallable (com.google.api.gax.rpc.testing.FakeSimpleApi.StashCallable)3 RetrySettings (com.google.api.gax.retrying.RetrySettings)2 OperationSnapshot (com.google.api.gax.longrunning.OperationSnapshot)1 Code (com.google.api.gax.rpc.StatusCode.Code)1 FakeOperationSnapshot (com.google.api.gax.rpc.testing.FakeOperationSnapshot)1 FakeStatusCode (com.google.api.gax.rpc.testing.FakeStatusCode)1 ClientStreamingStashCallable (com.google.api.gax.rpc.testing.FakeStreamingApi.ClientStreamingStashCallable)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1