diff --git a/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java b/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java index 4cc20f7aba3..97348e7bbd8 100644 --- a/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java +++ b/src/main/java/org/prebid/server/settings/CachingApplicationSettings.java @@ -248,6 +248,7 @@ private static Map getFromCacheOrAddMissedIds(String accountId, public void invalidateAccountCache(String accountId) { accountCache.remove(accountId); + accountToErrorCache.remove(accountId); logger.debug("Account with id {} was invalidated", accountId); } diff --git a/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java b/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java index 9bc9cb27157..66f867ebaf3 100644 --- a/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java +++ b/src/test/java/org/prebid/server/settings/CachingApplicationSettingsTest.java @@ -111,6 +111,52 @@ public void getAccountByIdShouldReturnResultFromCacheOnSuccessiveCalls() { verifyNoMoreInteractions(delegateSettings); } + @Test + public void getAccountByIdShouldReturnResultFromSeparateCallWhenCacheWasInvalidatedForAccount() { + // given + final Account account = Account.builder() + .id("accountId") + .auction(AccountAuctionConfig.builder() + .priceGranularity("med") + .build()) + .build(); + given(delegateSettings.getAccountById(eq("accountId"), same(timeout))) + .willReturn(Future.succeededFuture(account)); + + // when + final Future future = target.getAccountById("accountId", timeout); + target.invalidateAccountCache(account.getId()); + target.getAccountById("accountId", timeout); + + // then + assertThat(future.succeeded()).isTrue(); + assertThat(future.result()).isSameAs(account); + verify(delegateSettings, times(2)).getAccountById(eq("accountId"), same(timeout)); + } + + @Test + public void getAccountByIdShouldReturnResultFromSeparateCallWhenCacheWasInvalidatedForAllAccounts() { + // given + final Account account = Account.builder() + .id("accountId") + .auction(AccountAuctionConfig.builder() + .priceGranularity("med") + .build()) + .build(); + given(delegateSettings.getAccountById(eq("accountId"), same(timeout))) + .willReturn(Future.succeededFuture(account)); + + // when + final Future future = target.getAccountById("accountId", timeout); + target.invalidateAccountCache("accountId"); + target.getAccountById("accountId", timeout); + + // then + assertThat(future.succeeded()).isTrue(); + assertThat(future.result()).isSameAs(account); + verify(delegateSettings, times(2)).getAccountById(eq("accountId"), same(timeout)); + } + @Test public void getAccountByIdShouldPropagateFailure() { // given @@ -149,6 +195,46 @@ public void getAccountByIdShouldCachePreBidException() { .hasMessage("error"); } + @Test + public void getAccountByIdShouldThrowSeparatePreBidExceptionWhenCacheWasInvalidatedForAccount() { + // given + given(delegateSettings.getAccountById(anyString(), any())) + .willReturn(Future.failedFuture(new PreBidException("error"))); + + // when + target.getAccountById("accountId", timeout); + target.invalidateAccountCache("accountId"); + final Future lastFuture = target + .getAccountById("accountId", timeout); + + // then + verify(delegateSettings, times(2)).getAccountById(eq("accountId"), same(timeout)); + assertThat(lastFuture.failed()).isTrue(); + assertThat(lastFuture.cause()) + .isInstanceOf(PreBidException.class) + .hasMessage("error"); + } + + @Test + public void getAccountByIdShouldThrowSeparatePreBidExceptionWhenCacheWasInvalidatedForAllAccounts() { + // given + given(delegateSettings.getAccountById(anyString(), any())) + .willReturn(Future.failedFuture(new PreBidException("error"))); + + // when + target.getAccountById("accountId", timeout); + target.invalidateAccountCache("accountId"); + final Future lastFuture = target + .getAccountById("accountId", timeout); + + // then + verify(delegateSettings, times(2)).getAccountById(eq("accountId"), same(timeout)); + assertThat(lastFuture.failed()).isTrue(); + assertThat(lastFuture.cause()) + .isInstanceOf(PreBidException.class) + .hasMessage("error"); + } + @Test public void getAccountByIdShouldNotCacheNotPreBidException() { // given