minor modifications

This commit is contained in:
priyank-sriv 2019-07-23 01:52:22 +05:30
parent 4e22e8b3c6
commit cb686cf9c4
3 changed files with 8 additions and 13 deletions

View File

@ -0,0 +1,2 @@
### Relevant Articles:
- [Better Retries with Exponential Backoff and Jitter](https://baeldung.com/retries-with-exponential-backoff-and-jitter)

View File

@ -8,13 +8,6 @@
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<!--<parent>-->
<!--<artifactId>patterns</artifactId>-->
<!--<groupId>com.baeldung</groupId>-->
<!--<version>1.0.0-SNAPSHOT</version>-->
<!--<relativePath>..</relativePath>-->
<!--</parent>-->
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>

View File

@ -39,7 +39,7 @@ public class BackoffWithJitterTest {
} }
private PingPongService service; private PingPongService service;
private static final int NUM_TASKS = 8; private static final int NUM_CONCURRENT_CLIENTS = 8;
@Before @Before
public void setUp() { public void setUp() {
@ -55,7 +55,7 @@ public class BackoffWithJitterTest {
try { try {
pingPongFn.apply("Hello"); pingPongFn.apply("Hello");
} catch (PingPongServiceException e) { } 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 { private void test(IntervalFunction intervalFn) throws InterruptedException {
Function<String, String> pingPongFn = getRetryablePingPongFn(intervalFn); Function<String, String> pingPongFn = getRetryablePingPongFn(intervalFn);
ExecutorService executors = newFixedThreadPool(NUM_TASKS); ExecutorService executors = newFixedThreadPool(NUM_CONCURRENT_CLIENTS);
List<Callable<String>> tasks = nCopies(NUM_TASKS, () -> pingPongFn.apply("Hello")); List<Callable<String>> tasks = nCopies(NUM_CONCURRENT_CLIENTS, () -> pingPongFn.apply("Hello"));
when(service.call(anyString())).thenThrow(PingPongServiceException.class); when(service.call(anyString())).thenThrow(PingPongServiceException.class);
@ -83,7 +83,7 @@ public class BackoffWithJitterTest {
private Function<String, String> getRetryablePingPongFn(IntervalFunction intervalFn) { private Function<String, String> getRetryablePingPongFn(IntervalFunction intervalFn) {
RetryConfig retryConfig = RetryConfig.custom() RetryConfig retryConfig = RetryConfig.custom()
.maxAttempts(MAX_TRIES) .maxAttempts(MAX_RETRIES)
.intervalFunction(intervalFn) .intervalFunction(intervalFn)
.retryExceptions(PingPongServiceException.class) .retryExceptions(PingPongServiceException.class)
.build(); .build();
@ -98,6 +98,6 @@ public class BackoffWithJitterTest {
static final Long INITIAL_INTERVAL = 1000L; static final Long INITIAL_INTERVAL = 1000L;
static final Double MULTIPLIER = 2.0D; static final Double MULTIPLIER = 2.0D;
static final Double RANDOMIZATION_FACTOR = 0.6D; static final Double RANDOMIZATION_FACTOR = 0.6D;
static final Integer MAX_TRIES = 4; static final Integer MAX_RETRIES = 4;
} }
} }