Search in sources :

Example 6 with DummyXA

use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.

the class XAResourceRecordUnitTest method test.

@Test
public void test() throws Exception {
    XAResourceRecord xares = new XAResourceRecord();
    Object obj = new Object();
    xares.setValue(obj);
    assertTrue(xares.value() != obj);
    DummyRecoverableXAConnection rc = new DummyRecoverableXAConnection();
    Object[] params = new Object[1];
    params[XAResourceRecord.XACONNECTION] = rc;
    xares = new XAResourceRecord(new TransactionImple(0), new DummyXA(false), new XidImple(new Uid()), params);
    assertTrue(xares.type() != null);
    xares.merge(xares);
    xares.replace(xares);
    assertTrue(xares.toString() != null);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) DummyRecoverableXAConnection(com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection) Uid(com.arjuna.ats.arjuna.common.Uid) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Test(org.junit.Test)

Example 7 with DummyXA

use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.

the class XARecoveryResourceUnitTest method testRecoveryResource.

@Test
public void testRecoveryResource() {
    XARecoveryResourceImple res = new XARecoveryResourceImple(new Uid());
    assertEquals(res.getXAResource(), null);
    assertEquals(res.recoverable(), XARecoveryResource.INCOMPLETE_STATE);
    res = new XARecoveryResourceImple(new Uid(), new DummyXA(false));
    assertEquals(res.recoverable(), XARecoveryResource.RECOVERY_REQUIRED);
    assertEquals(res.recover(), XARecoveryResource.WAITING_FOR_RECOVERY);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) XARecoveryResourceImple(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryResourceImple) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) Test(org.junit.Test)

Example 8 with DummyXA

use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.

the class TransactionImpleUnitTest method testEnlist.

@Test
public void testEnlist() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    tx.setRollbackOnly();
    try {
        tx.enlistResource(null);
        fail();
    } catch (final SystemException ex) {
    }
    try {
        tx.enlistResource(new DummyXA(false));
        fail();
    } catch (final RollbackException ex) {
    }
    try {
        tx.commit();
        fail();
    } catch (final RollbackException ex) {
    }
    try {
        tx.enlistResource(new DummyXA(false));
        fail();
    } catch (final IllegalStateException ex) {
    }
}
Also used : DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) SystemException(javax.transaction.SystemException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 9 with DummyXA

use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.

the class TransactionImpleUnitTest method testXidCreation.

@Test
public void testXidCreation() throws Exception {
    ThreadActionData.purgeActions();
    Class[] parameterTypes = new Class[3];
    TransactionImple tx = new TransactionImple(0);
    parameterTypes[0] = boolean.class;
    parameterTypes[1] = XAModifier.class;
    parameterTypes[2] = XAResource.class;
    Method m = tx.getClass().getDeclaredMethod("createXid", parameterTypes);
    m.setAccessible(true);
    Object[] parameters = new Object[3];
    parameters[0] = false;
    parameters[1] = new DummyXAModifier();
    parameters[2] = new DummyXA(false);
    Xid res = (Xid) m.invoke(tx, parameters);
    assertTrue(res != null);
    tx.rollback();
}
Also used : Xid(javax.transaction.xa.Xid) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 10 with DummyXA

use of com.hp.mwtests.ts.jta.common.DummyXA in project narayana by jbosstm.

the class SynchronizationUnitTest method testSynchronizationFailure.

@Test
public void testSynchronizationFailure() throws Exception {
    TransactionImple tx = new TransactionImple(0);
    DummyXA res = new DummyXA(false) {

        public void rollback(Xid xid) throws XAException {
            super.rollback(xid);
            throw new XAException(XAException.XA_RETRY);
        }
    };
    tx.enlistResource(res);
    final String exceptionError = "intentional testing exception";
    tx.registerSynchronization(new javax.transaction.Synchronization() {

        @Override
        public void beforeCompletion() {
            throw new RuntimeException(exceptionError);
        }

        @Override
        public void afterCompletion(int status) {
        }
    });
    try {
        tx.commit();
    } catch (Exception e) {
        Throwable exceptionToCheck = e;
        while (exceptionToCheck != null) {
            if (exceptionToCheck.getMessage().equals(exceptionError))
                return;
            exceptionToCheck = exceptionToCheck.getCause();
        }
        throw e;
    }
}
Also used : Xid(javax.transaction.xa.Xid) DummyXA(com.hp.mwtests.ts.jta.common.DummyXA) XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) XAException(javax.transaction.xa.XAException) Test(org.junit.Test)

Aggregations

DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)15 Test (org.junit.Test)13 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)9 Uid (com.arjuna.ats.arjuna.common.Uid)6 XidImple (com.arjuna.ats.jta.xa.XidImple)5 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)4 Xid (javax.transaction.xa.Xid)3 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 DummyRecoverableXAConnection (com.hp.mwtests.ts.jta.common.DummyRecoverableXAConnection)2 HeuristicMixedException (javax.transaction.HeuristicMixedException)2 SystemException (javax.transaction.SystemException)2 XAResource (javax.transaction.xa.XAResource)2 RecoveryXids (com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids)1 XARecoveryResourceImple (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryResourceImple)1 XAOnePhaseResource (com.arjuna.ats.internal.jta.resources.arjunacore.XAOnePhaseResource)1 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)1 TestResource (com.hp.mwtests.ts.jta.common.TestResource)1 FailureXAResource (com.hp.mwtests.ts.jta.tools.FailureXAResource)1 Method (java.lang.reflect.Method)1