You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a service method annotated with @transactional which may as part of its normal operations mark the current tx as rollback only.
I am testing it from a Junit test method annotated with @TestTransaction, which calls it in a loop.
If the first call triggers the rollback, I'd like to be able with the subsequent calls in the loop in a normal transaction.
If I understand correctly because the service method mode is Tx.Mandatory it will reuse the top-level transaction, mark it as rollback only, and the next unrelated DB call from the test method triggers a PSQLException.
I guess I could try to address the issue by marking he service method as Tx.REQUIRE_NEW, but I am concerned about hidden side-effects / consequences of doing that. Ideally I'd like the method to use Tx.REQUIRE_NEW while being tested, and Tx.MANDATORY when in normal operations.
Is there a way to achieve that?
Sample pseudo-code:
@TestTransaction
@Test
public void createUsers() {
for (User u : Users) {
try { svc.createUser(u) }
catch (DuplicateUserException e) { }
}
@Transactional
public void createUser(User u) {
try {
db.createUser(u);
} catch (PersistenceException e) {
if (isDuplicateException(e)) {
throw new DuplicateUserException(...);
}
throw e;
}
}
Edit: It looks like I can use property expressions to adjust the @transactional value parameter or tests... so the question becomes, is my understanding of how transactions work here correct?
And a related question: I am using quarkus-narayana-jta, and I couldn't find any obvious way to debug-log transaction events (start, commit, rollback...)?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I have a service method annotated with @transactional which may as part of its normal operations mark the current tx as rollback only.
I am testing it from a Junit test method annotated with @TestTransaction, which calls it in a loop.
If the first call triggers the rollback, I'd like to be able with the subsequent calls in the loop in a normal transaction.
If I understand correctly because the service method mode is Tx.Mandatory it will reuse the top-level transaction, mark it as rollback only, and the next unrelated DB call from the test method triggers a PSQLException.
I guess I could try to address the issue by marking he service method as Tx.REQUIRE_NEW, but I am concerned about hidden side-effects / consequences of doing that. Ideally I'd like the method to use Tx.REQUIRE_NEW while being tested, and Tx.MANDATORY when in normal operations.
Is there a way to achieve that?
Sample pseudo-code:
Edit: It looks like I can use property expressions to adjust the @transactional value parameter or tests... so the question becomes, is my understanding of how transactions work here correct?
And a related question: I am using quarkus-narayana-jta, and I couldn't find any obvious way to debug-log transaction events (start, commit, rollback...)?
Beta Was this translation helpful? Give feedback.
All reactions