private void verifyRetrySettings(Set<Code> retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRpcTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRpcTimeoutMultiplier()).isAtLeast(1.0); assertThat(retrySettings.getMaxRpcTimeout()).isGreaterThan(Duration.ZERO); } }
private void verifyRetrySettingAreSane(Set<Code> retryCodes, RetrySettings retrySettings) { assertThat(retryCodes).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); assertThat(retrySettings.getTotalTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRetryDelay()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRetryDelayMultiplier()).isAtLeast(1.0); assertThat(retrySettings.getMaxRetryDelay()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getInitialRpcTimeout()).isGreaterThan(Duration.ZERO); assertThat(retrySettings.getRpcTimeoutMultiplier()).isAtLeast(1.0); assertThat(retrySettings.getMaxRpcTimeout()).isGreaterThan(Duration.ZERO); } }
@Test public void testReadRowsSettings() { ServerStreamingCallSettings.Builder<ReadRowsRequest, ReadRowsResponse> builder = EnhancedBigQueryStorageStubSettings.newBuilder().readRowsSettings(); assertThat(builder.getRetryableCodes()).containsAllOf(Code.DEADLINE_EXCEEDED, Code.UNAVAILABLE); RetrySettings retrySettings = builder.getRetrySettings(); assertThat(retrySettings.getInitialRetryDelay()).isEqualTo(Duration.ofMillis(100L)); assertThat(retrySettings.getRetryDelayMultiplier()).isWithin(1e-6).of(1.3); assertThat(retrySettings.getMaxRetryDelay()).isEqualTo(Duration.ofMinutes(1L)); assertThat(retrySettings.getInitialRpcTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getRpcTimeoutMultiplier()).isWithin(1e-6).of(1.0); assertThat(retrySettings.getMaxRpcTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(retrySettings.getTotalTimeout()).isEqualTo(Duration.ofDays(1L)); assertThat(builder.getIdleTimeout()).isEqualTo(Duration.ZERO); }
@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()); } }
@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()); }
@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()); } }
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; }
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; }
Math.min(delayMillis, retrySettings.getMaxRetryDelay().get(MILLIS)); if (retrySettings.isJittered()) { actualDelayMillis = ThreadLocalRandom.current().nextLong(actualDelayMillis);
@Test public void retrySettingsMerge() { RetrySettings.Builder builder = RetrySettings.newBuilder() .setTotalTimeout(Duration.ofMillis(45000)) .setInitialRpcTimeout(Duration.ofMillis(2000)) .setRpcTimeoutMultiplier(1.5) .setMaxRpcTimeout(Duration.ofMillis(30000)) .setInitialRetryDelay(Duration.ofMillis(100)) .setRetryDelayMultiplier(1.2) .setMaxRetryDelay(Duration.ofMillis(1000)); RetrySettings.Builder mergedBuilder = RetrySettings.newBuilder(); mergedBuilder.merge(builder); RetrySettings settingsA = builder.build(); RetrySettings settingsB = mergedBuilder.build(); Truth.assertThat(settingsA.getTotalTimeout()).isEqualTo(settingsB.getTotalTimeout()); Truth.assertThat(settingsA.getInitialRetryDelay()).isEqualTo(settingsB.getInitialRetryDelay()); Truth.assertThat(settingsA.getRpcTimeoutMultiplier()) .isWithin(0) .of(settingsB.getRpcTimeoutMultiplier()); Truth.assertThat(settingsA.getMaxRpcTimeout()).isEqualTo(settingsB.getMaxRpcTimeout()); Truth.assertThat(settingsA.getInitialRetryDelay()).isEqualTo(settingsB.getInitialRetryDelay()); Truth.assertThat(settingsA.getRetryDelayMultiplier()) .isWithin(0) .of(settingsB.getRetryDelayMultiplier()); Truth.assertThat(settingsA.getMaxRetryDelay()).isEqualTo(settingsB.getMaxRetryDelay()); }
newRetryDelay = (long) (settings.getRetryDelayMultiplier() * prevSettings.getRetryDelay().toMillis()); newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis());
newRetryDelay = (long) (settings.getRetryDelayMultiplier() * prevSettings.getRetryDelay().toMillis()); newRetryDelay = Math.min(newRetryDelay, settings.getMaxRetryDelay().toMillis());