Search in sources :

Example 26 with FakeChannel

use of com.google.api.gax.rpc.testing.FakeChannel 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());
}
Also used : ClientStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ClientStreamingStashCallable) RetrySettings(com.google.api.gax.retrying.RetrySettings) FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) FakeStatusCode(com.google.api.gax.rpc.testing.FakeStatusCode) Code(com.google.api.gax.rpc.StatusCode.Code) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 27 with FakeChannel

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

use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.

the class HttpJsonCallContextTest method testWithTransportChannelWrongType.

@Test
public void testWithTransportChannelWrongType() {
    try {
        FakeChannel channel = new FakeChannel();
        HttpJsonCallContext.createDefault().withTransportChannel(FakeTransportChannel.create(channel));
        Assert.fail("HttpJsonCallContext should have thrown an exception");
    } catch (IllegalArgumentException expected) {
        Truth.assertThat(expected).hasMessageThat().contains("Expected HttpJsonTransportChannel");
    }
}
Also used : FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Aggregations

FakeChannel (com.google.api.gax.rpc.testing.FakeChannel)28 Test (org.junit.Test)24 FakeTransportChannel (com.google.api.gax.rpc.testing.FakeTransportChannel)12 Credentials (com.google.auth.Credentials)12 FakeClientSettings (com.google.api.gax.rpc.testing.FakeClientSettings)11 FakeCallContext (com.google.api.gax.rpc.testing.FakeCallContext)9 BackgroundResource (com.google.api.gax.core.BackgroundResource)5 ServerStreamingStashCallable (com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable)4 OperationStashCallable (com.google.api.gax.rpc.testing.FakeOperationApi.OperationStashCallable)3 GoogleCredentials (com.google.auth.oauth2.GoogleCredentials)3 List (java.util.List)3 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)3 Before (org.junit.Before)3 ApiClock (com.google.api.core.ApiClock)2 CredentialsProvider (com.google.api.gax.core.CredentialsProvider)2 ExecutorProvider (com.google.api.gax.core.ExecutorProvider)2 FakeApiClock (com.google.api.gax.core.FakeApiClock)2 FixedCredentialsProvider (com.google.api.gax.core.FixedCredentialsProvider)2 FixedExecutorProvider (com.google.api.gax.core.FixedExecutorProvider)2 RetrySettings (com.google.api.gax.retrying.RetrySettings)2