Search in sources :

Example 6 with FakeChannel

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

the class ClientContextTest method testUserAgentConcat.

@Test
public void testUserAgentConcat() 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"));
    builder.setInternalHeaderProvider(FixedHeaderProvider.create("user-agent", "internal-agent"));
    ClientContext clientContext = ClientContext.create(builder.build());
    FakeTransportChannel transportChannel = (FakeTransportChannel) clientContext.getTransportChannel();
    assertThat(transportChannel.getHeaders()).containsEntry("user-agent", "user-supplied-agent internal-agent");
}
Also used : FakeTransportChannel(com.google.api.gax.rpc.testing.FakeTransportChannel) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 7 with FakeChannel

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

the class ClientContextTest method testHidingQuotaProjectId_noQuotaSetFromSetting.

@Test
public void testHidingQuotaProjectId_noQuotaSetFromSetting() throws IOException {
    FakeClientSettings.Builder builder = new FakeClientSettings.Builder();
    InterceptingExecutor executor = new InterceptingExecutor(1);
    FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
    FakeTransportProvider transportProvider = new FakeTransportProvider(transportChannel, executor, true, null, null);
    Map<String, List<String>> metaData = ImmutableMap.of("k1", Collections.singletonList("v1"));
    final Credentials credentialsWithoutQuotaProjectId = Mockito.mock(GoogleCredentials.class);
    Mockito.when(credentialsWithoutQuotaProjectId.getRequestMetadata(null)).thenReturn(metaData);
    HeaderProvider headerProviderWithQuota = Mockito.mock(HeaderProvider.class);
    HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class);
    builder.setExecutorProvider(new FakeExecutorProvider(executor, true));
    builder.setTransportChannelProvider(transportProvider);
    builder.setCredentialsProvider(new CredentialsProvider() {

        @Override
        public Credentials getCredentials() throws IOException {
            return credentialsWithoutQuotaProjectId;
        }
    });
    builder.setHeaderProvider(headerProviderWithQuota);
    builder.setInternalHeaderProvider(internalHeaderProvider);
    ClientContext clientContext = ClientContext.create(builder.build());
    assertThat(clientContext.getCredentials().getRequestMetadata(null)).isEqualTo(metaData);
}
Also used : FakeTransportChannel(com.google.api.gax.rpc.testing.FakeTransportChannel) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) FixedCredentialsProvider(com.google.api.gax.core.FixedCredentialsProvider) CredentialsProvider(com.google.api.gax.core.CredentialsProvider) IOException(java.io.IOException) List(java.util.List) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Credentials(com.google.auth.Credentials) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 8 with FakeChannel

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

the class ClientContextTest method testUserAgentInternalOnly.

@Test
public void testUserAgentInternalOnly() 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.setInternalHeaderProvider(FixedHeaderProvider.create("user-agent", "internal-agent"));
    ClientContext clientContext = ClientContext.create(builder.build());
    FakeTransportChannel transportChannel = (FakeTransportChannel) clientContext.getTransportChannel();
    assertThat(transportChannel.getHeaders()).containsEntry("user-agent", "internal-agent");
}
Also used : FakeTransportChannel(com.google.api.gax.rpc.testing.FakeTransportChannel) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 9 with FakeChannel

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

the class ClientContextTest method testMergeHeaders_noQuotaProjectIdSet.

@Test
public void testMergeHeaders_noQuotaProjectIdSet() throws IOException {
    final String QUOTA_PROJECT_ID_KEY = "x-goog-user-project";
    FakeClientSettings.Builder builder = new FakeClientSettings.Builder();
    InterceptingExecutor executor = new InterceptingExecutor(1);
    FakeTransportChannel transportChannel = FakeTransportChannel.create(new FakeChannel());
    FakeTransportProvider transportProvider = new FakeTransportProvider(transportChannel, executor, true, null, null);
    HeaderProvider headerProvider = Mockito.mock(HeaderProvider.class);
    Mockito.when(headerProvider.getHeaders()).thenReturn(ImmutableMap.of("header_k1", "v1"));
    HeaderProvider internalHeaderProvider = Mockito.mock(HeaderProvider.class);
    Mockito.when(internalHeaderProvider.getHeaders()).thenReturn(ImmutableMap.of("internal_header_k1", "v1"));
    builder.setTransportChannelProvider(transportProvider);
    builder.setCredentialsProvider(FixedCredentialsProvider.create(Mockito.mock(Credentials.class)));
    builder.setHeaderProvider(headerProvider);
    builder.setInternalHeaderProvider(internalHeaderProvider);
    ClientContext context = ClientContext.create(builder.build());
    List<BackgroundResource> resources = context.getBackgroundResources();
    FakeTransportChannel fakeTransportChannel = (FakeTransportChannel) resources.get(0);
    assertThat(fakeTransportChannel.getHeaders().size()).isEqualTo(headerProvider.getHeaders().size() + internalHeaderProvider.getHeaders().size());
    assertThat(fakeTransportChannel.getHeaders().containsKey(QUOTA_PROJECT_ID_KEY)).isFalse();
}
Also used : FakeTransportChannel(com.google.api.gax.rpc.testing.FakeTransportChannel) FakeClientSettings(com.google.api.gax.rpc.testing.FakeClientSettings) BackgroundResource(com.google.api.gax.core.BackgroundResource) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Test(org.junit.Test)

Example 10 with FakeChannel

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

the class BatchingTest method setUp.

@Before
public void setUp() {
    batchingExecutor = new ScheduledThreadPoolExecutor(1);
    clientContext = ClientContext.newBuilder().setExecutor(batchingExecutor).setDefaultCallContext(FakeCallContext.createDefault()).setTransportChannel(FakeTransportChannel.create(new FakeChannel())).build();
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) FakeChannel(com.google.api.gax.rpc.testing.FakeChannel) Before(org.junit.Before)

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