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:49 UTC
[aries-tx-control] 02/04: Tx Control 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 0fc68c8c57c98cb5ea7cf694a4301a8bec49af02
Author: Tim Ward <ti...@apache.org>
AuthorDate: Fri Jan 19 16:39:12 2018 +0000
Tx Control spec compliance
Make sure that we can't register pre-completion from inside a pre-completion callback
---
.../service/xa/impl/TransactionContextImpl.java | 8 ++++---
.../service/xa/impl/TransactionContextTest.java | 26 ++++++++++++++++++++++
2 files changed, 31 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 67eff17..cb1f6d1 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
@@ -70,6 +70,8 @@ public class TransactionContextImpl extends AbstractTransactionContextImpl imple
private final boolean readOnly;
private LocalResourceSupport localResourceSupport;
+
+ private boolean noMorePreCompletion;
public TransactionContextImpl(RecoveryWorkAroundTransactionManager transactionManager,
boolean readOnly, LocalResourceSupport localResourceSupport) {
@@ -195,9 +197,8 @@ public class TransactionContextImpl extends AbstractTransactionContextImpl imple
@Override
public void preCompletion(Runnable job) throws IllegalStateException {
- TransactionStatus status = getTransactionStatus();
- if (status.compareTo(MARKED_ROLLBACK) > 0) {
- throw new IllegalStateException("The current transaction is in state " + status);
+ if (noMorePreCompletion) {
+ throw new IllegalStateException("The current transactional work has finished executing so a pre-completion callback can no longer be registered");
}
preCompletion.add(job);
@@ -444,6 +445,7 @@ public class TransactionContextImpl extends AbstractTransactionContextImpl imple
@Override
public void beforeCompletion() {
+ noMorePreCompletion = true;
TransactionContextImpl.this.beforeCompletion(() -> safeSetRollbackOnly());
}
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 d782b94..cd2032a 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
@@ -467,6 +467,32 @@ public class TransactionContextTest {
Mockito.verifyNoMoreInteractions(xaResource);
}
+
+ @Test
+ public void tesXAResourcePreCompletionRegisterPreCompletion() throws Exception {
+
+ ctx.registerXAResource(xaResource, null);
+
+ Mockito.doAnswer(i -> {
+ assertEquals(ROLLING_BACK, ctx.getTransactionStatus());
+ return null;
+ }).when(xaResource).rollback(Mockito.any(Xid.class));
+
+ ctx.preCompletion(() -> ctx.preCompletion(() -> {}));
+
+ ctx.finish();
+
+ ArgumentCaptor<Xid> captor = ArgumentCaptor.forClass(Xid.class);
+
+ InOrder inOrder = Mockito.inOrder(xaResource);
+
+ inOrder.verify(xaResource).start(captor.capture(), Mockito.eq(XAResource.TMNOFLAGS));
+ inOrder.verify(xaResource).setTransactionTimeout(Mockito.anyInt());
+ inOrder.verify(xaResource).end(Mockito.eq(captor.getValue()), Mockito.eq(XAResource.TMFAIL));
+ inOrder.verify(xaResource).rollback(Mockito.eq(captor.getValue()));
+
+ Mockito.verifyNoMoreInteractions(xaResource);
+ }
@Test
public void testXAResourcePostCommitException() throws Exception {
--
To stop receiving notification emails like this one, please contact
"commits@aries.apache.org" <co...@aries.apache.org>.