Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Fix failing Oracle tests in exposed-tests #1831

Merged
merged 1 commit into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ class CreateMissingTablesAndColumnsTests : DatabaseTestsBase() {
val traceNumber = reference("traceNumber", ordersTable.traceNumber)
}

withDb {
// Oracle metadata only returns foreign keys that reference primary keys
withDb(excludeSettings = listOf(TestDB.ORACLE)) {
Comment on lines 520 to +524
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative to excluding Oracle would be to change the mapping of the test tables so that a primary key is referenced instead of a unique index:

val ordersTable = object : Table("tmporders") {
    val traceNumber = char("traceNumber", 10)
    override val primaryKey = PrimaryKey(traceNumber)
}
val receiptsTable = object : IntIdTable("receipts") {
    val traceNumber = reference("traceNumber", ordersTable.traceNumber)
}

This would still retain the original intention of the unit test, I think, which seems more about column naming than whether the column is a primary key or a unique index.

SchemaUtils.createMissingTablesAndColumns(ordersTable, receiptsTable)
assertTrue(ordersTable.exists())
assertTrue(receiptsTable.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
import org.jetbrains.exposed.sql.statements.api.ExposedBlob
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase
import org.jetbrains.exposed.sql.tests.TestDB
import org.jetbrains.exposed.sql.tests.currentDialectTest
import org.jetbrains.exposed.sql.tests.shared.*
import org.jetbrains.exposed.sql.transactions.TransactionManager
import org.jetbrains.exposed.sql.transactions.inTopLevelTransaction
import org.jetbrains.exposed.sql.vendors.OracleDialect
import org.junit.Test
import java.sql.Connection
import java.util.*
Expand Down Expand Up @@ -754,10 +756,9 @@ class EntityTests : DatabaseTestsBase() {
var holidays by Holiday via SchoolHolidays
}

@Test fun preloadReferencesOnASizedIterable() {

@Test
fun preloadReferencesOnASizedIterable() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -796,10 +797,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadReferencesOnAnEntity() {

@Test
fun preloadReferencesOnAnEntity() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -829,9 +829,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadOptionalReferencesOnASizedIterable() {
@Test
fun preloadOptionalReferencesOnASizedIterable() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand All @@ -844,6 +844,9 @@ class EntityTests : DatabaseTestsBase() {
name = "Eton"
region = region1
secondaryRegion = region2
}.apply {
// otherwise Oracle provides school1.id = 0 to testCache(), which returns null
if (currentDialectTest is OracleDialect) flush()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. What does flush mean? Maybe I missed it, but I couldn't find anything about it in the documentation.
  2. Do you think this test reflects real-life usage? If we expect users to use Exposed like this with Oracle, what do you think of adding this to the documentation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When new() is used, it creates an entity but then just queues it in a cache for insertion (even though SQL statements are logged). flush() manually takes the entities in the cache (as well as any entities that have been queued for update) and sends the values to the database. This happens under-the-hood at the end of a transaction or before/during certain other functions that force access to the entities.

I don't think this is a real-life scenario for any users, using testCache(), as anything that would access the created entity would trigger a flush. For example, if the apply {} block was removed and I did something like findById() or even just a println(school1.id), the test would pass.

}

val school2 = School.new {
Expand All @@ -866,10 +869,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadOptionalReferencesOnAnEntity() {

@Test
fun preloadOptionalReferencesOnAnEntity() {
withTables(Regions, Schools) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -897,10 +899,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadReferrersOnASizedIterable() {

@Test
fun preloadReferrersOnASizedIterable() {
withTables(Regions, Schools, Students) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -959,9 +960,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadReferrersOnAnEntity() {
@Test
fun preloadReferrersOnAnEntity() {
withTables(Regions, Schools, Students) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -999,10 +1000,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadOptionalReferrersOnASizedIterable() {

@Test
fun preloadOptionalReferrersOnASizedIterable() {
withTables(Regions, Schools, Students, Detentions) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -1048,10 +1048,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadInnerTableLinkOnASizedIterable() {

@Test
fun preloadInnerTableLinkOnASizedIterable() {
withTables(Regions, Schools, Holidays, SchoolHolidays) {

val now = System.currentTimeMillis()
val now10 = now + 10

Expand Down Expand Up @@ -1110,9 +1109,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadInnerTableLinkOnAnEntity() {
@Test
fun preloadInnerTableLinkOnAnEntity() {
withTables(Regions, Schools, Holidays, SchoolHolidays) {

val now = System.currentTimeMillis()
val now10 = now + 10

Expand Down Expand Up @@ -1169,10 +1168,9 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadRelationAtDepth() {

@Test
fun preloadRelationAtDepth() {
withTables(Regions, Schools, Holidays, SchoolHolidays, Students, Notes) {

val region1 = Region.new {
name = "United Kingdom"
}
Expand Down Expand Up @@ -1213,8 +1211,8 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadBackReferrenceOnASizedIterable() {

@Test
fun preloadBackReferrenceOnASizedIterable() {
withTables(Regions, Schools, Students, StudentBios) {
val region1 = Region.new {
name = "United States"
Expand Down Expand Up @@ -1258,8 +1256,8 @@ class EntityTests : DatabaseTestsBase() {
}
}

@Test fun preloadBackReferrenceOnAnEntity() {

@Test
fun preloadBackReferrenceOnAnEntity() {
withTables(Regions, Schools, Students, StudentBios) {
val region1 = Region.new {
name = "United States"
Expand Down
Loading