Skip to content

Commit

Permalink
another concurrency simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr committed Jan 31, 2022
1 parent 39be076 commit 0274f82
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ public synchronized SafeFuture<Optional<ProposerConfig>> getProposerConfig() {
}

if (futureProposerConfig.isPresent()) {
if (lastProposerConfig.isPresent()) {
LOG.warn("A proposer config load is in progress, providing last loaded config");
return SafeFuture.completedFuture(lastProposerConfig);
}
LOG.warn(
"A proposer config load is already progress, waiting it instead of generating a new request");
return futureProposerConfig.get();
}
futureProposerConfig =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void getProposerConfig_onErrorShouldReturnLastConfigWhenLastConfigAvailable() {
}

@Test
void getProposerConfig_onConcurrentCallsShouldMergeFuturesWhenNoLastConfigAvailable() {
void getProposerConfig_onConcurrentCallsShouldMergeFutures() {
SafeFuture<Optional<ProposerConfig>> futureMaybeConfig =
proposerConfigProvider.getProposerConfig();

Expand All @@ -112,28 +112,6 @@ void getProposerConfig_onConcurrentCallsShouldMergeFuturesWhenNoLastConfigAvaila
assertThat(futureMaybeConfig).isCompletedWithValue(Optional.of(proposerConfigA));
}

@Test
void getProposerConfig_onConcurrentCallsShouldReturnLastConfigWhenLastConfigAvailable() {
SafeFuture<Optional<ProposerConfig>> futureMaybeConfig =
proposerConfigProvider.getProposerConfig();

when(proposerConfigLoader.getProposerConfig(sourceUrl)).thenReturn(proposerConfigA);
asyncRunner.executeQueuedActions();

assertThat(futureMaybeConfig).isCompletedWithValue(Optional.of(proposerConfigA));

futureMaybeConfig = proposerConfigProvider.getProposerConfig();
SafeFuture<Optional<ProposerConfig>> futureMaybeConfig2 =
proposerConfigProvider.getProposerConfig();

assertThat(futureMaybeConfig2).isCompletedWithValue(Optional.of(proposerConfigA));

when(proposerConfigLoader.getProposerConfig(sourceUrl)).thenReturn(proposerConfigB);
asyncRunner.executeQueuedActions();

assertThat(futureMaybeConfig).isCompletedWithValue(Optional.of(proposerConfigB));
}

@Test
void getProposerConfig_shouldAlwaysReturnFirstValidConfigWhenRefreshIsFalse() {
final ProposerConfigProvider proposerConfigProvider =
Expand Down

0 comments on commit 0274f82

Please sign in to comment.