Permalink
Browse files

Added a test to enlist a resource in before completion

  • Loading branch information...
1 parent 6904a0c commit f7aa7f5651742f21e36727c9a37ce5dff38e735b @tomjenkinson tomjenkinson committed Oct 22, 2012
@@ -0,0 +1,123 @@
+package com.hp.mwtests.ts.jta.basic;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.RollbackException;
+import javax.transaction.Synchronization;
+import javax.transaction.SystemException;
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+import org.junit.Test;
+
+import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
+
+public class EnlistResourceDuringCommit {
+
+ @Test
+ public void testEnlistResourceDuringBeforeCompletion()
+ throws IllegalStateException, RollbackException, SystemException,
+ SecurityException, HeuristicMixedException,
+ HeuristicRollbackException {
+ final TransactionImple tx = new TransactionImple(0);
+ tx.registerSynchronization(new Synchronization() {
+
+ @Override
+ public void beforeCompletion() {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ try {
+ tx.enlistResource(new XAResource() {
+
+ @Override
+ public void start(Xid arg0, int arg1)
+ throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ }
+
+ @Override
+ public boolean setTransactionTimeout(int arg0)
+ throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ return false;
+ }
+
+ @Override
+ public void rollback(Xid arg0) throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ }
+
+ @Override
+ public Xid[] recover(int arg0) throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ return null;
+ }
+
+ @Override
+ public int prepare(Xid arg0) throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ return 0;
+ }
+
+ @Override
+ public boolean isSameRM(XAResource arg0)
+ throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ return false;
+ }
+
+ @Override
+ public int getTransactionTimeout() throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ return 0;
+ }
+
+ @Override
+ public void forget(Xid arg0) throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ }
+
+ @Override
+ public void end(Xid arg0, int arg1) throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ }
+
+ @Override
+ public void commit(Xid arg0, boolean arg1)
+ throws XAException {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+ }
+ });
+ } catch (IllegalStateException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (RollbackException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (SystemException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void afterCompletion(int status) {
+ System.out.println(new Throwable().getStackTrace()[0]
+ .getMethodName());
+
+ }
+ });
+ tx.commit();
+ }
+
+}

1 comment on commit f7aa7f5

@tomjenkinson
Collaborator

Output:
Oct 22, 2012 11:08:45 AM com.arjuna.ats.arjuna.coordinator.TxControl
WARN: ARJUNA012130: Name of XA node not defined. Using Arjuna:44833
Oct 22, 2012 11:08:45 AM com.arjuna.ats.arjuna.recovery.TransactionStatusManager addService
INFO: ARJUNA012163: Starting service com.arjuna.ats.arjuna.recovery.ActionStatusService on port 35276
Oct 22, 2012 11:08:45 AM com.arjuna.ats.internal.arjuna.recovery.TransactionStatusManagerItem
INFO: ARJUNA012337: TransactionStatusManagerItem host: 127.0.0.1 port: 35276
Oct 22, 2012 11:08:45 AM com.arjuna.ats.arjuna.recovery.TransactionStatusManager start
INFO: ARJUNA012170: TransactionStatusManager started on port 35276 and host 127.0.0.1 with service com.arjuna.ats.arjuna.recovery.ActionStatusService
beforeCompletion
setTransactionTimeout
start
end
commit
afterCompletion

Please sign in to comment.