commit | 127204681ca6f18882145c3250f471d24710f62f | [log] [tgz] |
---|---|---|
author | Tim Ward <timothyjward@apache.org> | Thu Jan 25 13:17:29 2018 -0500 |
committer | Tim Ward <timothyjward@apache.org> | Thu Jan 25 13:17:55 2018 -0500 |
tree | 6a3c7d38c045ae8b717e5f48194186da9644fd34 | |
parent | 4f155dd818e87b584244647f18893d7c460b6c05 [diff] |
Tx Control spec compliance - re-fix the setRollbackOnly issue in pre completion and add a unit test
diff --git a/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java b/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java index 678f416..109ff85 100644 --- a/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java +++ b/tx-control-services/tx-control-service-xa/src/main/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextImpl.java
@@ -315,10 +315,11 @@ if (re.getCause() instanceof SetRollbackOnlyException) { // This means that a pre-completion callback called setRollbackOnly // which can be safely ignored (i.e. it's not really an exception) - } - TransactionRolledBackException tre = + } else { + TransactionRolledBackException tre = new TransactionRolledBackException(re.getMessage(), re); - throw tre; + throw tre; + } } } } catch (Exception e) {
diff --git a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java index aa5c0a0..d528fbe 100644 --- a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java +++ b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
@@ -94,6 +94,24 @@ } @Test + public void testRequiredMarkedRollbackInPrecompletion() { + + AtomicReference<TransactionStatus> finalStatus = new AtomicReference<>(); + + txControl.required(() -> { + + assertTrue(txControl.activeTransaction()); + + txControl.getCurrentContext().postCompletion(finalStatus::set); + + txControl.getCurrentContext().preCompletion(txControl::setRollbackOnly); + return null; + }); + + assertEquals(ROLLED_BACK, finalStatus.get()); + } + + @Test public void testRequiredUserException() { AtomicReference<TransactionStatus> finalStatus = new AtomicReference<>();