Skip to content

Commit

Permalink
test: Add outer transaction manager setting exception test
Browse files Browse the repository at this point in the history
  • Loading branch information
FullOfOrange committed Aug 25, 2023
1 parent 7dcb3e3 commit 49d5178
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class SpringTransactionManager(
}

trxObject.setCurrentToOuter()
TransactionManager.resetCurrent(trxObject.outerManager)
}

private fun closeStatementsAndConnections(transaction: Transaction) {
Expand Down Expand Up @@ -131,6 +130,7 @@ class SpringTransactionManager(

fun setCurrentToOuter() {
manager.bindTransactionToThread(outerTransaction)
TransactionManager.resetCurrent(outerManager)
}

private fun hasOuterTransaction(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ open class SpringMultiContainerTransactionTest {
open fun test3() {
orders.transaction {
payments.create()
orders.create()
orders.findAll()
payments.create()
orders.create()
}
Assert.assertEquals(1, orders.findAll().size)
Assert.assertEquals(2, payments.findAll().size)
Expand Down Expand Up @@ -161,7 +162,11 @@ open class OrderConfig {
@Transactional
open class Orders {

open fun findAll() = Order.selectAll().map { it }
open fun findAll(): List<ResultRow> {
val list = Order.selectAll().toList()
list.forEach { it[Order.id] }
return list
}

open fun findAllWithExposedTrxBlock() = org.jetbrains.exposed.sql.transactions.transaction { findAll() }

Expand All @@ -178,6 +183,7 @@ open class Orders {

open fun transaction(block: () -> Unit) {
block()
Order.selectAll().forEach { it[Order.id] }
}
}

Expand Down Expand Up @@ -205,7 +211,11 @@ open class PaymentConfig {
@Transactional
open class Payments {

open fun findAll() = Payment.selectAll().map { it }
open fun findAll(): List<ResultRow> {
val list = Payment.selectAll().toList()
list.forEach { it[Payment.id] }
return list
}

open fun findAllWithExposedTrxBlock() = transaction { findAll() }

Expand All @@ -222,6 +232,7 @@ open class Payments {

open fun databaseTemplate(block: () -> Unit) {
block()
Payment.selectAll().forEach { it[Payment.id] }
}
}

Expand Down

0 comments on commit 49d5178

Please sign in to comment.