Author: timothyjward
Date: Tue Aug 16 11:50:39 2016
New Revision: 1756511
URL: http://svn.apache.org/viewvc?rev=1756511&view=rev
Log:
[tx-control] Correctly set the causes of ScopedWorkExceptions
Modified:
aries/trunk/tx-control/tx-control-service-common/src/main/java/org/apache/aries/tx/control/service/common/impl/AbstractTransactionControlImpl.java
aries/trunk/tx-control/tx-control-service-local/src/test/java/org/apache/aries/tx/control/service/local/impl/TransactionControlRunningTest.java
aries/trunk/tx-control/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
Modified:
aries/trunk/tx-control/tx-control-service-common/src/main/java/org/apache/aries/tx/control/service/common/impl/AbstractTransactionControlImpl.java
URL:
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-service-common/src/main/java/org/apache/aries/tx/control/service/common/impl/AbstractTransactionControlImpl.java?rev=1756511&r1=1756510&r2=1756511&view=diff
==============================================================================
---
aries/trunk/tx-control/tx-control-service-common/src/main/java/org/apache/aries/tx/control/service/common/impl/AbstractTransactionControlImpl.java
(original)
+++
aries/trunk/tx-control/tx-control-service-common/src/main/java/org/apache/aries/tx/control/service/common/impl/AbstractTransactionControlImpl.java
Tue Aug 16 11:50:39 2016
@@ -172,8 +172,20 @@ public abstract class AbstractTransactio
currentTran.recordFailure(e);
}
}
- ScopedWorkException workException = new
ScopedWorkException("The scoped work threw an exception", t,
- endTransaction ? null :
currentTran);
+
+ TransactionContext toPropagate = endTransaction
? null : currentTran;
+
+ ScopedWorkException workException;
+
+ if(t instanceof ScopedWorkException) {
+ workException = new
ScopedWorkException("A nested piece of scoped work threw an exception",
+ t.getCause(),
toPropagate);
+ workException.addSuppressed(t);
+ } else {
+ workException = new
ScopedWorkException("The scoped work threw an exception",
+ t, toPropagate);
+ }
+
Throwable throwable =
currentTran.firstUnexpectedException.get();
if(throwable != null) {
workException.addSuppressed(throwable);
Modified:
aries/trunk/tx-control/tx-control-service-local/src/test/java/org/apache/aries/tx/control/service/local/impl/TransactionControlRunningTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-service-local/src/test/java/org/apache/aries/tx/control/service/local/impl/TransactionControlRunningTest.java?rev=1756511&r1=1756510&r2=1756511&view=diff
==============================================================================
---
aries/trunk/tx-control/tx-control-service-local/src/test/java/org/apache/aries/tx/control/service/local/impl/TransactionControlRunningTest.java
(original)
+++
aries/trunk/tx-control/tx-control-service-local/src/test/java/org/apache/aries/tx/control/service/local/impl/TransactionControlRunningTest.java
Tue Aug 16 11:50:39 2016
@@ -342,6 +342,44 @@ public class TransactionControlRunningTe
}
@Test
+ public void
testTwoRequiredsNestedInnerThrowsExceptionOuterDoesNotCatch() {
+
+ AtomicReference<TransactionStatus> finalStatusOuter = new
AtomicReference<>();
+ AtomicReference<TransactionStatus> finalStatusInner = new
AtomicReference<>();
+
+ Exception userEx = new Exception("Bang!");
+
+ try {
+ txControl.required(() -> {
+
+ assertTrue(txControl.activeTransaction());
+
+ Object key =
txControl.getCurrentContext().getTransactionKey();
+
+
txControl.getCurrentContext().postCompletion(finalStatusOuter::set);
+
+ txControl.requiresNew(() -> {
+
assertFalse(key.equals(txControl.getCurrentContext().getTransactionKey()));
+
+
txControl.getCurrentContext().postCompletion(finalStatusInner::set);
+
+ txControl.setRollbackOnly();
+
+ throw userEx;
+ });
+ fail("Should not be reached!");
+ return null;
+ });
+ } catch (ScopedWorkException swe) {
+ assertSame(userEx, swe.getCause());
+ }
+
+ assertEquals(ROLLED_BACK, finalStatusOuter.get());
+ assertEquals(ROLLED_BACK, finalStatusInner.get());
+
+ }
+
+ @Test
public void testTwoRequiredsNestedNoRollbackForInnerException() {
AtomicReference<TransactionStatus> finalStatusOuter = new
AtomicReference<>();
Modified:
aries/trunk/tx-control/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
URL:
http://svn.apache.org/viewvc/aries/trunk/tx-control/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java?rev=1756511&r1=1756510&r2=1756511&view=diff
==============================================================================
---
aries/trunk/tx-control/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
(original)
+++
aries/trunk/tx-control/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionControlRunningTest.java
Tue Aug 16 11:50:39 2016
@@ -343,6 +343,44 @@ public class TransactionControlRunningTe
}
@Test
+ public void
testTwoRequiredsNestedInnerThrowsExceptionOuterDoesNotCatch() {
+
+ AtomicReference<TransactionStatus> finalStatusOuter = new
AtomicReference<>();
+ AtomicReference<TransactionStatus> finalStatusInner = new
AtomicReference<>();
+
+ Exception userEx = new Exception("Bang!");
+
+ try {
+ txControl.required(() -> {
+
+ assertTrue(txControl.activeTransaction());
+
+ Object key =
txControl.getCurrentContext().getTransactionKey();
+
+
txControl.getCurrentContext().postCompletion(finalStatusOuter::set);
+
+ txControl.requiresNew(() -> {
+
assertFalse(key.equals(txControl.getCurrentContext().getTransactionKey()));
+
+
txControl.getCurrentContext().postCompletion(finalStatusInner::set);
+
+ txControl.setRollbackOnly();
+
+ throw userEx;
+ });
+ fail("Should not be reached!");
+ return null;
+ });
+ } catch (ScopedWorkException swe) {
+ assertSame(userEx, swe.getCause());
+ }
+
+ assertEquals(ROLLED_BACK, finalStatusOuter.get());
+ assertEquals(ROLLED_BACK, finalStatusInner.get());
+
+ }
+
+ @Test
public void testTwoRequiredsNestedNoRollbackForInnerException() {
AtomicReference<TransactionStatus> finalStatusOuter = new
AtomicReference<>();