From 58e70e634e6bf019b72a00d71d02c6d6ec8082d1 Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 16:54:31 +0100 Subject: [PATCH 01/13] Retryable with exponential backoff not working with delayExpression --- .../springframework/retry/backoff/ExponentialBackOffPolicy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index bd1f71c3..f2d713df 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -297,7 +297,7 @@ public double getMultiplier() { } public long getInterval() { - return this.intervalSupplier != null ? this.intervalSupplier.get() : this.interval; + return this.interval > 0 ? this.interval : this.intervalSupplier.get(); } public long getMaxInterval() { From 0dae5b5fc1fb1fddad8d0e134a509b6cc311d37e Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 17:18:34 +0100 Subject: [PATCH 02/13] Retryable with exponential backoff not working with delayExpression --- .../retry/backoff/ExponentialBackOffPolicy.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index f2d713df..e15569b5 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -297,7 +297,11 @@ public double getMultiplier() { } public long getInterval() { - return this.interval > 0 ? this.interval : this.intervalSupplier.get(); + if (intervalSupplier == null) { + return this.interval; + } else { + return this.interval == DEFAULT_INITIAL_INTERVAL ? this.intervalSupplier.get() : this.interval; + } } public long getMaxInterval() { From b2be988dc8d8f61b1c3609b4507fe32368bba678 Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 17:21:07 +0100 Subject: [PATCH 03/13] Retryable with exponential backoff not working with delayExpression --- .../retry/backoff/ExponentialBackOffPolicy.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index e15569b5..71287ace 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -259,7 +259,7 @@ static class ExponentialBackOffContext implements BackOffContext { private final long maxInterval; - private Supplier intervalSupplier; + private final Supplier initialIntervalSupplier; private Supplier multiplierSupplier; @@ -271,7 +271,7 @@ public ExponentialBackOffContext(long interval, double multiplier, long maxInter this.interval = interval; this.multiplier = multiplier; this.maxInterval = maxInterval; - this.intervalSupplier = intervalSupplier; + this.initialIntervalSupplier = intervalSupplier; this.multiplierSupplier = multiplierSupplier; this.maxIntervalSupplier = maxIntervalSupplier; } @@ -297,10 +297,10 @@ public double getMultiplier() { } public long getInterval() { - if (intervalSupplier == null) { + if (initialIntervalSupplier == null) { return this.interval; } else { - return this.interval == DEFAULT_INITIAL_INTERVAL ? this.intervalSupplier.get() : this.interval; + return this.interval == DEFAULT_INITIAL_INTERVAL ? this.initialIntervalSupplier.get() : this.interval; } } From aa0bac8c16e3bcf9435368ad3bfa446ac1da486b Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 17:33:07 +0100 Subject: [PATCH 04/13] Retryable with exponential backoff not working with delayExpression --- .../retry/backoff/ExponentialBackOffPolicy.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 71287ace..870d579c 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -299,7 +299,8 @@ public double getMultiplier() { public long getInterval() { if (initialIntervalSupplier == null) { return this.interval; - } else { + } + else { return this.interval == DEFAULT_INITIAL_INTERVAL ? this.initialIntervalSupplier.get() : this.interval; } } From 33af265b026c082726f68bc57f5f57908915839c Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 18:17:23 +0100 Subject: [PATCH 05/13] Retryable with exponential backoff not working with delayExpression --- .../retry/backoff/ExponentialBackOffPolicy.java | 9 ++++++++- .../backoff/ExponentialBackOffPolicyTests.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 870d579c..7b0c79ca 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -289,7 +289,14 @@ public synchronized long getSleepAndIncrement() { } protected long getNextInterval() { - return (long) (this.interval * getMultiplier()); + if (initialIntervalSupplier == null) { + return (long) (this.interval * getMultiplier()); + } + else { + return this.interval == DEFAULT_INITIAL_INTERVAL + ? (long) (this.initialIntervalSupplier.get() * getMultiplier()) + : (long) (this.interval * getMultiplier()); + } } public double getMultiplier() { diff --git a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java index 294203da..f90f1502 100644 --- a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java @@ -94,6 +94,22 @@ public void testMultiBackOff() { } } + @Test + public void testMultiBackOffWithInitialDelaySupplaier() { + ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); + long seed = 40; + double multiplier = 1.2; + strategy.initialIntervalSupplier(() -> 40L); + strategy.setMultiplier(multiplier); + strategy.setSleeper(sleeper); + BackOffContext context = strategy.start(null); + for (int x = 0; x < 5; x++) { + strategy.backOff(context); + assertThat(sleeper.getLastBackOff()).isEqualTo(seed); + seed *= multiplier; + } + } + @Test public void testInterruptedStatusIsRestored() { ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); From 903640ec21c02a6278e1d9415edb59f3f1f5c0be Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 18:19:03 +0100 Subject: [PATCH 06/13] Retryable with exponential backoff not working with delayExpression --- .../retry/backoff/ExponentialBackOffPolicyTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java index f90f1502..2c0f390d 100644 --- a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java @@ -95,7 +95,7 @@ public void testMultiBackOff() { } @Test - public void testMultiBackOffWithInitialDelaySupplaier() { + public void testMultiBackOffWithInitialDelaySupplier() { ExponentialBackOffPolicy strategy = new ExponentialBackOffPolicy(); long seed = 40; double multiplier = 1.2; From c4f14f42102d17038aafd18e730b4fe3c7b8db6c Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 20:01:32 +0100 Subject: [PATCH 07/13] Retryable with exponential backoff not working with delayExpression --- .../springframework/retry/backoff/ExponentialBackOffPolicy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 7b0c79ca..dc241efe 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -289,7 +289,7 @@ public synchronized long getSleepAndIncrement() { } protected long getNextInterval() { - if (initialIntervalSupplier == null) { + if (this.initialIntervalSupplier == null) { return (long) (this.interval * getMultiplier()); } else { From 6e018d24dbbf6dea28d0177e09893ebde979d6e8 Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 8 Nov 2023 21:11:06 +0100 Subject: [PATCH 08/13] Retryable with exponential backoff not working with delayExpression --- .../retry/backoff/ExponentialBackOffPolicy.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index dc241efe..d54129f2 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -49,10 +49,10 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy Date: Thu, 9 Nov 2023 13:28:37 +0100 Subject: [PATCH 09/13] updated logical conditions --- .../retry/backoff/ExponentialBackOffPolicy.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index d54129f2..891c2cda 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -289,13 +289,11 @@ public synchronized long getSleepAndIncrement() { } protected long getNextInterval() { - if (this.initialIntervalSupplier == null) { + if (this.initialIntervalSupplier == null || this.interval != DEFAULT_INITIAL_INTERVAL) { return (long) (this.interval * getMultiplier()); } else { - return this.interval == DEFAULT_INITIAL_INTERVAL - ? (long) (this.initialIntervalSupplier.get() * getMultiplier()) - : (long) (this.interval * getMultiplier()); + return (long) (this.initialIntervalSupplier.get() * getMultiplier()); } } @@ -304,11 +302,11 @@ public double getMultiplier() { } public long getInterval() { - if (initialIntervalSupplier == null) { + if (initialIntervalSupplier == null || this.interval != DEFAULT_INITIAL_INTERVAL) { return this.interval; } else { - return this.interval == DEFAULT_INITIAL_INTERVAL ? this.initialIntervalSupplier.get() : this.interval; + return this.initialIntervalSupplier.get(); } } From 06cd6d5316587cda5bb814c004ebc72ecf2e72b4 Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Tue, 14 Nov 2023 20:58:34 +0100 Subject: [PATCH 10/13] addressing comment --- .../backoff/ExponentialBackOffPolicy.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 891c2cda..06551e35 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -52,7 +52,7 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy initialIntervalSupplier; + private Supplier initialIntervalSupplier; private Supplier multiplierSupplier; @@ -289,12 +289,7 @@ public synchronized long getSleepAndIncrement() { } protected long getNextInterval() { - if (this.initialIntervalSupplier == null || this.interval != DEFAULT_INITIAL_INTERVAL) { - return (long) (this.interval * getMultiplier()); - } - else { - return (long) (this.initialIntervalSupplier.get() * getMultiplier()); - } + return (long) (this.interval * getMultiplier()); } public double getMultiplier() { @@ -302,12 +297,11 @@ public double getMultiplier() { } public long getInterval() { - if (initialIntervalSupplier == null || this.interval != DEFAULT_INITIAL_INTERVAL) { - return this.interval; - } - else { - return this.initialIntervalSupplier.get(); + if (this.initialIntervalSupplier != null) { + this.interval = this.initialIntervalSupplier.get(); + this.initialIntervalSupplier = null; } + return this.interval; } public long getMaxInterval() { From e8715bc75e3b4febaba91490d68e6d3739a14ac4 Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Tue, 14 Nov 2023 20:59:34 +0100 Subject: [PATCH 11/13] addressing comment --- .../springframework/retry/backoff/ExponentialBackOffPolicy.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 06551e35..3199725a 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -49,7 +49,7 @@ public class ExponentialBackOffPolicy implements SleepingBackOffPolicy Date: Tue, 14 Nov 2023 21:12:03 +0100 Subject: [PATCH 12/13] addressing comment --- .../org/springframework/retry/annotation/EnableRetryTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java index f1e6518a..f6229502 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java @@ -295,7 +295,7 @@ void runtimeExpressions() throws Exception { service.service6(); RuntimeConfigs runtime = context.getBean(RuntimeConfigs.class); verify(runtime, times(5)).getMaxAttempts(); - verify(runtime, times(2)).getInitial(); + verify(runtime, times(1)).getInitial(); verify(runtime, times(2)).getMax(); verify(runtime, times(2)).getMult(); From cac9236b71ac5e65e5c10485d7fc681cbdd787bb Mon Sep 17 00:00:00 2001 From: Anton Aharkau Date: Wed, 15 Nov 2023 08:19:53 +0100 Subject: [PATCH 13/13] added author --- .../springframework/retry/backoff/ExponentialBackOffPolicy.java | 1 + .../org/springframework/retry/annotation/EnableRetryTests.java | 1 + .../retry/backoff/ExponentialBackOffPolicyTests.java | 1 + 3 files changed, 3 insertions(+) diff --git a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java index 3199725a..25556a74 100644 --- a/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java +++ b/src/main/java/org/springframework/retry/backoff/ExponentialBackOffPolicy.java @@ -42,6 +42,7 @@ * @author Gary Russell * @author Artem Bilan * @author Marius Lichtblau + * @author Anton Aharkau */ @SuppressWarnings("serial") public class ExponentialBackOffPolicy implements SleepingBackOffPolicy { diff --git a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java index f6229502..2d20b0f8 100644 --- a/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java +++ b/src/test/java/org/springframework/retry/annotation/EnableRetryTests.java @@ -59,6 +59,7 @@ * @author Aldo Sinanaj * @author Henning Pƶttker * @author Yanming Zhou + * @author Anton Aharkau * @since 1.1 */ public class EnableRetryTests { diff --git a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java index 2c0f390d..3182c14a 100644 --- a/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java +++ b/src/test/java/org/springframework/retry/backoff/ExponentialBackOffPolicyTests.java @@ -26,6 +26,7 @@ * @author Dave Syer * @author Gary Russell * @author Marius Lichtblau + * @author Anton Aharkau */ public class ExponentialBackOffPolicyTests {