Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

EOL - default stats (EXPOSUREAPP-14836) #5864

Merged
merged 7 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

1
�ҟ�%https://corona-pandemieradar.de/:lang
SamuraiKek marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9c965a43d7bb263b4cb26c3dac32ec6fb51e210215b2e903ca98bd0635586e03
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.rki.coronawarnapp.statistics.source

import android.content.Context
import dagger.Reusable
import de.rki.coronawarnapp.util.di.AppContext
import javax.inject.Inject

@Reusable
class DefaultStatsSource @Inject constructor(
@AppContext private val context: Context,
) {

fun getDefaultStats(): ByteArray {
return context.assets.open("default_stats/default_stats.bin").readBytes()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import javax.inject.Singleton

@Singleton
class StatisticsCache @Inject constructor(
@Statistics cacheDir: File
@Statistics cacheDir: File,
private val defaultStatsSource: DefaultStatsSource
) : Resettable {

private val cacheFile = File(cacheDir, "cache_raw")

fun load(): ByteArray? = try {
if (cacheFile.exists()) cacheFile.readBytes() else null
if (cacheFile.exists()) cacheFile.readBytes() else defaultStatsSource.getDefaultStats()
} catch (e: Exception) {
Timber.tag(TAG).e(e, "Failed to load raw statistics from cache.")
null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class StatisticsProvider @Inject constructor(
private fun fromCache(): StatisticsData? = try {
Timber.tag(TAG).d("fromCache()")
val rawData = localCache.load()
rawData?.let { it -> parser.parse(it) }?.also {
rawData?.let { parser.parse(it) }?.also {
Timber.tag(TAG).d("Parsed from cache: %s", it)
if (!it.isDataAvailable) {
Timber.tag(TAG).w("RawData: %s", rawData.toHexString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package de.rki.coronawarnapp.statistics.source

import io.kotest.matchers.shouldBe
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
Expand All @@ -18,10 +20,12 @@ class StatisticsCacheTest : BaseIOTest() {
private val cacheFile = File(statisticsCacheDir, "cache_raw")

private val testData = "Row, Row, Row Your Boat".encodeToByteArray()
@MockK lateinit var defaultStatsSource: DefaultStatsSource

@BeforeEach
fun setup() {
MockKAnnotations.init(this)
every { defaultStatsSource.getDefaultStats() } returns byteArrayOf()
}

@AfterEach
Expand All @@ -30,12 +34,13 @@ class StatisticsCacheTest : BaseIOTest() {
}

fun createInstance() = StatisticsCache(
cacheDir = statisticsCacheDir
cacheDir = statisticsCacheDir,
defaultStatsSource = defaultStatsSource
)

@Test
fun `empty start`() {
createInstance().load() shouldBe null
createInstance().load() shouldBe byteArrayOf()
cacheFile.exists() shouldBe false
}

Expand Down