Search in sources :

Example 21 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredRollbackException.

@Test
public void testCheckDeferredRollbackException() throws Exception {
    ThreadActionData.purgeActions();
    TransactionImple tx = new TransactionImple(0);
    try {
        tx.enlistResource(new FailureXAResource(FailLocation.commit, FailType.rollback));
    } catch (final RollbackException ex) {
        fail();
    }
    try {
        tx.commit();
        fail();
    } catch (final RollbackException ex) {
        assertEquals(XAException.XA_HEURRB, ((XAException) ex.getSuppressed()[0]).errorCode);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 22 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ExceptionDeferrerTest method testCheckDeferredHeuristicRollbackSecondOfThreeFails.

@Test
public void testCheckDeferredHeuristicRollbackSecondOfThreeFails() throws Exception {
    ThreadActionData.purgeActions();
    TxControl.setXANodeName("test");
    TransactionImple tx = new TransactionImple(500);
    try {
        tx.enlistResource(new TestResource());
        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);
    }
}
Also used : XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) FailureXAResource(com.hp.mwtests.ts.jta.common.FailureXAResource) HeuristicMixedException(javax.transaction.HeuristicMixedException) TestResource(com.hp.mwtests.ts.jta.common.TestResource) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Example 23 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterNoCommit.

@Test
public void testRMFAILAfterNoCommit() throws Exception {
    jtaPropertyManager.getJTAEnvironmentBean().setNotifyCommitMarkableResourceRecoveryModuleOfCompleteBranches(false);
    final JdbcDataSource dataSource = new JdbcDataSource();
    dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
    // Test code
    Utils.createTables(dataSource.getConnection());
    // We can't just instantiate one as we need to be using the
    // same one as
    // the transaction
    // manager would have used to mark the transaction for GC
    CommitMarkableResourceRecordRecoveryModule commitMarkableResourceRecoveryModule = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                commitMarkableResourceRecoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof XARecoveryModule) {
                XARecoveryModule xarm = (XARecoveryModule) m;
                xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {

                    public boolean initialise(String p) throws Exception {
                        return true;
                    }

                    public XAResource[] getXAResources() throws Exception {
                        return new XAResource[] { xaResource };
                    }
                });
            }
        }
    }
    javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.begin();
    Uid get_uid = ((TransactionImple) tm.getTransaction()).get_uid();
    Connection localJDBCConnection = dataSource.getConnection();
    localJDBCConnection.setAutoCommit(false);
    nonXAResource = new JDBCConnectableResource(localJDBCConnection) {

        @Override
        public void commit(Xid arg0, boolean arg1) throws XAException {
            throw new XAException(XAException.XAER_RMFAIL);
        }
    };
    tm.getTransaction().enlistResource(nonXAResource);
    xaResource = new SimpleXAResource();
    tm.getTransaction().enlistResource(xaResource);
    localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
    tm.commit();
    assertTrue(xaResource.wasCommitted());
    Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
    assertNotNull(committed);
    InputObjectState uids = new InputObjectState();
    StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
    Uid uid = UidHelper.unpackFrom(uids);
    assertTrue(uid.equals(get_uid));
    // Belt and braces but we don't expect the CMR to be removed anyway as
    // the RM is "offline"
    manager.scan();
    manager.scan();
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
    // This will make the AA a heuristic
    manager.scan();
    EditableAtomicAction editableAtomicAction = new EditableAtomicAction(get_uid);
    editableAtomicAction.deleteHeuristicParticipant(0);
    manager.scan();
    StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
    uid = UidHelper.unpackFrom(uids);
    assertTrue(uid.equals(Uid.nullUid()));
    // This is when the CMR deletes are done due to ordering
    manager.scan();
    // of the recovery modules
    assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) Enumeration(java.util.Enumeration) XAException(javax.transaction.xa.XAException) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) Connection(java.sql.Connection) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) InitialContext(javax.naming.InitialContext) Uid(com.arjuna.ats.arjuna.common.Uid) AtomicAction(com.arjuna.ats.arjuna.AtomicAction) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 24 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple in project narayana by jbosstm.

the class ObjStoreBrowserTest method getHeuristic.

private HeuristicTestData getHeuristic() throws Exception {
    // generates a heuristic on commit
    FailureXAResource failureXAResource = new FailureXAResource(FailureXAResource.FailLocation.commit);
    TransactionImple tx = new TransactionImple(1000000000);
    XAResourceRecordBeanMBean resourceBean = getHeuristicMBean(osb, tx, failureXAResource);
    JTAActionBean txnMBean = getTransactionBean(osb, tx, true);
    Set<ObjectName> participants;
    String resourceBeanName;
    String txnBeanName;
    assertNotNull(txnMBean);
    assertNotNull(resourceBean);
    txnBeanName = String.format("jboss.jta:type=ObjectStore,itype=%s,uid=%s", txnMBean.type(), txnMBean.getId().replace(':', '_'));
    resourceBeanName = String.format("%s,puid=%s", txnBeanName, resourceBean.getId().replace(':', '_'));
    participants = JMXServer.getAgent().queryNames(resourceBeanName, null);
    assertEquals(1, participants.size());
    return new HeuristicTestData(tx, failureXAResource, txnMBean, resourceBean, participants.iterator().next(), txnBeanName, resourceBeanName);
}
Also used : XAResourceRecordBeanMBean(com.arjuna.ats.internal.jta.tools.osb.mbean.jta.XAResourceRecordBeanMBean) TransactionImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple) JTAActionBean(com.arjuna.ats.internal.jta.tools.osb.mbean.jta.JTAActionBean) ObjectName(javax.management.ObjectName)

Example 25 with TransactionImple

use of com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple 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)

Aggregations

TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)32 Test (org.junit.Test)30 FailureXAResource (com.hp.mwtests.ts.jta.common.FailureXAResource)12 XAException (javax.transaction.xa.XAException)11 RollbackException (javax.transaction.RollbackException)10 DummyXA (com.hp.mwtests.ts.jta.common.DummyXA)9 Uid (com.arjuna.ats.arjuna.common.Uid)7 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)7 HeuristicMixedException (javax.transaction.HeuristicMixedException)6 TestResource (com.hp.mwtests.ts.jta.common.TestResource)5 XAResource (javax.transaction.xa.XAResource)5 Xid (javax.transaction.xa.Xid)5 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)4 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)4 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)4 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)4 SystemException (javax.transaction.SystemException)4 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)3 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)3 XidImple (com.arjuna.ats.jta.xa.XidImple)3