BigtableOptionsFactory { public static BigtableOptions fromConfiguration(final Configuration configuration) throws IOException { BigtableOptions.Builder bigtableOptionsBuilder = BigtableOptions.builder(); bigtableOptionsBuilder.setProjectId(getValue(configuration, PROJECT_ID_KEY, "Project ID")); bigtableOptionsBuilder.setInstanceId(getValue(configuration, INSTANCE_ID_KEY, "Instance ID")); String appProfileId = configuration.get(APP_PROFILE_ID_KEY); if (appProfileId != null) { bigtableOptionsBuilder.setAppProfileId(appProfileId); } String dataHostOverride = configuration.get(BIGTABLE_HOST_KEY); if (dataHostOverride != null) { LOG.debug("API Data endpoint host %s.", dataHostOverride); bigtableOptionsBuilder.setDataHost(dataHostOverride); } String adminHostOverride = configuration.get(BIGTABLE_ADMIN_HOST_KEY); if (adminHostOverride != null) { LOG.debug("Admin endpoint host %s.", adminHostOverride); bigtableOptionsBuilder.setAdminHost(adminHostOverride); } String portOverrideStr = configuration.get(BIGTABLE_PORT_KEY); if (portOverrideStr != null) { bigtableOptionsBuilder.setPort(Integer.parseInt(portOverrideStr)); } String usePlaintextStr = configuration.get(BIGTABLE_USE_PLAINTEXT_NEGOTIATION); if (usePlaintextStr != null) { bigtableOptionsBuilder.setUsePlaintextNegotiation(Boolean.parseBoolean(usePlaintextStr)); } setBulkOptions(configuration, bigtableOptionsBuilder); setChannelOptions(configuration, bigtableOptionsBuilder); setClientCallOptions(configuration, bigtableOptionsBuilder); String emulatorHost = configuration.get(BIGTABLE_EMULATOR_HOST_KEY); if (emulatorHost != null) { bigtableOptionsBuilder.enableEmulator(emulatorHost); } String useBatchStr = configuration.get(BIGTABLE_USE_BATCH); if (useBatchStr != null) { bigtableOptionsBuilder.setUseBatch(Boolean.parseBoolean(useBatchStr)); } String useGcjClientStr = configuration.get(BIGTABLE_USE_GCJ_CLIENT); if (useGcjClientStr != null) { bigtableOptionsBuilder.setUseGCJClient(Boolean.parseBoolean(useGcjClientStr)); } return bigtableOptionsBuilder.build(); }  static BigtableOptions fromConfiguration(final Configuration configuration); static final String BIGTABLE_PORT_KEY; static final String BIGTABLE_ADMIN_HOST_KEY; static final String BIGTABLE_HOST_KEY; static final String BIGTABLE_EMULATOR_HOST_KEY; static final String PROJECT_ID_KEY; static final String INSTANCE_ID_KEY; static final String APP_PROFILE_ID_KEY; static final String BIGTABLE_SNAPSHOT_CLUSTER_ID_KEY; static final String BIGTABLE_SNAPSHOT_DEFAULT_TTL_SECS_KEY; static final String CUSTOM_USER_AGENT_KEY; static final String BIGTABLE_USE_SERVICE_ACCOUNTS_KEY; static final boolean BIGTABLE_USE_SERVICE_ACCOUNTS_DEFAULT; static final String BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY; static final boolean BIGTABLE_NULL_CREDENTIAL_ENABLE_DEFAULT; static final String BIGTABLE_SERVICE_ACCOUNT_EMAIL_KEY; static final String BIGTABLE_SERVICE_ACCOUNT_P12_KEYFILE_LOCATION_KEY; static final String BIGTABLE_SERVICE_ACCOUNT_JSON_KEYFILE_LOCATION_KEY; static final String BIGTABLE_SERVICE_ACCOUNT_JSON_VALUE_KEY; static final String ENABLE_GRPC_RETRIES_KEY; static final String ALLOW_NO_TIMESTAMP_RETRIES_KEY; static final String ADDITIONAL_RETRY_CODES; static final String ENABLE_GRPC_RETRY_DEADLINEEXCEEDED_KEY; static final String INITIAL_ELAPSED_BACKOFF_MILLIS_KEY; static final String MAX_ELAPSED_BACKOFF_MILLIS_KEY; static final String READ_PARTIAL_ROW_TIMEOUT_MS; static final String MAX_SCAN_TIMEOUT_RETRIES; static final String READ_BUFFER_SIZE; static final String BIGTABLE_DATA_CHANNEL_COUNT_KEY; static final String BIGTABLE_USE_BULK_API; static final String BIGTABLE_USE_BATCH; static final String BIGTABLE_BULK_MAX_REQUEST_SIZE_BYTES; static final String BIGTABLE_BULK_MAX_ROW_KEY_COUNT; static final String BIGTABLE_BULK_AUTOFLUSH_MS_KEY; static final String MAX_INFLIGHT_RPCS_KEY; static final String BIGTABLE_BUFFERED_MUTATOR_MAX_MEMORY_KEY; @Deprecated
  static final String BIGTABLE_BUFFERED_MUTATOR_ENABLE_THROTTLING; @Deprecated
  static final String BIGTABLE_BUFFERED_MUTATOR_THROTTLING_THRESHOLD_MILLIS; static final String BIGTABLE_USE_PLAINTEXT_NEGOTIATION; static final String BIGTABLE_USE_CACHED_DATA_CHANNEL_POOL; static final String BIGTABLE_ASYNC_MUTATOR_COUNT_KEY; static final String BIGTABLE_USE_TIMEOUTS_KEY; static final String BIGTABLE_RPC_TIMEOUT_MS_KEY; @Deprecated
  static final String BIGTABLE_LONG_RPC_TIMEOUT_MS_KEY; static final String BIGTABLE_MUTATE_RPC_TIMEOUT_MS_KEY; static final String BIGTABLE_READ_RPC_TIMEOUT_MS_KEY; static final String BIGTABLE_NAMESPACE_WARNING_KEY; static final String BIGTABLE_USE_GCJ_CLIENT; }
