From 4913e99c2e4e89949d7662d69bcc8e4dea5f9fa8 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Jul 2024 16:40:30 +0600 Subject: [PATCH 1/6] start 0.21.6 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7073379f1b5..9d1176879f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.21.6 + ## 0.21.5 * `KSP`: diff --git a/gradle.properties b/gradle.properties index 92bac1cd669..00bb79cbadb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,5 +15,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.21.5 -android_code_version=264 +version=0.21.6 +android_code_version=265 From ad401105a1b62be9f4d6b9ba311fa7af2b83537a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 26 Jul 2024 17:17:11 +0600 Subject: [PATCH 2/6] fixes in ksp sealed generator --- CHANGELOG.md | 4 ++++ ksp/sealed/generator/src/main/kotlin/Processor.kt | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1176879f5..34ce9695623 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## 0.21.6 +* `KSP`: + * `Sealed`: + * Fixes in generation + ## 0.21.5 * `KSP`: diff --git a/ksp/sealed/generator/src/main/kotlin/Processor.kt b/ksp/sealed/generator/src/main/kotlin/Processor.kt index de653834d08..6eca44452a7 100644 --- a/ksp/sealed/generator/src/main/kotlin/Processor.kt +++ b/ksp/sealed/generator/src/main/kotlin/Processor.kt @@ -26,7 +26,8 @@ class Processor( private fun KSClassDeclaration.findSealedConnection(potentialSealedParent: KSClassDeclaration): Boolean { val targetClassname = potentialSealedParent.qualifiedName ?.asString() return superTypes.any { - targetClassname == ((it.resolve().declaration as? KSClassDeclaration) ?.qualifiedName ?.asString()) || (it is KSClassDeclaration && it.getSealedSubclasses().any() && it.findSealedConnection(potentialSealedParent)) + val itAsDeclaration = it.resolve().declaration as? KSClassDeclaration ?: return@any false + targetClassname == (itAsDeclaration.qualifiedName ?.asString()) || (itAsDeclaration.getSealedSubclasses().any() && itAsDeclaration.findSealedConnection(potentialSealedParent)) } } From 2df7e9b529f8fb74310c3ea61a2dc78e747c4a84 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Fri, 2 Aug 2024 21:40:22 +0300 Subject: [PATCH 3/6] drafted test for MapCRUDRepo. --- .../src/commonTest/kotlin/MapCRUDRepoTest.kt | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt diff --git a/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt b/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt new file mode 100644 index 00000000000..fc386c3971c --- /dev/null +++ b/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt @@ -0,0 +1,100 @@ +import dev.inmo.micro_utils.repos.MapCRUDRepo +import dev.inmo.micro_utils.repos.create +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.runTest +import kotlin.test.Test +import kotlin.test.assertEquals + +data class TestModel( + val testery: String, + val isTestery: Boolean, + val testeryAmount: Int +) + +class MapCRUDRepoTest { + /** + * A utility function used for generating non-intersecting ranges in cyclic environment, like [repeat] + * or for-loops + */ + private fun getIdRange(start: Int, base: Int) = (start * base)..(start * base + (base - 1)) + + @Test + fun mapCrudRepoTest() = runTest { + val base = 200 // define a bigger number to increase test intensity + val targetMap = mutableMapOf() + + // filling the map + val jobs = List(base) { id -> + launch(Dispatchers.Default) { // to make delays work + println("launching job $id") + delay((1..5).random().toLong()) + + val idsList = getIdRange(id, base).toMutableList() + println("created ids list $idsList") + val mapCRUDRepo = MapCRUDRepo( + targetMap, + createCallback = { new -> + val newObject = idsList.first() to new + idsList.remove(newObject.first) + println("created $newObject in map") + newObject + }, + updateCallback = { new, id, old -> + println("updated object at $id from $old to $new") + new + } + ) + for (i in getIdRange(id, base)) { + val newModel = TestModel( + testery = "testery$i", + isTestery = i % 2 == 0, + testeryAmount = i + ) + mapCRUDRepo.create(newModel) + } + } + } + + jobs.forEach { + println("joining job ${it.hashCode()}") + it.join() + } + + // validating the map + val validationJobs = List(base) { id -> + launch { + val idsList = getIdRange(id, base).toMutableList() + val mapCRUDRepo = MapCRUDRepo( + targetMap, + // these will not be used + createCallback = { new -> + val newObject = idsList.first() to new + idsList.remove(newObject.first) + println("created $newObject in map") + newObject + }, + updateCallback = { new, id, old -> + println("updated object at $id from $old to $new") + new + } + ) + for (i in getIdRange(id, base)) { + val newModel = TestModel( + testery = "testery$i", + isTestery = i % 2 == 0, + testeryAmount = i + ) + val oldModel = mapCRUDRepo.getById(i) + assertEquals(newModel, oldModel) + } + } + } + + validationJobs.forEach { + println("joining validation job ${it.hashCode()}") + it.join() + } + } +} \ No newline at end of file From 0c1256f4690f72f9032184fad01b2ba12e4a0c13 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Sat, 3 Aug 2024 11:45:14 +0300 Subject: [PATCH 4/6] made test for MapCRUDRepo.update(id, newObject) --- .../src/commonTest/kotlin/MapCRUDRepoTest.kt | 85 ++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt b/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt index fc386c3971c..e777f042fb2 100644 --- a/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt +++ b/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt @@ -22,7 +22,7 @@ class MapCRUDRepoTest { @Test fun mapCrudRepoTest() = runTest { - val base = 200 // define a bigger number to increase test intensity + val base = 4 // define a bigger number to increase test intensity val targetMap = mutableMapOf() // filling the map @@ -97,4 +97,87 @@ class MapCRUDRepoTest { it.join() } } + + @Test + fun updateMapCrudRepoTest() = runTest { + val base = 10 // define a bigger number to increase test intensity + val targetMap = mutableMapOf() + + // fill the map using stdlib method + repeat(base * base) { num -> + targetMap[num] = TestModel( + testery = "testery$num", + isTestery = num % 2 == 0, + testeryAmount = num + ) + } + + // update the map using MapCRUDRepo + val jobs = List(base) { id -> + launch { + println("launching job $id") + val idsList = getIdRange(id, base).toMutableList() + val mapCRUDRepo = MapCRUDRepo( + targetMap, + updateCallback = { new, id, old -> + println("updated object at $id from $old to $new") + new + }, + createCallback = { new -> + val newObject = idsList.first() to new + idsList.remove(newObject.first) + println("created $newObject in map") + newObject + } + ) + for (i in getIdRange(id, base)) { + val newModel = TestModel( + testery = "testery${i}new", + isTestery = i % 2 == 0, + testeryAmount = i + ) + mapCRUDRepo.update(i, newModel) + } + } + } + + jobs.forEach { + println("joining job ${it.hashCode()}") + it.join() + } + + // validating the map + val validationJobs = List(base) { id -> + launch { + val idsList = getIdRange(id, base).toMutableList() + val mapCRUDRepo = MapCRUDRepo( + targetMap, + updateCallback = { new, id, old -> + println("updated object at $id from $old to $new") + new + }, + createCallback = { new -> + val newObject = idsList.first() to new + idsList.remove(newObject.first) + println("created $newObject in map") + newObject + } + ) + for (i in getIdRange(id, base)) { + val newModel = TestModel( + testery = "testery${i}new", + isTestery = i % 2 == 0, + testeryAmount = i + ) + val oldModel = mapCRUDRepo.getById(i) + assertEquals(newModel, oldModel) + } + } + } + + validationJobs.forEach { + println("joining validation job ${it.hashCode()}") + it.join() + } + } } \ No newline at end of file From 0865faa1d800e4a13e94b424c06b79e9459f63d9 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Sat, 3 Aug 2024 11:48:44 +0300 Subject: [PATCH 5/6] added vararg deletion feature --- .../kotlin/dev/inmo/micro_utils/repos/StandartCRUDRepo.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartCRUDRepo.kt b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartCRUDRepo.kt index 28a9b94983f..c029c83f954 100644 --- a/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartCRUDRepo.kt +++ b/repos/common/src/commonMain/kotlin/dev/inmo/micro_utils/repos/StandartCRUDRepo.kt @@ -39,6 +39,7 @@ interface WriteCRUDRepo : Repo { suspend fun update(id: IdType, value: InputValueType): ObjectType? suspend fun update(values: List>): List suspend fun deleteById(ids: List) + suspend fun deleteById(vararg ids: IdType) = deleteById(ids.toList()) } typealias WriteStandardCRUDRepo = WriteCRUDRepo From d325cfd2988cce730b894531864d5f3edf052622 Mon Sep 17 00:00:00 2001 From: bpavuk Date: Sat, 3 Aug 2024 11:58:19 +0300 Subject: [PATCH 6/6] added deletion test --- .../src/commonTest/kotlin/MapCRUDRepoTest.kt | 119 +++++++++++++++--- 1 file changed, 101 insertions(+), 18 deletions(-) diff --git a/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt b/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt index e777f042fb2..3dc84bfb78d 100644 --- a/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt +++ b/repos/inmemory/src/commonTest/kotlin/MapCRUDRepoTest.kt @@ -26,12 +26,12 @@ class MapCRUDRepoTest { val targetMap = mutableMapOf() // filling the map - val jobs = List(base) { id -> + val jobs = List(base) { jobId -> launch(Dispatchers.Default) { // to make delays work - println("launching job $id") + println("launching job $jobId") delay((1..5).random().toLong()) - val idsList = getIdRange(id, base).toMutableList() + val idsList = getIdRange(jobId, base).toMutableList() println("created ids list $idsList") val mapCRUDRepo = MapCRUDRepo( targetMap, @@ -46,11 +46,11 @@ class MapCRUDRepoTest { new } ) - for (i in getIdRange(id, base)) { + for (id in getIdRange(jobId, base)) { val newModel = TestModel( - testery = "testery$i", - isTestery = i % 2 == 0, - testeryAmount = i + testery = "testery$id", + isTestery = id % 2 == 0, + testeryAmount = id ) mapCRUDRepo.create(newModel) } @@ -113,10 +113,10 @@ class MapCRUDRepoTest { } // update the map using MapCRUDRepo - val jobs = List(base) { id -> + val jobs = List(base) { jobId -> launch { - println("launching job $id") - val idsList = getIdRange(id, base).toMutableList() + println("launching job $jobId") + val idsList = getIdRange(jobId, base).toMutableList() val mapCRUDRepo = MapCRUDRepo( targetMap, updateCallback = { new, id, old -> @@ -130,13 +130,13 @@ class MapCRUDRepoTest { newObject } ) - for (i in getIdRange(id, base)) { + for (id in getIdRange(jobId, base)) { val newModel = TestModel( - testery = "testery${i}new", - isTestery = i % 2 == 0, - testeryAmount = i + testery = "testery${id}new", + isTestery = id % 2 == 0, + testeryAmount = id ) - mapCRUDRepo.update(i, newModel) + mapCRUDRepo.update(id, newModel) } } } @@ -147,9 +147,9 @@ class MapCRUDRepoTest { } // validating the map - val validationJobs = List(base) { id -> + val validationJobs = List(base) { jobId -> launch { - val idsList = getIdRange(id, base).toMutableList() + val idsList = getIdRange(jobId, base).toMutableList() val mapCRUDRepo = MapCRUDRepo( targetMap, updateCallback = { new, id, old -> @@ -163,7 +163,7 @@ class MapCRUDRepoTest { newObject } ) - for (i in getIdRange(id, base)) { + for (i in getIdRange(jobId, base)) { val newModel = TestModel( testery = "testery${i}new", isTestery = i % 2 == 0, @@ -180,4 +180,87 @@ class MapCRUDRepoTest { it.join() } } + + @Test + fun deleteMapCrudRepoTest() = runTest { + val base = 10 // define a bigger number to increase test intensity + val targetMap = mutableMapOf() + + // fill the map using stdlib methods + repeat(base * base) { num -> + targetMap[num] = TestModel( + testery = "testery$num", + isTestery = num % 2 == 0, + testeryAmount = num + ) + } + + // delete every even element from the map + val jobs = List(base) { jobId -> + launch { + val idsList = getIdRange(jobId, base).toMutableList() + println("idsList: $idsList") + val mapCRUDRepo = MapCRUDRepo( + targetMap, + // these will not be used + createCallback = { new -> + val newObject = idsList.first() to new + idsList.remove(newObject.first) + println("created $newObject in map") + newObject + }, + updateCallback = { new, id, old -> + println("updated object at $id from $old to $new") + new + } + ) + for (id in getIdRange(jobId, base)) { + if (id % 2 == 0 /* testery.isTestery */) { + println("deleting $id") + mapCRUDRepo.deleteById(id) + } + } + } + } + + jobs.forEach { + println("joining job ${it.hashCode()}") + it.join() + } + + // validating the map + val validationJobs = List(base) { id -> + launch { + val idsList = getIdRange(id, base).toMutableList() + val mapCRUDRepo = MapCRUDRepo( + targetMap, + // these will not be used + createCallback = { new -> + val newObject = idsList.first() to new + idsList.remove(newObject.first) + println("created $newObject in map") + newObject + }, + updateCallback = { new, id, old -> + println("updated object at $id from $old to $new") + new + } + ) + for (id in getIdRange(id, base)) { + val newModel = TestModel( + testery = "testery${id}", + isTestery = id % 2 == 0, + testeryAmount = id + ) + val oldModel = mapCRUDRepo.getById(id) + assertEquals(if (newModel.isTestery) null else newModel, oldModel) + } + } + } + + validationJobs.forEach { + println("joining validation job ${it.hashCode()}") + it.join() + } + } } \ No newline at end of file