Search in sources :

Example 1 with GcpOptions

use of org.apache.beam.sdk.extensions.gcp.options.GcpOptions in project beam by apache.

the class BigtableIOTest method testUsePipelineOptionsCredentialsIfNotSpecifiedInBigtableOptions.

/** Tests that credentials are used from PipelineOptions if not supplied by BigtableOptions. */
@Test
public void testUsePipelineOptionsCredentialsIfNotSpecifiedInBigtableOptions() throws Exception {
    BigtableOptions options = BIGTABLE_OPTIONS.toBuilder().setCredentialOptions(CredentialOptions.defaultCredentials()).build();
    GcpOptions pipelineOptions = PipelineOptionsFactory.as(GcpOptions.class);
    pipelineOptions.setGcpCredential(new TestCredential());
    BigtableService readService = BigtableIO.read().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    BigtableService writeService = BigtableIO.write().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    assertEquals(CredentialType.SuppliedCredentials, readService.getBigtableOptions().getCredentialOptions().getCredentialType());
    assertEquals(CredentialType.SuppliedCredentials, writeService.getBigtableOptions().getCredentialOptions().getCredentialType());
}
Also used : GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) Test(org.junit.Test)

Example 2 with GcpOptions

use of org.apache.beam.sdk.extensions.gcp.options.GcpOptions in project beam by apache.

the class BigtableIOTest method testDontUsePipelineOptionsCredentialsIfSpecifiedInBigtableOptions.

/** Tests that credentials are not used from PipelineOptions if supplied by BigtableOptions. */
@Test
public void testDontUsePipelineOptionsCredentialsIfSpecifiedInBigtableOptions() throws Exception {
    BigtableOptions options = BIGTABLE_OPTIONS.toBuilder().setCredentialOptions(CredentialOptions.nullCredential()).build();
    GcpOptions pipelineOptions = PipelineOptionsFactory.as(GcpOptions.class);
    pipelineOptions.setGcpCredential(new TestCredential());
    BigtableService readService = BigtableIO.read().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    BigtableService writeService = BigtableIO.write().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableService(pipelineOptions);
    assertEquals(CredentialType.None, readService.getBigtableOptions().getCredentialOptions().getCredentialType());
    assertEquals(CredentialType.None, writeService.getBigtableOptions().getCredentialOptions().getCredentialType());
}
Also used : GcpOptions(org.apache.beam.sdk.extensions.gcp.options.GcpOptions) TestCredential(org.apache.beam.sdk.extensions.gcp.auth.TestCredential) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) Test(org.junit.Test)

Aggregations

BigtableOptions (com.google.cloud.bigtable.config.BigtableOptions)2 TestCredential (org.apache.beam.sdk.extensions.gcp.auth.TestCredential)2 GcpOptions (org.apache.beam.sdk.extensions.gcp.options.GcpOptions)2 Test (org.junit.Test)2