Skip to content

Commit 2ff90e4

Browse files
committed
chore: Fix review comments
Signed-off-by: Javier Aliaga <javier@diagrid.io>
1 parent a062651 commit 2ff90e4

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

durabletask-client/src/main/java/io/dapr/durabletask/RetryPolicy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public Duration getRetryTimeout() {
191191
* @throws IllegalArgumentException if {@code jitterFactor} is outside [0.0, 1.0]
192192
*/
193193
public RetryPolicy setJitterFactor(double jitterFactor) {
194-
if (jitterFactor < 0.0 || jitterFactor > 1.0) {
194+
if (!Double.isFinite(jitterFactor) || jitterFactor < 0.0 || jitterFactor > 1.0) {
195195
throw new IllegalArgumentException("The value for jitterFactor must be between 0.0 and 1.0 inclusive.");
196196
}
197197
this.jitterFactor = jitterFactor;

durabletask-client/src/main/java/io/dapr/durabletask/TaskOrchestrationExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ private Duration getNextDelay() {
15041504
(long) Helpers.powExact(this.policy.getBackoffCoefficient(), this.attemptNumber));
15051505
} catch (ArithmeticException overflowException) {
15061506
if (maxDelayInMillis > 0) {
1507-
return this.policy.getMaxRetryInterval();
1507+
nextDelayInMillis = maxDelayInMillis;
15081508
} else {
15091509
// If no maximum is specified, just throw
15101510
throw new ArithmeticException("The retry policy calculation resulted in an arithmetic "

durabletask-client/src/test/java/io/dapr/durabletask/RetryPolicyTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ void jitterFactorAboveOneThrows() {
6868
assertThrows(IllegalArgumentException.class, () -> policy.setJitterFactor(1.1));
6969
}
7070

71+
@Test
72+
void jitterFactorNaNThrows() {
73+
RetryPolicy policy = new RetryPolicy(3, Duration.ofSeconds(1));
74+
assertThrows(IllegalArgumentException.class, () -> policy.setJitterFactor(Double.NaN));
75+
}
76+
77+
@Test
78+
void jitterFactorPositiveInfinityThrows() {
79+
RetryPolicy policy = new RetryPolicy(3, Duration.ofSeconds(1));
80+
assertThrows(IllegalArgumentException.class, () -> policy.setJitterFactor(Double.POSITIVE_INFINITY));
81+
}
82+
7183
// ---- deterministic delay formula ----
7284

7385
/**

sdk-workflows/src/main/java/io/dapr/workflows/WorkflowTaskRetryPolicy.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@ public final class WorkflowTaskRetryPolicy {
2626
private final Duration retryTimeout;
2727
private final Double jitterFactor;
2828

29+
/**
30+
* Constructor for WorkflowTaskRetryPolicy (without jitter).
31+
* @param maxNumberOfAttempts Maximum number of attempts to retry the workflow.
32+
* @param firstRetryInterval Interval to wait before the first retry.
33+
* @param backoffCoefficient Coefficient to increase the retry interval.
34+
* @param maxRetryInterval Maximum interval to wait between retries.
35+
* @param retryTimeout Timeout for the whole retry process.
36+
*/
37+
public WorkflowTaskRetryPolicy(
38+
Integer maxNumberOfAttempts,
39+
Duration firstRetryInterval,
40+
Double backoffCoefficient,
41+
Duration maxRetryInterval,
42+
Duration retryTimeout
43+
) {
44+
this(maxNumberOfAttempts, firstRetryInterval, backoffCoefficient,
45+
maxRetryInterval, retryTimeout, null);
46+
}
47+
2948
/**
3049
* Constructor for WorkflowTaskRetryPolicy.
3150
* @param maxNumberOfAttempts Maximum number of attempts to retry the workflow.
@@ -200,7 +219,7 @@ public Builder setRetryTimeout(Duration retryTimeout) {
200219
* @return This builder
201220
*/
202221
public Builder setJitterFactor(double jitterFactor) {
203-
if (jitterFactor < 0.0 || jitterFactor > 1.0) {
222+
if (!Double.isFinite(jitterFactor) || jitterFactor < 0.0 || jitterFactor > 1.0) {
204223
throw new IllegalArgumentException("The value for jitterFactor must be between 0.0 and 1.0 inclusive.");
205224
}
206225

sdk-workflows/src/test/java/io/dapr/workflows/WorkflowTaskRetryPolicyTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,18 @@ void jitterFactorAboveOneThrows() {
8787
assertThrows(IllegalArgumentException.class, () -> builder.setJitterFactor(1.1));
8888
}
8989

90+
@Test
91+
void jitterFactorNaNThrows() {
92+
WorkflowTaskRetryPolicy.Builder builder = WorkflowTaskRetryPolicy.newBuilder();
93+
assertThrows(IllegalArgumentException.class, () -> builder.setJitterFactor(Double.NaN));
94+
}
95+
96+
@Test
97+
void jitterFactorPositiveInfinityThrows() {
98+
WorkflowTaskRetryPolicy.Builder builder = WorkflowTaskRetryPolicy.newBuilder();
99+
assertThrows(IllegalArgumentException.class, () -> builder.setJitterFactor(Double.POSITIVE_INFINITY));
100+
}
101+
90102
// ---- builder chaining ----
91103

92104
@Test

0 commit comments

Comments
 (0)