Skip to content

how to run an integrated test that requires a reactive transaction manager using coroutines? #2451

Answered by dstepanov
lucasgust asked this question in Q&A
Discussion options

You must be logged in to vote

Avoid combining coroutines and R2DBC. In the future, we should have some Coroutine TX operations to avoid R2dbc code in Kotlin.

For now, you can create:

@Singleton
open class KotlinTransactional {

    @Transactional
    open suspend fun <T> inTx(tx: suspend () -> T): T {
        return tx.invoke()
    }

}

And use it:

        beforeEach {
            runBlocking { // Might not be needed
                kotlinTransactional.inTx {
                    employeeDataAccessPort.deleteAll()
                }
            }
        }

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@lucasgust
Comment options

@dstepanov
Comment options

@lucasgust
Comment options

Answer selected by lucasgust
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants