|
21 | 21 | import dev.failsafe.event.ExecutionScheduledEvent; |
22 | 22 | import dev.failsafe.internal.RetryPolicyImpl; |
23 | 23 | import dev.failsafe.internal.util.Assert; |
| 24 | +import dev.failsafe.internal.util.Durations; |
24 | 25 |
|
25 | 26 | import java.time.Duration; |
26 | 27 | import java.time.temporal.ChronoUnit; |
@@ -290,6 +291,8 @@ public RetryPolicyBuilder<R> withBackoff(long delay, long maxDelay, ChronoUnit c |
290 | 291 | public RetryPolicyBuilder<R> withBackoff(Duration delay, Duration maxDelay, double delayFactor) { |
291 | 292 | Assert.notNull(delay, "delay"); |
292 | 293 | Assert.notNull(maxDelay, "maxDelay"); |
| 294 | + delay = Durations.ofSafeNanos(delay); |
| 295 | + maxDelay = Durations.ofSafeNanos(maxDelay); |
293 | 296 | Assert.isTrue(!delay.isNegative() && !delay.isZero(), "The delay must be > 0"); |
294 | 297 | Assert.state(config.maxDuration == null || delay.toNanos() < config.maxDuration.toNanos(), |
295 | 298 | "delay must be < the maxDuration"); |
@@ -319,6 +322,7 @@ public RetryPolicyBuilder<R> withBackoff(Duration delay, Duration maxDelay, doub |
319 | 322 | @Override |
320 | 323 | public RetryPolicyBuilder<R> withDelay(Duration delay) { |
321 | 324 | Assert.notNull(delay, "delay"); |
| 325 | + delay = Durations.ofSafeNanos(delay); |
322 | 326 | Assert.state(config.maxDuration == null || delay.toNanos() < config.maxDuration.toNanos(), |
323 | 327 | "delay must be < the maxDuration"); |
324 | 328 | Assert.state(config.jitter == null || delay.toNanos() >= config.jitter.toNanos(), |
@@ -361,6 +365,8 @@ public RetryPolicyBuilder<R> withDelay(long delayMin, long delayMax, ChronoUnit |
361 | 365 | public RetryPolicyBuilder<R> withDelay(Duration delayMin, Duration delayMax) { |
362 | 366 | Assert.notNull(delayMin, "delayMin"); |
363 | 367 | Assert.notNull(delayMax, "delayMax"); |
| 368 | + delayMin = Durations.ofSafeNanos(delayMin); |
| 369 | + delayMax = Durations.ofSafeNanos(delayMax); |
364 | 370 | Assert.isTrue(!delayMin.isNegative() && !delayMin.isZero(), "delayMin must be > 0"); |
365 | 371 | Assert.isTrue(!delayMax.isNegative() && !delayMax.isZero(), "delayMax must be > 0"); |
366 | 372 | Assert.isTrue(delayMin.toNanos() < delayMax.toNanos(), "delayMin must be < delayMax"); |
@@ -415,6 +421,7 @@ public RetryPolicyBuilder<R> withJitter(double jitterFactor) { |
415 | 421 | */ |
416 | 422 | public RetryPolicyBuilder<R> withJitter(Duration jitter) { |
417 | 423 | Assert.notNull(jitter, "jitter"); |
| 424 | + jitter = Durations.ofSafeNanos(jitter); |
418 | 425 | Assert.isTrue(jitter.toNanos() > 0, "jitter must be > 0"); |
419 | 426 | boolean validJitter = config.delayMin != null ? |
420 | 427 | jitter.toNanos() <= config.delayMin.toNanos() : |
@@ -459,6 +466,7 @@ public RetryPolicyBuilder<R> withMaxAttempts(int maxAttempts) { |
459 | 466 | */ |
460 | 467 | public RetryPolicyBuilder<R> withMaxDuration(Duration maxDuration) { |
461 | 468 | Assert.notNull(maxDuration, "maxDuration"); |
| 469 | + maxDuration = Durations.ofSafeNanos(maxDuration); |
462 | 470 | Assert.state(maxDuration.toNanos() > config.delay.toNanos(), "maxDuration must be > the delay"); |
463 | 471 | Assert.state(config.delayMax == null || maxDuration.toNanos() > config.delayMax.toNanos(), |
464 | 472 | "maxDuration must be > the max random delay"); |
|
0 commit comments