Skip to content

Commit 0dbd1bc

Browse files
Fix RetryOptions.addDoNotRetry (#520)
* Remove unnecessary validations in RetryOptions.addDoNotRetry * Add basic test on RetryOptions.addDoNotRetry Co-authored-by: Liang Mei <[email protected]>
1 parent d98d33f commit 0dbd1bc

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

src/main/java/com/uber/cadence/common/RetryOptions.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,9 @@ public final RetryOptions addDoNotRetry(Class<? extends Throwable>... doNotRetry
9292
return this;
9393
}
9494

95-
double backoffCoefficient = getBackoffCoefficient();
96-
if (backoffCoefficient == 0) {
97-
backoffCoefficient = DEFAULT_BACKOFF_COEFFICIENT;
98-
}
99-
100-
RetryOptions.Builder builder =
101-
new RetryOptions.Builder()
102-
.setInitialInterval(getInitialInterval())
103-
.setExpiration(getExpiration())
104-
.setMaximumInterval(getMaximumInterval())
105-
.setBackoffCoefficient(backoffCoefficient)
106-
.setDoNotRetry(merge(getDoNotRetry(), Arrays.asList(doNotRetry)));
95+
RetryOptions.Builder builder = new RetryOptions.Builder(this);
96+
builder.setDoNotRetry(merge(getDoNotRetry(), Arrays.asList(doNotRetry)));
10797

108-
if (getMaximumAttempts() > 0) {
109-
builder.setMaximumAttempts(getMaximumAttempts());
110-
}
11198
return builder.validateBuildWithDefaults();
11299
}
113100

src/test/java/com/uber/cadence/internal/common/RetryerTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ public void testInterruptedException() throws InterruptedException {
107107
assertTrue(System.currentTimeMillis() - start < 100000);
108108
}
109109

110+
@Test
111+
public void testAddDoNotRetry() throws InterruptedException {
112+
RetryOptions options =
113+
new RetryOptions.Builder()
114+
.setInitialInterval(Duration.ofMillis(10))
115+
.setExpiration(Duration.ofSeconds(100))
116+
.validateBuildWithDefaults();
117+
options = options.addDoNotRetry(InterruptedException.class);
118+
long start = System.currentTimeMillis();
119+
try {
120+
Retryer.retryWithResultAsync(
121+
options,
122+
() -> {
123+
CompletableFuture<Void> result = new CompletableFuture<>();
124+
result.completeExceptionally(new InterruptedException("simulated"));
125+
return result;
126+
})
127+
.get();
128+
fail("unreachable");
129+
} catch (ExecutionException e) {
130+
assertTrue(e.getCause() instanceof InterruptedException);
131+
assertEquals("simulated", e.getCause().getMessage());
132+
}
133+
assertTrue(System.currentTimeMillis() - start < 100000);
134+
}
135+
110136
@Test
111137
public void testMaxAttempt() throws InterruptedException {
112138
RetryOptions options =

0 commit comments

Comments
 (0)