Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a test to enlist a resource in before completion

  • Loading branch information...
commit f7aa7f5651742f21e36727c9a37ce5dff38e735b 1 parent 6904a0c
Tom Jenkinson tomjenkinson authored
123 ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/basic/EnlistResourceDuringCommit.java
... ... @@ -0,0 +1,123 @@
  1 +package com.hp.mwtests.ts.jta.basic;
  2 +import javax.transaction.HeuristicMixedException;
  3 +import javax.transaction.HeuristicRollbackException;
  4 +import javax.transaction.RollbackException;
  5 +import javax.transaction.Synchronization;
  6 +import javax.transaction.SystemException;
  7 +import javax.transaction.xa.XAException;
  8 +import javax.transaction.xa.XAResource;
  9 +import javax.transaction.xa.Xid;
  10 +
  11 +import org.junit.Test;
  12 +
  13 +import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
  14 +
  15 +public class EnlistResourceDuringCommit {
  16 +
  17 + @Test
  18 + public void testEnlistResourceDuringBeforeCompletion()
  19 + throws IllegalStateException, RollbackException, SystemException,
  20 + SecurityException, HeuristicMixedException,
  21 + HeuristicRollbackException {
  22 + final TransactionImple tx = new TransactionImple(0);
  23 + tx.registerSynchronization(new Synchronization() {
  24 +
  25 + @Override
  26 + public void beforeCompletion() {
  27 + System.out.println(new Throwable().getStackTrace()[0]
  28 + .getMethodName());
  29 + try {
  30 + tx.enlistResource(new XAResource() {
  31 +
  32 + @Override
  33 + public void start(Xid arg0, int arg1)
  34 + throws XAException {
  35 + System.out.println(new Throwable().getStackTrace()[0]
  36 + .getMethodName());
  37 + }
  38 +
  39 + @Override
  40 + public boolean setTransactionTimeout(int arg0)
  41 + throws XAException {
  42 + System.out.println(new Throwable().getStackTrace()[0]
  43 + .getMethodName());
  44 + return false;
  45 + }
  46 +
  47 + @Override
  48 + public void rollback(Xid arg0) throws XAException {
  49 + System.out.println(new Throwable().getStackTrace()[0]
  50 + .getMethodName());
  51 + }
  52 +
  53 + @Override
  54 + public Xid[] recover(int arg0) throws XAException {
  55 + System.out.println(new Throwable().getStackTrace()[0]
  56 + .getMethodName());
  57 + return null;
  58 + }
  59 +
  60 + @Override
  61 + public int prepare(Xid arg0) throws XAException {
  62 + System.out.println(new Throwable().getStackTrace()[0]
  63 + .getMethodName());
  64 + return 0;
  65 + }
  66 +
  67 + @Override
  68 + public boolean isSameRM(XAResource arg0)
  69 + throws XAException {
  70 + System.out.println(new Throwable().getStackTrace()[0]
  71 + .getMethodName());
  72 + return false;
  73 + }
  74 +
  75 + @Override
  76 + public int getTransactionTimeout() throws XAException {
  77 + System.out.println(new Throwable().getStackTrace()[0]
  78 + .getMethodName());
  79 + return 0;
  80 + }
  81 +
  82 + @Override
  83 + public void forget(Xid arg0) throws XAException {
  84 + System.out.println(new Throwable().getStackTrace()[0]
  85 + .getMethodName());
  86 + }
  87 +
  88 + @Override
  89 + public void end(Xid arg0, int arg1) throws XAException {
  90 + System.out.println(new Throwable().getStackTrace()[0]
  91 + .getMethodName());
  92 + }
  93 +
  94 + @Override
  95 + public void commit(Xid arg0, boolean arg1)
  96 + throws XAException {
  97 + System.out.println(new Throwable().getStackTrace()[0]
  98 + .getMethodName());
  99 + }
  100 + });
  101 + } catch (IllegalStateException e) {
  102 + // TODO Auto-generated catch block
  103 + e.printStackTrace();
  104 + } catch (RollbackException e) {
  105 + // TODO Auto-generated catch block
  106 + e.printStackTrace();
  107 + } catch (SystemException e) {
  108 + // TODO Auto-generated catch block
  109 + e.printStackTrace();
  110 + }
  111 + }
  112 +
  113 + @Override
  114 + public void afterCompletion(int status) {
  115 + System.out.println(new Throwable().getStackTrace()[0]
  116 + .getMethodName());
  117 +
  118 + }
  119 + });
  120 + tx.commit();
  121 + }
  122 +
  123 +}

1 comment on commit f7aa7f5

Tom Jenkinson

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.
Something went wrong with that request. Please try again.