extract projection snapshot logic

implement GameStateRepositoryTest
add lambda to the GameEventHandler.handle{} to set the version

add VersionBuilder
add version to the events
add creation date to the events
rename gameId to aggregateId
add EventHandler interface
This commit is contained in:
2025-03-13 00:27:44 +01:00
parent d5b033e731
commit 286dedac76
36 changed files with 684 additions and 266 deletions

View File

@@ -0,0 +1,42 @@
package eventDemo.libs.event
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.equals.shouldBeEqual
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
@OptIn(DelicateCoroutinesApi::class)
class VersionBuilderLocalTest :
FunSpec({
test("buildNextVersion") {
VersionBuilderLocal().run {
buildNextVersion() shouldBeEqual 1
buildNextVersion() shouldBeEqual 2
buildNextVersion() shouldBeEqual 3
}
}
test("buildNextVersion concurrently") {
val versionBuilder = VersionBuilderLocal()
(1..20)
.map {
GlobalScope.launch {
(1..1000).map {
versionBuilder.buildNextVersion()
}
}
}.joinAll()
versionBuilder.getLastVersion() shouldBeEqual 20 * 1000
}
test("getLastVersion") {
VersionBuilderLocal().run {
getLastVersion() shouldBeEqual 0
getLastVersion() shouldBeEqual 0
getLastVersion() shouldBeEqual 0
}
}
})