use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class EnlistResourceDuringCommit method testEnlistResourceDuringBeforeCompletion.
@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();
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackFirstResourceFails.
@Test
public void testCheckDeferredHeuristicRollbackFirstResourceFails() throws Exception {
ThreadActionData.purgeActions();
TxControl.setXANodeName("test");
TransactionImple tx = new TransactionImple(500);
try {
tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.nota));
tx.enlistResource(new TestResource());
} catch (final RollbackException ex) {
fail();
}
try {
tx.commit();
fail();
} catch (final HeuristicMixedException ex) {
assertEquals(XAException.XAER_NOTA, ((XAException) ex.getSuppressed()[0]).errorCode);
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class ExceptionDeferrerTest method testCheckDeferredPrepareRollbackException.
@Test
public void testCheckDeferredPrepareRollbackException() throws Exception {
ThreadActionData.purgeActions();
TransactionImple tx = new TransactionImple(0);
tx.enlistResource(new FailureXAResource());
try {
tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.rollback));
} catch (final RollbackException ex) {
fail();
}
try {
tx.commit();
fail();
} catch (final RollbackException ex) {
assertEquals(XAException.XAER_INVAL, ((XAException) ex.getSuppressed()[0]).errorCode);
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class ExceptionDeferrerTest method testCheckDeferredPrepareInitCause.
@Test
public void testCheckDeferredPrepareInitCause() throws Exception {
ThreadActionData.purgeActions();
TransactionImple tx = new TransactionImple(0);
tx.enlistResource(new FailureXAResource());
try {
tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.message));
} catch (final RollbackException ex) {
fail();
}
try {
tx.commit();
fail();
} catch (final RollbackException ex) {
assertEquals(XAException.XA_RBROLLBACK, ((XAException) ex.getSuppressed()[0]).errorCode);
assertEquals("test message", ((XAException) ex.getSuppressed()[0]).getCause().getMessage());
}
}
use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.
the class ExceptionDeferrerTest method testCheckDeferredPrepareHeuristic.
@Test
public void testCheckDeferredPrepareHeuristic() throws Exception {
ThreadActionData.purgeActions();
TransactionImple tx = new TransactionImple(0);
tx.enlistResource(new FailureXAResource());
try {
tx.enlistResource(new FailureXAResource(FailLocation.prepare, FailType.XA_HEURHAZ));
} catch (final RollbackException ex) {
fail();
}
try {
tx.commit();
fail();
} catch (final HeuristicMixedException ex) {
assertEquals(XAException.XA_HEURHAZ, ((XAException) ex.getSuppressed()[0]).errorCode);
}
}
Aggregations