You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2018/01/19 17:28:50 UTC
[aries-tx-control] 03/04: Tx Control Service spec compliance
This is an automated email from the ASF dual-hosted git repository.
timothyjward pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-tx-control.git
commit 0553df8dbce9712a971289ed22d8493a299d6487
Author: Tim Ward <ti...@apache.org>
AuthorDate: Fri Jan 19 16:59:35 2018 +0000
Tx Control Service spec compliance
A setRollbackOnly called in a pre-completion callback should not result in an exception being thrown to the client
---
.../service/xa/impl/TransactionContextImpl.java | 12 ++++++--
.../service/xa/impl/TransactionContextTest.java | 35 +++++++++++++++++++++-
2 files changed, 44 insertions(+), 3 deletions(-)
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 cb1f6d1..3f18dcf 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
@@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
+import javax.transaction.RollbackException;
import javax.transaction.Status;
import javax.transaction.Synchronization;
import javax.transaction.SystemException;
@@ -48,6 +49,7 @@ import javax.transaction.xa.Xid;
import org.apache.aries.tx.control.service.common.impl.AbstractTransactionContextImpl;
import org.apache.geronimo.transaction.manager.RecoveryWorkAroundTransactionManager;
+import org.apache.geronimo.transaction.manager.SetRollbackOnlyException;
import org.osgi.service.transaction.control.LocalResource;
import org.osgi.service.transaction.control.TransactionContext;
import org.osgi.service.transaction.control.TransactionException;
@@ -132,7 +134,6 @@ public class TransactionContextImpl extends AbstractTransactionContextImpl imple
throw new IllegalStateException("The transaction is already being committed");
case COMMITTED:
throw new IllegalStateException("The transaction is already committed");
-
case ROLLING_BACK:
case ROLLED_BACK:
// A no op
@@ -307,7 +308,14 @@ public class TransactionContextImpl extends AbstractTransactionContextImpl imple
listener.beforeCompletion();
transactionManager.rollback();
} else {
- transactionManager.commit();
+ try {
+ transactionManager.commit();
+ } catch (RollbackException re) {
+ 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)
+ }
+ }
}
} catch (Exception e) {
recordFailure(e);
diff --git a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextTest.java b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextTest.java
index cd2032a..3fb3fd4 100644
--- a/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextTest.java
+++ b/tx-control-services/tx-control-service-xa/src/test/java/org/apache/aries/tx/control/service/xa/impl/TransactionContextTest.java
@@ -83,6 +83,7 @@ public class TransactionContextTest {
public void testSetRollbackOnly() {
ctx.setRollbackOnly();
assertTrue(ctx.getRollbackOnly());
+ assertEquals(MARKED_ROLLBACK, ctx.getTransactionStatus());
}
@Test
@@ -183,15 +184,38 @@ public class TransactionContextTest {
assertEquals(0, value.getAndSet(1));
-
ctx.setRollbackOnly();
+ assertTrue(ctx.getRollbackOnly());
+ assertEquals(MARKED_ROLLBACK, ctx.getTransactionStatus());
+
ctx.finish();
assertEquals(5, value.get());
}
@Test
+ public void testPreCompletionCallsSetRollbackOnly() throws Exception {
+
+ ctx.registerXAResource(xaResource, null);
+
+ AtomicInteger value = new AtomicInteger(0);
+
+ ctx.preCompletion(() -> {
+ ctx.setRollbackOnly();
+ assertEquals(MARKED_ROLLBACK, ctx.getTransactionStatus());
+ value.compareAndSet(1, 5);
+ });
+
+ assertEquals(0, value.getAndSet(1));
+
+ ctx.finish();
+
+ assertEquals(5, value.get());
+ assertEquals(ROLLED_BACK, ctx.getTransactionStatus());
+ }
+
+ @Test
public void testPostCompletion() throws Exception {
AtomicInteger value = new AtomicInteger(0);
@@ -222,6 +246,9 @@ public class TransactionContextTest {
ctx.setRollbackOnly();
+ assertTrue(ctx.getRollbackOnly());
+ assertEquals(MARKED_ROLLBACK, ctx.getTransactionStatus());
+
ctx.finish();
assertEquals(5, value.get());
@@ -300,6 +327,9 @@ public class TransactionContextTest {
ctx.registerLocalResource(localResource);
ctx.setRollbackOnly();
+ assertTrue(ctx.getRollbackOnly());
+ assertEquals(MARKED_ROLLBACK, ctx.getTransactionStatus());
+
Mockito.doAnswer(i -> {
assertEquals(ROLLING_BACK, ctx.getTransactionStatus());
return null;
@@ -424,6 +454,9 @@ public class TransactionContextTest {
ctx.registerXAResource(xaResource, null);
ctx.setRollbackOnly();
+ assertTrue(ctx.getRollbackOnly());
+ assertEquals(MARKED_ROLLBACK, ctx.getTransactionStatus());
+
Mockito.doAnswer(i -> {
assertEquals(ROLLING_BACK, ctx.getTransactionStatus());
return null;
--
To stop receiving notification emails like this one, please contact
"commits@aries.apache.org" <co...@aries.apache.org>.