From 68644a4e24f29223f8f533a3d353dff7457d9737 Mon Sep 17 00:00:00 2001 From: Mira Leung Date: Fri, 19 Feb 2021 11:12:35 -0800 Subject: [PATCH] feat!: deprecate RetrySettings.isJittered [gax-java] (#1308) * feat!: deprecate RetrySettings.isJittered * fix: Address comments --- .../gax/retrying/ExponentialRetryAlgorithm.java | 2 +- .../google/api/gax/retrying/RetrySettings.java | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java b/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java index ecc91bb9e..355e2779c 100644 --- a/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java +++ b/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java @@ -187,7 +187,7 @@ public boolean shouldRetry(TimedAttemptSettings nextAttemptSettings) { // Injecting Random is not possible here, as Random does not provide nextLong(long bound) method protected long nextRandomLong(long bound) { - return bound > 0 && globalSettings.isJittered() + return bound > 0 && globalSettings.isJittered() // Jitter check needed for testing purposes. ? ThreadLocalRandom.current().nextLong(bound) : bound; } diff --git a/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java b/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java index a3a888d4b..2276eb407 100644 --- a/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java +++ b/gax/src/main/java/com/google/api/gax/retrying/RetrySettings.java @@ -30,6 +30,7 @@ package com.google.api.gax.retrying; import com.google.auto.value.AutoValue; +import com.google.common.annotations.VisibleForTesting; import java.io.Serializable; import org.threeten.bp.Duration; @@ -112,7 +113,11 @@ public abstract class RetrySettings implements Serializable { *
{@code actualDelay = rand_between(0, min(maxRetryDelay, delay))}
* * The default value is {@code true}. + * + * @deprecated Retries always jitter. */ + @Deprecated + @VisibleForTesting public abstract boolean isJittered(); /** @@ -194,13 +199,17 @@ public abstract static class Builder { public abstract Builder setMaxAttempts(int maxAttempts); /** - * Jitter determines if the delay time should be randomized. In most cases, if jitter is set to - * {@code true} the actual delay time is calculated in the following way: + * Jitter determines if the delay time should be randomized. If jitter is set to {@code true} + * the actual delay time is calculated in the following way: * *
{@code actualDelay = rand_between(0, min(maxRetryDelay, exponentialDelay))}
* - * The default value is {@code true}. + * The default value is {@code true}, and this method will be a no-op soon. + * + * @deprecated Retries always jitter. */ + @Deprecated + @VisibleForTesting public abstract Builder setJittered(boolean jittered); /**