From bae3e621215b640e691e83d7e1358cf11f12e2e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20M=C3=B6ller?= <jakob.moeller@sap.com> Date: Wed, 9 Sep 2020 15:48:08 +0200 Subject: [PATCH] Throw Exception in case we have a failed entry to ensure Abortion of the Transaction (EXPOSUREAPP-2405) (#1134) * Throw Exception in case we have a failed entry to ensure Abortion of the Transaction. Signed-off-by: d067928 <jakob.moeller@sap.com> * Adjust test to not expect call to clear cache files Signed-off-by: d067928 <jakob.moeller@sap.com> --- .../java/de/rki/coronawarnapp/util/CachedKeyFileHolder.kt | 6 +++++- .../de/rki/coronawarnapp/util/CachedKeyFileHolderTest.kt | 2 -- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CachedKeyFileHolder.kt b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CachedKeyFileHolder.kt index 97998f348..bd7a7158e 100644 --- a/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CachedKeyFileHolder.kt +++ b/Corona-Warn-App/src/main/java/de/rki/coronawarnapp/util/CachedKeyFileHolder.kt @@ -37,6 +37,7 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.withContext import timber.log.Timber import java.io.File +import java.io.IOException import java.util.Collections import java.util.Date import java.util.UUID @@ -121,7 +122,10 @@ object CachedKeyFileHolder { deferredQueries.awaitAll() Timber.v("${failedEntryCacheKeys.size} failed entries ") // For an error we clear the cache to try again - keyCache.clear(failedEntryCacheKeys) + if (failedEntryCacheKeys.isNotEmpty()) { + keyCache.clear(failedEntryCacheKeys) + throw IOException("failed to download all key files, at least one failing request.") + } keyCache.getFilesFromEntries() .also { it.forEach { file -> Timber.v("cached file:${file.path}") } } } diff --git a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CachedKeyFileHolderTest.kt b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CachedKeyFileHolderTest.kt index 1d6e89794..607077c1a 100644 --- a/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CachedKeyFileHolderTest.kt +++ b/Corona-Warn-App/src/test/java/de/rki/coronawarnapp/util/CachedKeyFileHolderTest.kt @@ -38,7 +38,6 @@ class CachedKeyFileHolderTest { every { KeyCacheRepository.getDateRepository(any()) } returns keyCacheRepository mockkObject(CachedKeyFileHolder) coEvery { keyCacheRepository.deleteOutdatedEntries(any()) } just Runs - coEvery { keyCacheRepository.clear(any()) } just Runs } /** @@ -65,7 +64,6 @@ class CachedKeyFileHolderTest { keyCacheRepository.deleteOutdatedEntries(any()) CachedKeyFileHolder["getMissingDaysFromDiff"](arrayListOf<String>()) keyCacheRepository.getDates() - keyCacheRepository.clear(emptyList()) keyCacheRepository.getFilesFromEntries() } } -- GitLab