blob: 780bbd3ece519c8f8407ac3631f5206acec94a0e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package com.pitchedapps.frost.db
import kotlinx.coroutines.runBlocking
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.test.fail
class CacheDbTest : BaseDbTest() {
private val dao get() = db.cacheDao()
private val cookieDao get() = db.cookieDao()
private fun cookie(id: Long) = CookieEntity(id, "name$id", "cookie$id")
@Test
fun save() {
val cookie = cookie(1L)
val type = "test"
val content = "long test".repeat(10000)
runBlocking {
cookieDao.insertCookie(cookie)
dao.save(cookie.id, type, content)
val cache = dao.select(cookie.id, type) ?: fail("Cache not found")
assertEquals(content, cache.contents, "Content mismatch")
assertTrue(
System.currentTimeMillis() - cache.lastUpdated < 500,
"Cache retrieval took over 500ms (${System.currentTimeMillis() - cache.lastUpdated})"
)
}
}
}
|