@Test public void testProjectIdIsRequired() throws IOException { Configuration configuration = new Configuration(false); configuration.unset(BigtableOptionsFactory.PROJECT_ID_KEY); expectedException.expect(IllegalArgumentException.class); BigtableOptionsFactory.fromConfiguration(configuration); }
@Test public void testHostIsRequired() throws IOException { Configuration configuration = new Configuration(false); configuration.unset(BigtableOptionsFactory.BIGTABLE_HOST_KEY); expectedException.expect(IllegalArgumentException.class); BigtableOptionsFactory.fromConfiguration(configuration); }
@Test public void testInstanceIsRequired() throws IOException { Configuration configuration = new Configuration(false); configuration.unset(BigtableOptionsFactory.INSTANCE_ID_KEY); expectedException.expect(IllegalArgumentException.class); BigtableOptionsFactory.fromConfiguration(configuration); }
@Test public void testConnectionKeysAreUsed() throws IOException { configuration.set(BigtableOptionsFactory.BIGTABLE_HOST_KEY, "data-host"); configuration.set(BigtableOptionsFactory.BIGTABLE_ADMIN_HOST_KEY, "admin-host"); configuration.setInt(BigtableOptionsFactory.BIGTABLE_PORT_KEY, 1234); configuration.setBoolean(BigtableOptionsFactory.BIGTABLE_USE_PLAINTEXT_NEGOTIATION, true); BigtableOptions options = BigtableOptionsFactory.fromConfiguration(configuration); assertEquals("data-host", options.getDataHost()); assertEquals("admin-host", options.getAdminHost()); assertEquals(1234, options.getPort()); assertTrue( "BIGTABLE_USE_PLAINTEXT_NEGOTIATION was not propagated", options.usePlaintextNegotiation()); }
@Test public void testOptionsAreConstructedWithValidInput() throws IOException { configuration.set(BigtableOptionsFactory.BIGTABLE_HOST_KEY, TEST_HOST); configuration.setBoolean(BigtableOptionsFactory.BIGTABLE_USE_SERVICE_ACCOUNTS_KEY, false); configuration.setBoolean(BigtableOptionsFactory.BIGTABLE_NULL_CREDENTIAL_ENABLE_KEY, true); BigtableOptions options = BigtableOptionsFactory.fromConfiguration(configuration); assertEquals(TEST_HOST, options.getDataHost()); assertEquals(TEST_PROJECT_ID, options.getProjectId()); assertEquals(TEST_INSTANCE_ID, options.getInstanceId()); }
@Test public void testDefaultRetryOptions() throws IOException { RetryOptions retryOptions = BigtableOptionsFactory.fromConfiguration(configuration).getRetryOptions(); assertEquals(RetryOptions.DEFAULT_ENABLE_GRPC_RETRIES, retryOptions.enableRetries()); assertEquals( RetryOptions.DEFAULT_MAX_ELAPSED_BACKOFF_MILLIS, retryOptions.getMaxElapsedBackoffMillis()); assertEquals( RetryOptions.DEFAULT_READ_PARTIAL_ROW_TIMEOUT_MS, retryOptions.getReadPartialRowTimeoutMillis()); assertEquals( RetryOptions.DEFAULT_MAX_SCAN_TIMEOUT_RETRIES, retryOptions.getMaxScanTimeoutRetries()); }
@Test public void testSettingRetryOptions() throws IOException { configuration.set(BigtableOptionsFactory.ENABLE_GRPC_RETRIES_KEY, "false"); configuration.set(BigtableOptionsFactory.ENABLE_GRPC_RETRY_DEADLINEEXCEEDED_KEY, "false"); configuration.set(BigtableOptionsFactory.MAX_ELAPSED_BACKOFF_MILLIS_KEY, "111"); configuration.set(BigtableOptionsFactory.READ_PARTIAL_ROW_TIMEOUT_MS, "123"); RetryOptions retryOptions = BigtableOptionsFactory.fromConfiguration(configuration).getRetryOptions(); assertEquals(false, retryOptions.enableRetries()); assertEquals(false, retryOptions.retryOnDeadlineExceeded()); assertEquals(111, retryOptions.getMaxElapsedBackoffMillis()); assertEquals(123, retryOptions.getReadPartialRowTimeoutMillis()); }
@Test public void testExplicitCredentials() throws IOException, GeneralSecurityException { Credentials credentials = Mockito.mock(Credentials.class); configuration = new Configuration(false); configuration.set(BigtableOptionsFactory.BIGTABLE_HOST_KEY, TEST_HOST); configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, TEST_PROJECT_ID); configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, TEST_INSTANCE_ID); configuration = BigtableConfiguration.withCredentials(configuration, credentials); BigtableOptions options = BigtableOptionsFactory.fromConfiguration(configuration); Credentials actualCreds = CredentialFactory.getCredentials(options.getCredentialOptions()); Assert.assertSame(credentials, actualCreds); }
@Test public void testLongOperationsTimeouts() throws IOException { String longTimeout = "10000"; configuration.set(BigtableOptionsFactory.BIGTABLE_LONG_RPC_TIMEOUT_MS_KEY, longTimeout); BigtableOptions options = BigtableOptionsFactory.fromConfiguration(configuration); assertEquals( Integer.parseInt(longTimeout), options.getCallOptionsConfig().getMutateRpcTimeoutMs()); assertEquals( Integer.parseInt(longTimeout), options.getCallOptionsConfig().getReadStreamRpcTimeoutMs()); String readTimeout = "20000"; configuration = new Configuration(false); configuration.set(BigtableOptionsFactory.BIGTABLE_HOST_KEY, TEST_HOST); configuration.set(BigtableOptionsFactory.PROJECT_ID_KEY, TEST_PROJECT_ID); configuration.set(BigtableOptionsFactory.INSTANCE_ID_KEY, TEST_INSTANCE_ID); configuration.set(BigtableOptionsFactory.BIGTABLE_MUTATE_RPC_TIMEOUT_MS_KEY, longTimeout); configuration.set(BigtableOptionsFactory.BIGTABLE_READ_RPC_TIMEOUT_MS_KEY, readTimeout); options = BigtableOptionsFactory.fromConfiguration(configuration); assertEquals(LONG_TIMEOUT_MS_DEFAULT, options.getCallOptionsConfig().getLongRpcTimeoutMs()); assertEquals( Integer.parseInt(longTimeout), options.getCallOptionsConfig().getMutateRpcTimeoutMs()); assertEquals( Integer.parseInt(readTimeout), options.getCallOptionsConfig().getReadStreamRpcTimeoutMs()); }