2024-08-09 15:58:09 +00:00
|
|
|
package dev.inmo.micro_utils.repos.common.tests
|
|
|
|
|
2024-08-09 13:22:32 +00:00
|
|
|
import com.benasher44.uuid.uuid4
|
|
|
|
import dev.inmo.micro_utils.repos.*
|
|
|
|
import korlibs.time.seconds
|
|
|
|
import kotlinx.coroutines.joinAll
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import kotlinx.coroutines.test.runTest
|
|
|
|
import kotlin.test.*
|
|
|
|
|
|
|
|
abstract class CommonKeyValuesRepoTests : CommonRepoTests<KeyValuesRepo<String, String>>() {
|
2024-08-09 15:58:09 +00:00
|
|
|
@Test
|
|
|
|
fun creatingWorksProperly() = runTest(timeout = 120.seconds) {
|
2024-08-09 13:22:32 +00:00
|
|
|
val repo = repoCreator()
|
|
|
|
val testData = (0 until testSequencesSize).associate {
|
|
|
|
("$it-" + uuid4().toString()) to (0 until 1000).map {
|
|
|
|
"$it-" + uuid4().toString()
|
|
|
|
}.sorted()
|
|
|
|
}
|
|
|
|
val updatedTestData = testData.keys.associateWith {
|
|
|
|
(0 until 1000).map {
|
|
|
|
"$it-" + uuid4().toString()
|
|
|
|
}.sorted()
|
|
|
|
}
|
|
|
|
val addedData = testData.keys.associateWith {
|
|
|
|
"$it-" + uuid4().toString()
|
|
|
|
}
|
|
|
|
|
|
|
|
updatedTestData.map {
|
|
|
|
launch {
|
|
|
|
repo.set(it.key, it.value)
|
|
|
|
assertContentEquals(it.value.sorted(), repo.getAll(it.key).sorted())
|
|
|
|
}
|
|
|
|
}.joinAll()
|
|
|
|
|
|
|
|
updatedTestData.map {
|
|
|
|
launch {
|
|
|
|
repo.set(it.key, it.value)
|
|
|
|
val all = repo.getAll(it.key)
|
|
|
|
assertContentEquals(it.value.sorted(), all.sorted())
|
|
|
|
}
|
|
|
|
}.joinAll()
|
|
|
|
|
|
|
|
addedData.forEach {
|
|
|
|
repo.add(it.key, it.value)
|
|
|
|
assertTrue(repo.contains(it.key, it.value))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|