Skip to content

Commit

Permalink
Move retries to constant
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyeh committed May 6, 2024
1 parent 0cd7f64 commit 4770e62
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

public class ExternalUrlKeyReader {
private static final Duration FIXED_DELAY = Duration.ofSeconds(5);
private static final int MAX_RETRIES = 59;

private final String url;
private final ObjectMapper mapper;
Expand Down Expand Up @@ -76,7 +77,7 @@ SafeFuture<String[]> retry() {
return readUrl();
},
FIXED_DELAY,
59)
MAX_RETRIES)
.exceptionallyCompose(
ex ->
SafeFuture.failedFuture(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

class ExternalUrlKeyReaderTest {
private static final Duration DELAY = Duration.ofSeconds(5);
private static final int MAX_RETRIES = 59;
private static final String VALID_URL = "http://test:0000/api/v1/eth2/publicKeys";

private final ObjectMapper mapper = mock(ObjectMapper.class);
Expand Down Expand Up @@ -125,7 +126,7 @@ void readKeysWithRetry_unreachableUrlRetryUntilMaxRetries() throws IOException {
final ExternalUrlKeyReader reader = new ExternalUrlKeyReader(VALID_URL, mapper, asyncRunner);

final SafeFuture<String[]> keys = reader.retry();
for (int i = 0; i < 59; i++) {
for (int i = 0; i < MAX_RETRIES; i++) {
assertThat(keys).isNotCompleted();
timeProvider.advanceTimeBy(DELAY);
asyncRunner.executeQueuedActions();
Expand All @@ -135,6 +136,6 @@ void readKeysWithRetry_unreachableUrlRetryUntilMaxRetries() throws IOException {
.isInstanceOf(CompletionException.class)
.hasCauseInstanceOf(InvalidConfigurationException.class)
.hasRootCause(exception);
verify(mapper, times(60)).readValue(any(URL.class), eq(String[].class));
verify(mapper, times(MAX_RETRIES + 1)).readValue(any(URL.class), eq(String[].class));
}
}

0 comments on commit 4770e62

Please sign in to comment.