BigtableVeneerSettingsFactory { public static BigtableDataSettings createBigtableDataSettings( @Nonnull final BigtableOptions options) throws IOException { checkState( options.getRetryOptions().enableRetries(), "Disabling retries is not currently supported."); final BigtableDataSettings.Builder builder = BigtableDataSettings.newBuilder(); final Builder dataSettingStub = builder.stubSettings(); Duration shortRpcTimeoutMs = ofMillis(options.getCallOptionsConfig().getShortRpcTimeoutMs()); builder .setProjectId(options.getProjectId()) .setInstanceId(options.getInstanceId()) .setAppProfileId(options.getAppProfileId()); dataSettingStub .setEndpoint(options.getDataHost() + ":" + options.getPort()) .setHeaderProvider(buildHeaderProvider(options.getUserAgent())) .setCredentialsProvider(buildCredentialProvider(options.getCredentialOptions())); if (options.usePlaintextNegotiation()) { dataSettingStub.setTransportChannelProvider( buildChannelProvider(dataSettingStub.getEndpoint(), options)); } dataSettingStub.checkAndMutateRowSettings().setSimpleTimeoutNoRetries(shortRpcTimeoutMs); dataSettingStub.readModifyWriteRowSettings().setSimpleTimeoutNoRetries(shortRpcTimeoutMs); buildBulkMutationsSettings(dataSettingStub, options); buildReadRowsSettings(dataSettingStub, options); buildReadRowSettings(dataSettingStub, options); buildBulkReadRowsSettings(dataSettingStub, options); buildMutateRowSettings(dataSettingStub, options); buildSampleRowKeysSettings(dataSettingStub, options); return builder.build(); }  static BigtableDataSettings createBigtableDataSettings(
      @Nonnull final BigtableOptions options); static BigtableTableAdminSettings createTableAdminSettings(
      @Nonnull final BigtableOptions options);  }
@Test public void testWhenBulkOptionIsDisabled() throws IOException { BulkOptions bulkOptions = BulkOptions.builder().setUseBulkApi(false).build(); BigtableOptions options = BigtableOptions.builder() .setProjectId(TEST_PROJECT_ID) .setInstanceId(TEST_INSTANCE_ID) .setCredentialOptions(CredentialOptions.nullCredential()) .setBulkOptions(bulkOptions) .build(); dataSettings = BigtableVeneerSettingsFactory.createBigtableDataSettings(options); assertFalse( dataSettings .getStubSettings() .bulkMutateRowsSettings() .getBatchingSettings() .getIsEnabled()); }
@Test public void testBulkMutation() throws IOException { BigtableOptions options = BigtableOptions.builder() .setProjectId(TEST_PROJECT_ID) .setInstanceId(TEST_INSTANCE_ID) .setCredentialOptions(CredentialOptions.nullCredential()) .setUserAgent("Test-user-agent") .build(); dataSettings = BigtableVeneerSettingsFactory.createBigtableDataSettings(options); BulkOptions bulkOptions = options.getBulkOptions(); BatchingSettings batchingSettings = dataSettings.getStubSettings().bulkMutateRowsSettings().getBatchingSettings(); long outstandingElementCount = bulkOptions.getMaxInflightRpcs() * bulkOptions.getBulkMaxRowKeyCount(); assertTrue(batchingSettings.getIsEnabled()); assertEquals( bulkOptions.getBulkMaxRequestSize(), batchingSettings.getRequestByteThreshold().longValue()); assertEquals( bulkOptions.getBulkMaxRowKeyCount(), batchingSettings.getElementCountThreshold().longValue()); assertEquals( bulkOptions.getMaxMemory(), batchingSettings.getFlowControlSettings().getMaxOutstandingRequestBytes().longValue()); assertEquals( outstandingElementCount, batchingSettings.getFlowControlSettings().getMaxOutstandingElementCount().longValue()); }
@Test public void testBulkReadConfig() throws IOException { int maxRowKeyCount = 1_000_000; BigtableOptions options = BigtableOptions.builder() .setProjectId(TEST_PROJECT_ID) .setInstanceId(TEST_INSTANCE_ID) .setCredentialOptions(CredentialOptions.nullCredential()) .setUserAgent("Test-user-agent") .setBulkOptions(BulkOptions.builder().setBulkMaxRowKeyCount(maxRowKeyCount).build()) .build(); dataSettings = BigtableVeneerSettingsFactory.createBigtableDataSettings(options); assertEquals( maxRowKeyCount, dataSettings .getStubSettings() .bulkReadRowsSettings() .getBatchingSettings() .getElementCountThreshold() .intValue()); }
@Test public void testWhenRetriesAreDisabled() throws IOException { RetryOptions retryOptions = RetryOptions.builder().setEnableRetries(false).build(); BigtableOptions options = BigtableOptions.builder() .setProjectId(TEST_PROJECT_ID) .setInstanceId(TEST_INSTANCE_ID) .setRetryOptions(retryOptions) .build(); expectException.expect(IllegalStateException.class); expectException.expectMessage("Disabling retries is not currently supported."); dataSettings = BigtableVeneerSettingsFactory.createBigtableDataSettings(options); }
@Test public void testWithNullCredentials() throws IOException { BigtableOptions options = BigtableOptions.builder() .setProjectId(TEST_PROJECT_ID) .setInstanceId(TEST_INSTANCE_ID) .setCredentialOptions(CredentialOptions.nullCredential()) .setUserAgent(TEST_USER_AGENT) .build(); dataSettings = BigtableVeneerSettingsFactory.createBigtableDataSettings(options); assertTrue( dataSettings.getStubSettings().getCredentialsProvider() instanceof NoCredentialsProvider); }
@Test public void testConfigValues() throws IOException { dataSettings = BigtableVeneerSettingsFactory.createBigtableDataSettings(bigtableOptions); verifyRetry(dataSettings.getStubSettings().sampleRowKeysSettings().getRetrySettings()); assertEquals( DEFAULT_RETRY_CODES, dataSettings.getStubSettings().sampleRowKeysSettings().getRetryableCodes()); verifyRetry(dataSettings.getStubSettings().mutateRowSettings().getRetrySettings()); assertEquals( DEFAULT_RETRY_CODES, dataSettings.getStubSettings().mutateRowSettings().getRetryableCodes()); verifyRetry(dataSettings.getStubSettings().bulkMutateRowsSettings().getRetrySettings()); assertEquals( DEFAULT_RETRY_CODES, dataSettings.getStubSettings().bulkMutateRowsSettings().getRetryableCodes()); verifyRetry(dataSettings.getStubSettings().bulkReadRowsSettings().getRetrySettings()); assertEquals( DEFAULT_RETRY_CODES, dataSettings.getStubSettings().bulkReadRowsSettings().getRetryableCodes()); verifyDisabledRetry( dataSettings.getStubSettings().readModifyWriteRowSettings().getRetrySettings()); assertTrue( dataSettings.getStubSettings().readModifyWriteRowSettings().getRetryableCodes().isEmpty()); verifyDisabledRetry( dataSettings.getStubSettings().checkAndMutateRowSettings().getRetrySettings()); assertTrue( dataSettings.getStubSettings().checkAndMutateRowSettings().getRetryableCodes().isEmpty()); }