if (options.retryOptions.getInitialBackoffMillis() == RetryOptions.DEFAULT_INITIAL_BACKOFF_MILLIS) { retryOptionsBuilder.setInitialBackoffMillis((int) TimeUnit.SECONDS.toMillis(5));
@Test public void testReadWithBigTableOptionsSetsRetryOptions() { final int initialBackoffMillis = -1; BigtableOptions.Builder optionsBuilder = BIGTABLE_OPTIONS.toBuilder(); RetryOptions.Builder retryOptionsBuilder = new RetryOptions.Builder(); retryOptionsBuilder.setInitialBackoffMillis(initialBackoffMillis); optionsBuilder.setRetryOptions(retryOptionsBuilder.build()); BigtableIO.Read read = BigtableIO.read().withBigtableOptions(optionsBuilder.build()); BigtableOptions options = read.getBigtableOptions(); assertEquals(initialBackoffMillis, options.getRetryOptions().getInitialBackoffMillis()); assertThat(options.getRetryOptions(), Matchers.equalTo(retryOptionsBuilder.build())); }
/** * <p>createBackoff.</p> * * @return a {@link ExponentialRetryAlgorithm} object. */ private ExponentialRetryAlgorithm createRetryAlgorithm(ApiClock clock) { long timeoutMs = retryOptions.getMaxElapsedBackoffMillis(); Deadline deadline = getOperationCallOptions().getDeadline(); if (deadline != null) { timeoutMs = deadline.timeRemaining(TimeUnit.MILLISECONDS); } RetrySettings retrySettings = RetrySettings.newBuilder() .setJittered(true) // How long should the sleep be between RPC failure and the next RPC retry? .setInitialRetryDelay(toDuration(retryOptions.getInitialBackoffMillis())) // How fast should the retry delay increase? .setRetryDelayMultiplier(retryOptions.getBackoffMultiplier()) // What is the maximum amount of sleep time between retries? // There needs to be some sane number for max retry delay, and it's unclear what that // number ought to be. 1 Minute time was chosen because some number is needed. .setMaxRetryDelay(Duration.of(1, ChronoUnit.MINUTES)) // How long should we wait before giving up retries after the first failure? .setTotalTimeout(toDuration(timeoutMs)) .build(); return new ExponentialRetryAlgorithm(retrySettings, clock); }
@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(); assertEquals(true, 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())); }