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