Search in sources :

Example 1 with EditableAtomicAction

use of com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction in project narayana by jbosstm.

the class LogEditorUnitTest method test.

@Test
public void test() throws Exception {
    String localOSRoot = "foobar";
    String objectStoreDir = System.getProperty("java.io.tmpdir") + "/bar";
    arjPropertyManager.getObjectStoreEnvironmentBean().setLocalOSRoot(localOSRoot);
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreDir(objectStoreDir);
    // dummy to set up ObjectStore
    AtomicAction A = new AtomicAction();
    A.begin();
    A.add(new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal));
    A.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    A.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    A.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    int outcome = A.commit();
    System.out.println("Transaction " + A + " committed with " + ActionStatus.stringForm(outcome));
    AtomicAction B = new AtomicAction();
    B.begin();
    B.add(new CrashRecord(CrashRecord.CrashLocation.NoCrash, CrashRecord.CrashType.Normal));
    B.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    B.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.Normal));
    B.add(new CrashRecord(CrashRecord.CrashLocation.CrashInCommit, CrashRecord.CrashType.HeuristicHazard));
    outcome = B.commit();
    System.out.println("Transaction " + B + " committed with " + ActionStatus.stringForm(outcome));
    RecordTypeManager.manager().add(new DummyMap2());
    EditableAtomicAction eaa = new EditableAtomicAction(B.get_uid());
    assertTrue(eaa.toString() != null);
    eaa.moveHeuristicToPrepared(1);
    try {
        eaa.moveHeuristicToPrepared(-1);
        fail();
    } catch (final Exception ex) {
    }
    eaa = new EditableAtomicAction(A.get_uid());
    eaa.deleteHeuristicParticipant(0);
    try {
        eaa.deleteHeuristicParticipant(-1);
        fail();
    } catch (final Exception ex) {
    }
}
Also used : AtomicAction(com.arjuna.ats.arjuna.AtomicAction) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) EditableAtomicAction(com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction) CrashRecord(com.hp.mwtests.ts.arjuna.resources.CrashRecord) Test(org.junit.Test)

Example 2 with EditableAtomicAction

use of com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction 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)

Aggregations

AtomicAction (com.arjuna.ats.arjuna.AtomicAction)2 EditableAtomicAction (com.arjuna.ats.internal.arjuna.tools.log.EditableAtomicAction)2 Test (org.junit.Test)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)1 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)1 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 CrashRecord (com.hp.mwtests.ts.arjuna.resources.CrashRecord)1 Connection (java.sql.Connection)1 Enumeration (java.util.Enumeration)1 Vector (java.util.Vector)1 InitialContext (javax.naming.InitialContext)1 XAException (javax.transaction.xa.XAException)1 XAResource (javax.transaction.xa.XAResource)1 Xid (javax.transaction.xa.Xid)1 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)1