fix ProjectionSnapshotRepositoryInMemory.excludeTheHeadBySize

This commit is contained in:
2025-04-05 05:10:27 +02:00
parent d05bf62bf0
commit 0bfeef8a91
2 changed files with 4 additions and 12 deletions

View File

@@ -144,14 +144,8 @@ class ProjectionSnapshotRepositoryInMemory<E : Event<ID>, P : Projection<ID>, ID
*/ */
private fun FilteredList<P>.excludeTheHeadBySize(): FilteredList<P> { private fun FilteredList<P>.excludeTheHeadBySize(): FilteredList<P> {
// filter if size exceeds the limit // filter if size exceeds the limit
if (size > snapshotCacheConfig.maxSnapshotCacheSize) {
val numberToRemove = size - snapshotCacheConfig.maxSnapshotCacheSize
if (numberToRemove > 0) {
return sortedBy { it.first.lastEventVersion } return sortedBy { it.first.lastEventVersion }
.takeLast(numberToRemove) .dropLast(snapshotCacheConfig.maxSnapshotCacheSize)
}
}
return this
} }
/** /**

View File

@@ -11,9 +11,8 @@ import io.kotest.assertions.nondeterministic.eventually
import io.kotest.assertions.nondeterministic.eventuallyConfig import io.kotest.assertions.nondeterministic.eventuallyConfig
import io.kotest.core.spec.style.FunSpec import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.collections.shouldHaveSize
import io.kotest.matchers.comparables.shouldBeGreaterThan
import io.kotest.matchers.equals.shouldBeEqual import io.kotest.matchers.equals.shouldBeEqual
import io.kotest.matchers.ints.shouldBeLessThan import io.kotest.matchers.shouldBe
import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.joinAll import kotlinx.coroutines.joinAll
@@ -148,8 +147,7 @@ class GameStateRepositoryTest :
lastEventVersion shouldBeEqual 1000 lastEventVersion shouldBeEqual 1000
players shouldHaveSize 1000 players shouldHaveSize 1000
} }
repo.count(aggregateId) shouldBeGreaterThan 20 repo.count(aggregateId) shouldBe 119
repo.count(aggregateId) shouldBeLessThan 30
} }
} }
} }