com.google.api.gax.retrying.RetrySettings.getMaxAttempts()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(56)

本文整理了Java中com.google.api.gax.retrying.RetrySettings.getMaxAttempts方法的一些代码示例,展示了RetrySettings.getMaxAttempts的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RetrySettings.getMaxAttempts方法的具体详情如下:
包路径:com.google.api.gax.retrying.RetrySettings
类名称:RetrySettings
方法名:getMaxAttempts

RetrySettings.getMaxAttempts介绍

[英]MaxAttempts defines the maximum number of attempts to perform. The default value is 0. If this value is greater than 0, and the number of attempts reaches this limit, the logic will give up retrying even if the total retry time is still lower than TotalTimeout.
[中]MaxAttempts定义要执行的最大尝试次数。默认值为0。如果此值大于0,且尝试次数达到此限制,则即使总重试时间仍低于TotalTimeout,逻辑也将放弃重试。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void checkAndMutateRowSettingsAreSane() {
 UnaryCallSettings.Builder<ConditionalRowMutation, Boolean> builder =
   EnhancedBigtableStubSettings.newBuilder().checkAndMutateRowSettings();
 // CheckAndMutateRow is not retryable in the case of toggle mutations. So it's disabled by
 // default.
 assertThat(builder.getRetrySettings().getMaxAttempts()).isAtMost(1);
 assertThat(builder.getRetryableCodes()).isEmpty();
}

代码示例来源:origin: googleapis/google-cloud-java

if (retrySettings.getMaxAttempts() == 0) {
 retrySettings = retrySettings.toBuilder().setMaxAttempts(Integer.MAX_VALUE).build();

代码示例来源:origin: googleapis/google-cloud-java

@Test
 public void testCreateFromStream() {
  RemoteStorageHelper helper = RemoteStorageHelper.create(PROJECT_ID, JSON_KEY_STREAM);
  StorageOptions options = helper.getOptions();
  assertEquals(PROJECT_ID, options.getProjectId());
  assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout());
  assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout());
  assertEquals(10, options.getRetrySettings().getMaxAttempts());
  assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay());
  assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout());
  assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay());
 }
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testCreateFromStream() {
 RemoteComputeHelper helper = RemoteComputeHelper.create(PROJECT_ID, JSON_KEY_STREAM);
 ComputeOptions options = helper.getOptions();
 assertEquals(PROJECT_ID, options.getProjectId());
 assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout());
 assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout());
 assertEquals(10, options.getRetrySettings().getMaxAttempts());
 assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay());
 assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout());
 assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
 public void testCreateFromStream() {
  RemoteBigQueryHelper helper = RemoteBigQueryHelper.create(PROJECT_ID, JSON_KEY_STREAM);
  BigQueryOptions options = helper.getOptions();
  assertEquals(PROJECT_ID, options.getProjectId());
  assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getConnectTimeout());
  assertEquals(60000, ((HttpTransportOptions) options.getTransportOptions()).getReadTimeout());
  assertEquals(10, options.getRetrySettings().getMaxAttempts());
  assertEquals(Duration.ofMillis(30000), options.getRetrySettings().getMaxRetryDelay());
  assertEquals(Duration.ofMillis(120000), options.getRetrySettings().getTotalTimeout());
  assertEquals(Duration.ofMillis(250), options.getRetrySettings().getInitialRetryDelay());
 }
}

代码示例来源:origin: googleapis/gax-java

/**
 * Returns {@code true} if another attempt should be made, or {@code false} otherwise.
 *
 * @param nextAttemptSettings attempt settings, which will be used for the next attempt, if
 *     accepted
 * @return {@code true} if {@code nextAttemptSettings} does not exceed either maxAttempts limit or
 *     totalTimeout limit, or {@code false} otherwise
 */
@Override
public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) {
 RetrySettings globalSettings = nextAttemptSettings.getGlobalSettings();
 long totalTimeSpentNanos =
   clock.nanoTime()
     - nextAttemptSettings.getFirstAttemptStartTimeNanos()
     + nextAttemptSettings.getRandomizedRetryDelay().toNanos();
 return totalTimeSpentNanos <= globalSettings.getTotalTimeout().toNanos()
   && (globalSettings.getMaxAttempts() <= 0
     || nextAttemptSettings.getAttemptCount() < globalSettings.getMaxAttempts());
}

代码示例来源:origin: com.google.api/gax

