'Quarkus: can I share a transaction between test and application
From the title you'll probably tell me "use the @TestTransaction". This is not my question. As I undertand this annotation, it will rollback any changes in the db, in this case:
@QuarkusTest
class Test {
@Inject val repository: Repository
@Test
@TestTransaction
fun test() {
repository.persist(MyClass(...))
}
Now, in the case where you want - from the test - to persist some changes and call an endpoint that also persists updates, how are we supposed to handle it?
@Test
@TestTransaction
fun testWithEndpoint() {
repository.persist(MyClass(...))
given().body(MyClass(...)).post("/save-my-class").then()...
}
This gives me a pessimistic lock exception, I guess because the test starts one blocking transaction, and the server cannot then get the lock. Is there any way the wrap the whole into a single transaction that would be rollbacked at the end?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
