feat: add linear retry strategy#468
Conversation
| * @param increment Amount to add to the delay after each retry attempt | ||
| * @return RetryStrategy implementing linear backoff | ||
| */ | ||
| public static RetryStrategy linearBackoff(int maxAttempts, Duration initialDelay, Duration increment) { |
There was a problem hiding this comment.
This should be more consistent with exponentialBackoff and have a maxDelay and jitterStrategy
There was a problem hiding this comment.
Do we want a jitter for this strategy?
There was a problem hiding this comment.
Yeah, basically the preset LINEAR may not need a jitter but the RetryStrategy factory linearBackoff should support customizable jitter
| ); | ||
|
|
||
| /** Linear retry strategy: 6 total attempts (1 initial + 5 retries) with 1s, 2s, 3s, 4s, and 5s delays. */ | ||
| public static final RetryStrategy LINEAR = linearBackoff(6, Duration.ofSeconds(1), Duration.ofSeconds(1)); |
There was a problem hiding this comment.
This should match the format (with comments ) of the Default above.
|
e2e failed for credential issues:
|
|
Thanks for the review. I pushed fb73e27 with the follow-up changes:
Verification run locally via Docker Maven:
|
Summary
Adds a linear retry strategy for Java SDK parity with the JavaScript SDK change referenced in #462.
The new
RetryStrategies.linearBackoff(maxAttempts, initialDelay, increment)factory computes retry delays asinitialDelay + increment * (attempt - 1), preserving the SDK's existing 1-based attempt andattempt >= maxAttemptsstop behavior. It also addsRetryStrategies.Presets.LINEAR, which uses six total attempts with retry delays of 1s, 2s, 3s, 4s, and 5s.Focused unit coverage checks the custom progression, preset progression, max-attempt stop behavior, and validation for invalid
maxAttempts, null durations, and sub-second durations.Closes #462
Verification
git diff --checkdocker run --rm -v "$PWD":/workspace -w /workspace maven:3.9-eclipse-temurin-17 mvn spotless:applydocker run --rm -v "$PWD":/workspace -w /workspace maven:3.9-eclipse-temurin-17 mvn -pl sdk test -Dtest=RetryStrategiesTest