/**
 * Returns {@code true} if another attempt should be made, or {@code false} otherwise.
 *
 * @param nextAttemptSettings attempt settings, which will be used for the next attempt, if
 *     accepted
 * @return {@code true} if {@code nextAttemptSettings} does not exceed either maxAttempts limit or
 *     totalTimeout limit, or {@code false} otherwise
 */
@Override
public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) {
 RetrySettings globalSettings = nextAttemptSettings.getGlobalSettings();
 long totalTimeSpentNanos =
   clock.nanoTime()
     - nextAttemptSettings.getFirstAttemptStartTimeNanos()
     + nextAttemptSettings.getRandomizedRetryDelay().toNanos();
 return totalTimeSpentNanos <= globalSettings.getTotalTimeout().toNanos()
   && (globalSettings.getMaxAttempts() <= 0
     || nextAttemptSettings.getAttemptCount() < globalSettings.getMaxAttempts());
}

代码示例来源:origin: com.google.api/gax

public RetrySettings build() {
 RetrySettings params = autoBuild();
 if (params.getTotalTimeout().toMillis() < 0) {
  throw new IllegalStateException("total timeout must not be negative");
 }
 if (params.getInitialRetryDelay().toMillis() < 0) {
  throw new IllegalStateException("initial retry delay must not be negative");
 }
 if (params.getRetryDelayMultiplier() < 1.0) {
  throw new IllegalStateException("retry delay multiplier must be at least 1");
 }
 if (params.getMaxRetryDelay().compareTo(params.getInitialRetryDelay()) < 0) {
  throw new IllegalStateException("max retry delay must not be shorter than initial delay");
 }
 if (params.getMaxAttempts() < 0) {
  throw new IllegalStateException("max attempts must be non-negative");
 }
 if (params.getInitialRpcTimeout().toMillis() < 0) {
  throw new IllegalStateException("initial rpc timeout must not be negative");
 }
 if (params.getMaxRpcTimeout().compareTo(params.getInitialRpcTimeout()) < 0) {
  throw new IllegalStateException("max rpc timeout must not be shorter than initial timeout");
 }
 if (params.getRpcTimeoutMultiplier() < 1.0) {
  throw new IllegalStateException("rpc timeout multiplier must be at least 1");
 }
 return params;
}

代码示例来源:origin: googleapis/gax-java

public RetrySettings build() {
 RetrySettings params = autoBuild();
 if (params.getTotalTimeout().toMillis() < 0) {
  throw new IllegalStateException("total timeout must not be negative");
 }
 if (params.getInitialRetryDelay().toMillis() < 0) {
  throw new IllegalStateException("initial retry delay must not be negative");
 }
 if (params.getRetryDelayMultiplier() < 1.0) {
  throw new IllegalStateException("retry delay multiplier must be at least 1");
 }
 if (params.getMaxRetryDelay().compareTo(params.getInitialRetryDelay()) < 0) {
  throw new IllegalStateException("max retry delay must not be shorter than initial delay");
 }
 if (params.getMaxAttempts() < 0) {
  throw new IllegalStateException("max attempts must be non-negative");
 }
 if (params.getInitialRpcTimeout().toMillis() < 0) {
  throw new IllegalStateException("initial rpc timeout must not be negative");
 }
 if (params.getMaxRpcTimeout().compareTo(params.getInitialRpcTimeout()) < 0) {
  throw new IllegalStateException("max rpc timeout must not be shorter than initial timeout");
 }
 if (params.getRpcTimeoutMultiplier() < 1.0) {
  throw new IllegalStateException("rpc timeout multiplier must be at least 1");
 }
 return params;
}

代码示例来源:origin: google/java-photoslibrary

&& (retrySettings.getMaxAttempts() == UNLIMITED_RETRIES
   || retries < retrySettings.getMaxAttempts())) {
retries++;
if (!successful && retries < retrySettings.getMaxAttempts()) {

代码示例来源:origin: googleapis/gax-java

@Test
 public void testSetSimpleTimeoutNoRetries() {
  UnaryCallSettings.Builder builder = new UnaryCallSettings.Builder();
  builder.setSimpleTimeoutNoRetries(Duration.ofSeconds(13));

  Truth.assertThat(builder.getRetryableCodes().size()).isEqualTo(0);
  Truth.assertThat(builder.getRetrySettings().getMaxAttempts()).isEqualTo(1);
  Truth.assertThat(builder.getRetrySettings().getTotalTimeout())
    .isEqualTo(Duration.ofSeconds(13));
 }
}

相关文章