Search in sources :

Example 1 with BigtableOptions

use of com.google.cloud.bigtable.config.BigtableOptions 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").getBigtableConfig().getBigtableService(pipelineOptions);
    BigtableService writeService = BigtableIO.write().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableConfig().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)

Example 2 with BigtableOptions

use of com.google.cloud.bigtable.config.BigtableOptions 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").getBigtableConfig().getBigtableService(pipelineOptions);
    BigtableService writeService = BigtableIO.write().withBigtableOptions(options).withTableId("TEST-TABLE").getBigtableConfig().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 3 with BigtableOptions

use of com.google.cloud.bigtable.config.BigtableOptions in project beam by apache.

the class BigtableIOTest method testWriteWithBigTableOptionsSetsBulkOptionsAndRetryOptions.

@Test
public void testWriteWithBigTableOptionsSetsBulkOptionsAndRetryOptions() {
    final int maxInflightRpcs = 1;
    final int initialBackoffMillis = -1;
    BigtableOptions.Builder optionsBuilder = BIGTABLE_OPTIONS.toBuilder();
    BulkOptions.Builder bulkOptionsBuilder = new BulkOptions.Builder();
    bulkOptionsBuilder.setMaxInflightRpcs(maxInflightRpcs);
    RetryOptions.Builder retryOptionsBuilder = new RetryOptions.Builder();
    retryOptionsBuilder.setInitialBackoffMillis(initialBackoffMillis);
    optionsBuilder.setBulkOptions(bulkOptionsBuilder.build()).setRetryOptions(retryOptionsBuilder.build());
    BigtableIO.Write write = BigtableIO.write().withBigtableOptions(optionsBuilder.build());
    BigtableOptions options = write.getBigtableOptions();
    assertTrue(options.getBulkOptions().useBulkApi());
    assertEquals(maxInflightRpcs, options.getBulkOptions().getMaxInflightRpcs());
    assertEquals(initialBackoffMillis, options.getRetryOptions().getInitialBackoffMillis());
    assertThat(options.getBulkOptions(), Matchers.equalTo(bulkOptionsBuilder.setUseBulkApi(true).build()));
    assertThat(options.getRetryOptions(), Matchers.equalTo(retryOptionsBuilder.build()));
}
Also used : BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) RetryOptions(com.google.cloud.bigtable.config.RetryOptions) BulkOptions(com.google.cloud.bigtable.config.BulkOptions) Test(org.junit.Test)

Example 4 with BigtableOptions

use of com.google.cloud.bigtable.config.BigtableOptions in project simple-bigtable by spotify.

the class BigtableMock method getMock.

public static BigtableMock getMock() {
    final BigtableDataClient dataClient = Mockito.mock(BigtableDataClient.class);
    final BigtableTableAdminClient tableAdminClient = Mockito.mock(BigtableTableAdminClient.class);
    final BigtableSession session = Mockito.mock(BigtableSession.class);
    final BigtableOptions options = Mockito.mock(BigtableOptions.class);
    try {
        Mockito.when(session.getDataClient()).thenReturn(dataClient);
        Mockito.when(session.getTableAdminClient()).thenReturn(tableAdminClient);
        Mockito.when(session.getOptions()).thenReturn(options);
        Mockito.when(options.getInstanceName()).thenReturn(new BigtableInstanceName(PROJECT_ID, INSTANCE_ID));
    } catch (IOException e) {
        Throwables.propagate(e);
    }
    return new BigtableMock(session, PROJECT_ID, INSTANCE_ID);
}
Also used : BigtableInstanceName(com.google.cloud.bigtable.grpc.BigtableInstanceName) BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) BigtableTableAdminClient(com.google.cloud.bigtable.grpc.BigtableTableAdminClient) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.grpc.BigtableDataClient)

Example 5 with BigtableOptions

use of com.google.cloud.bigtable.config.BigtableOptions in project beam by apache.

the class BigtableWriteIT method setup.

@Before
public void setup() throws Exception {
    PipelineOptionsFactory.register(BigtableTestOptions.class);
    options = TestPipeline.testingPipelineOptions().as(BigtableTestOptions.class);
    project = options.as(GcpOptions.class).getProject();
    bigtableOptions = new BigtableOptions.Builder().setProjectId(project).setInstanceId(options.getInstanceId()).setUserAgent("apache-beam-test").build();
    session = new BigtableSession(bigtableOptions.toBuilder().setCredentialOptions(CredentialOptions.credential(options.as(GcpOptions.class).getGcpCredential())).build());
    tableAdminClient = session.getTableAdminClient();
}
Also used : BigtableOptions(com.google.cloud.bigtable.config.BigtableOptions) BigtableSession(com.google.cloud.bigtable.grpc.BigtableSession) Before(org.junit.Before)

Aggregations

BigtableOptions (com.google.cloud.bigtable.config.BigtableOptions)7 Test (org.junit.Test)4 RetryOptions (com.google.cloud.bigtable.config.RetryOptions)2 BigtableSession (com.google.cloud.bigtable.grpc.BigtableSession)2 TestCredential (org.apache.beam.sdk.extensions.gcp.auth.TestCredential)2 GcpOptions (org.apache.beam.sdk.extensions.gcp.options.GcpOptions)2 Before (org.junit.Before)2 BulkOptions (com.google.cloud.bigtable.config.BulkOptions)1 BigtableDataClient (com.google.cloud.bigtable.grpc.BigtableDataClient)1 BigtableInstanceName (com.google.cloud.bigtable.grpc.BigtableInstanceName)1 BigtableTableAdminClient (com.google.cloud.bigtable.grpc.BigtableTableAdminClient)1 IOException (java.io.IOException)1 MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)1