File tree 2 files changed +16
-2
lines changed
main/java/net/jodah/failsafe
test/java/net/jodah/failsafe
2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ class RetryPolicyExecutor extends PolicyExecutor<RetryPolicy> {
37
37
private volatile int failedAttempts ;
38
38
private volatile boolean retriesExceeded ;
39
39
/** The fixed, backoff, random or computed delay time in nanoseconds. */
40
- private volatile long delayNanos = - 1 ;
40
+ private volatile long delayNanos ;
41
41
42
42
// Listeners
43
43
private final EventListener abortListener ;
@@ -221,7 +221,7 @@ private long getFixedOrRandomDelayNanos(long waitNanos) {
221
221
Duration delayMin = policy .getDelayMin ();
222
222
Duration delayMax = policy .getDelayMax ();
223
223
224
- if (waitNanos == - 1 && delay != null && !delay .equals (Duration .ZERO ))
224
+ if (waitNanos == 0 && delay != null && !delay .equals (Duration .ZERO ))
225
225
waitNanos = delay .toNanos ();
226
226
else if (delayMin != null && delayMax != null )
227
227
waitNanos = randomDelayInRange (delayMin .toNanos (), delayMax .toNanos (), Math .random ());
Original file line number Diff line number Diff line change @@ -539,6 +539,20 @@ public void shouldSkipExecutionWhenCircuitOpen() {
539
539
assertThrows (future ::get , ExecutionException .class , CircuitBreakerOpenException .class );
540
540
}
541
541
542
+ public void testRetryPolicyScheduledDelayIsZero () throws Throwable {
543
+ RetryPolicy <Object > rp = new RetryPolicy <>().onRetryScheduled (e -> {
544
+ assertEquals (e .getDelay ().toMillis (), 0 );
545
+ System .out .println (e .getDelay ().toMillis ());
546
+ waiter .resume ();
547
+ });
548
+
549
+ Failsafe .with (rp ).runAsync (() -> {
550
+ throw new IllegalStateException ();
551
+ });
552
+
553
+ waiter .await (1000 );
554
+ }
555
+
542
556
private void assertInterruptedExceptionOnCancel (FailsafeExecutor <Boolean > failsafe ) throws Throwable {
543
557
CompletableFuture <Void > future = failsafe .runAsync (() -> {
544
558
try {
You can’t perform that action at this time.
0 commit comments