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