From cb686cf9c4f1587d729e66668ec9387631b4a1f9 Mon Sep 17 00:00:00 2001 From: priyank-sriv Date: Tue, 23 Jul 2019 01:52:22 +0530 Subject: [PATCH] minor modifications --- patterns/backoff-jitter/README.md | 2 ++ patterns/backoff-jitter/pom.xml | 7 ------- .../backoff/jitter/BackoffWithJitterTest.java | 12 ++++++------ 3 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 patterns/backoff-jitter/README.md diff --git a/patterns/backoff-jitter/README.md b/patterns/backoff-jitter/README.md new file mode 100644 index 0000000000..6459e4c8e0 --- /dev/null +++ b/patterns/backoff-jitter/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Better Retries with Exponential Backoff and Jitter](https://baeldung.com/retries-with-exponential-backoff-and-jitter) diff --git a/patterns/backoff-jitter/pom.xml b/patterns/backoff-jitter/pom.xml index 0a48a18abb..6b0d016609 100644 --- a/patterns/backoff-jitter/pom.xml +++ b/patterns/backoff-jitter/pom.xml @@ -8,13 +8,6 @@ 1.0.0-SNAPSHOT pom - - - - - - - junit diff --git a/patterns/backoff-jitter/src/test/java/com/baeldung/backoff/jitter/BackoffWithJitterTest.java b/patterns/backoff-jitter/src/test/java/com/baeldung/backoff/jitter/BackoffWithJitterTest.java index 0f0e652596..f6b3ebbe45 100644 --- a/patterns/backoff-jitter/src/test/java/com/baeldung/backoff/jitter/BackoffWithJitterTest.java +++ b/patterns/backoff-jitter/src/test/java/com/baeldung/backoff/jitter/BackoffWithJitterTest.java @@ -39,7 +39,7 @@ public class BackoffWithJitterTest { } private PingPongService service; - private static final int NUM_TASKS = 8; + private static final int NUM_CONCURRENT_CLIENTS = 8; @Before public void setUp() { @@ -55,7 +55,7 @@ public class BackoffWithJitterTest { try { pingPongFn.apply("Hello"); } catch (PingPongServiceException e) { - verify(service, times(MAX_TRIES)).call(anyString()); + verify(service, times(MAX_RETRIES)).call(anyString()); } } @@ -73,8 +73,8 @@ public class BackoffWithJitterTest { private void test(IntervalFunction intervalFn) throws InterruptedException { Function pingPongFn = getRetryablePingPongFn(intervalFn); - ExecutorService executors = newFixedThreadPool(NUM_TASKS); - List> tasks = nCopies(NUM_TASKS, () -> pingPongFn.apply("Hello")); + ExecutorService executors = newFixedThreadPool(NUM_CONCURRENT_CLIENTS); + List> tasks = nCopies(NUM_CONCURRENT_CLIENTS, () -> pingPongFn.apply("Hello")); when(service.call(anyString())).thenThrow(PingPongServiceException.class); @@ -83,7 +83,7 @@ public class BackoffWithJitterTest { private Function getRetryablePingPongFn(IntervalFunction intervalFn) { RetryConfig retryConfig = RetryConfig.custom() - .maxAttempts(MAX_TRIES) + .maxAttempts(MAX_RETRIES) .intervalFunction(intervalFn) .retryExceptions(PingPongServiceException.class) .build(); @@ -98,6 +98,6 @@ public class BackoffWithJitterTest { static final Long INITIAL_INTERVAL = 1000L; static final Double MULTIPLIER = 2.0D; static final Double RANDOMIZATION_FACTOR = 0.6D; - static final Integer MAX_TRIES = 4; + static final Integer MAX_RETRIES = 4; } }