Search in sources :

Example 6 with FakeCallContext

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

Example 7 with FakeCallContext

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

Example 8 with FakeCallContext

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);
}
Also used : FakeCallContext(com.google.api.gax.rpc.testing.FakeCallContext) ServerStreamingStashCallable(com.google.api.gax.rpc.testing.FakeStreamingApi.ServerStreamingStashCallable) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 9 with FakeCallContext

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

Example 10 with FakeCallContext

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());
}
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)

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