-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EXPOSED-689 warmUpLinkedReferences() should not return all the values…
… from cache (#2355) * EXPOSED-689 warmUpLinkedReferences() should not return all the values from cache
- Loading branch information
1 parent
07575c1
commit 36501a5
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...est/kotlin/org/jetbrains/exposed/sql/tests/shared/entities/WarmUpLinkedReferencesTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.jetbrains.exposed.sql.tests.shared.entities | ||
|
||
import org.jetbrains.exposed.dao.IntEntity | ||
import org.jetbrains.exposed.dao.IntEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.IntIdTable | ||
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase | ||
import org.jetbrains.exposed.sql.tests.shared.assertEquals | ||
import org.junit.Test | ||
|
||
class WarmUpLinkedReferencesTests : DatabaseTestsBase() { | ||
|
||
object Box : IntIdTable() { | ||
val value = integer("value") | ||
} | ||
|
||
class EBox(id: EntityID<Int>) : IntEntity(id) { | ||
var value by Box.value | ||
|
||
companion object : IntEntityClass<EBox>(Box) | ||
} | ||
|
||
object BoxItem : IntIdTable() { | ||
val box = reference("box", Box) | ||
|
||
val value = integer("value") | ||
} | ||
|
||
class EBoxItem(id: EntityID<Int>) : IntEntity(id) { | ||
var value by BoxItem.value | ||
var box by EBox referencedOn BoxItem.box | ||
|
||
companion object : IntEntityClass<EBoxItem>(BoxItem) | ||
} | ||
|
||
@Test | ||
fun warmUpLinkedReferencesShouldNotReturnAllTheValueFromCache() { | ||
withTables(Box, BoxItem) { | ||
val boxEntities = (0..4).map { | ||
EBox.new { | ||
value = it | ||
} | ||
} | ||
|
||
boxEntities.forEach { | ||
EBoxItem.new { | ||
box = it | ||
value = it.id.value | ||
} | ||
} | ||
|
||
val ids = boxEntities.map { it.id } | ||
|
||
// Warm up all the entities to fill the cache | ||
EBox.warmUpLinkedReferences(ids, BoxItem) | ||
|
||
val warmedUp = EBox.warmUpLinkedReferences(ids.slice(0..2), BoxItem) | ||
assertEquals(3, warmedUp.size) | ||
} | ||
} | ||
} |