use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ClientContextTest method testUserAgentExternalOnly.
@Test
public void testUserAgentExternalOnly() throws Exception {
TransportChannelProvider transportChannelProvider = new FakeTransportProvider(FakeTransportChannel.create(new FakeChannel()), null, true, null, null);
ClientSettings.Builder builder = new FakeClientSettings.Builder().setExecutorProvider(FixedExecutorProvider.create(Mockito.mock(ScheduledExecutorService.class))).setTransportChannelProvider(transportChannelProvider).setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(GoogleCredentials.class)));
builder.setHeaderProvider(FixedHeaderProvider.create("user-agent", "user-supplied-agent"));
ClientContext clientContext = ClientContext.create(builder.build());
FakeTransportChannel transportChannel = (FakeTransportChannel) clientContext.getTransportChannel();
assertThat(transportChannel.getHeaders()).containsEntry("user-agent", "user-supplied-agent");
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class RetryingTest method resetClock.
@Before
public void resetClock() {
fakeClock = new FakeApiClock(System.nanoTime());
executor = RecordingScheduler.create(fakeClock);
clientContext = ClientContext.newBuilder().setExecutor(executor).setClock(fakeClock).setDefaultCallContext(FakeCallContext.createDefault()).setTransportChannel(FakeTransportChannel.create(new FakeChannel())).build();
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ServerStreamingCallableTest method testIteratedServerStreamingCallWithContext.
@Test
public void testIteratedServerStreamingCallWithContext() {
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());
Integer request = 1;
callable.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);
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class GrpcCallContextTest method testWithTransportChannelWrongType.
@Test
public void testWithTransportChannelWrongType() {
FakeChannel channel = new FakeChannel();
try {
GrpcCallContext.createDefault().withTransportChannel(FakeTransportChannel.create(channel));
Assert.fail("GrpcCallContext should have thrown an exception");
} catch (IllegalArgumentException expected) {
Truth.assertThat(expected).hasMessageThat().contains("Expected GrpcTransportChannel");
}
}
use of com.google.api.gax.rpc.testing.FakeChannel in project gax-java by googleapis.
the class ClientContextTest method testExecutorSettings.
@Test
public void testExecutorSettings() throws Exception {
TransportChannelProvider transportChannelProvider = new FakeTransportProvider(FakeTransportChannel.create(new FakeChannel()), null, true, null, null);
ClientSettings.Builder builder = new FakeClientSettings.Builder().setTransportChannelProvider(transportChannelProvider).setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(GoogleCredentials.class)));
// By default, if executor is not set, channel provider should not have an executor set
ClientContext context = ClientContext.create(builder.build());
FakeTransportChannel transportChannel = (FakeTransportChannel) context.getTransportChannel();
assertThat(transportChannel.getExecutor()).isNull();
ExecutorProvider channelExecutorProvider = FixedExecutorProvider.create(Mockito.mock(ScheduledExecutorService.class));
builder.setTransportChannelProvider(transportChannelProvider.withExecutor((Executor) channelExecutorProvider.getExecutor()));
context = ClientContext.create(builder.build());
transportChannel = (FakeTransportChannel) context.getTransportChannel();
assertThat(transportChannel.getExecutor()).isSameInstanceAs(channelExecutorProvider.getExecutor());
ExecutorProvider executorProvider = FixedExecutorProvider.create(Mockito.mock(ScheduledExecutorService.class));
assertThat(channelExecutorProvider.getExecutor()).isNotSameInstanceAs(executorProvider.getExecutor());
// For backward compatibility, if executor is set from stubSettings.setExecutor, and transport
// channel already has an executor, the ExecutorProvider set in stubSettings won't override
// transport channel's executor
builder.setExecutorProvider(executorProvider);
context = ClientContext.create(builder.build());
transportChannel = (FakeTransportChannel) context.getTransportChannel();
assertThat(transportChannel.getExecutor()).isSameInstanceAs(channelExecutorProvider.getExecutor());
// For backward compatibility, if executor is set from stubSettings.setExecutor, and transport
// channel doesn't have an executor, transport channel will get the executor from
// stubSettings.setExecutor
builder.setExecutorProvider(executorProvider);
builder.setTransportChannelProvider(new FakeTransportProvider(FakeTransportChannel.create(new FakeChannel()), null, true, null, null));
context = ClientContext.create(builder.build());
transportChannel = (FakeTransportChannel) context.getTransportChannel();
assertThat(transportChannel.getExecutor()).isSameInstanceAs(executorProvider.getExecutor());
}
Aggregations