Search in sources :

Example 31 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class AtomicActionRecoveryModule method periodicWorkFirstPass.

/**
 * This is called periodically by the RecoveryManager
 */
public void periodicWorkFirstPass() {
    // Transaction type
    boolean AtomicActions = false;
    // uids per transaction type
    InputObjectState aa_uids = new InputObjectState();
    try {
        if (tsLogger.logger.isDebugEnabled()) {
            tsLogger.logger.debug("AtomicActionRecoveryModule first pass");
        }
        AtomicActions = _recoveryStore.allObjUids(_transactionType, aa_uids);
    } catch (ObjectStoreException ex) {
        tsLogger.i18NLogger.warn_recovery_AtomicActionRecoveryModule_1(ex);
    }
    if (AtomicActions) {
        _transactionUidVector = processTransactions(aa_uids);
    }
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ObjectStoreException(com.arjuna.ats.arjuna.exceptions.ObjectStoreException)

Example 32 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class LogStoreTest method test.

@Test
public void test() {
    arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
    RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
    final int numberOfTransactions = 1000;
    final Uid[] ids = new Uid[numberOfTransactions];
    final int fakeData = 0xdeedbaaf;
    final String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/Test";
    for (int i = 0; i < numberOfTransactions; i++) {
        OutputObjectState dummyState = new OutputObjectState();
        try {
            dummyState.packInt(fakeData);
            ids[i] = new Uid();
            recoveryStore.write_committed(ids[i], type, dummyState);
        } catch (final Exception ex) {
            ex.printStackTrace();
        }
    }
    InputObjectState ios = new InputObjectState();
    boolean passed = false;
    try {
        if (recoveryStore.allObjUids(type, ios, StateStatus.OS_UNKNOWN)) {
            Uid id = new Uid(Uid.nullUid());
            int numberOfEntries = 0;
            do {
                try {
                    id = UidHelper.unpackFrom(ios);
                } catch (Exception ex) {
                    id = Uid.nullUid();
                }
                if (id.notEquals(Uid.nullUid())) {
                    passed = true;
                    System.err.println("Located transaction log " + id + " in object store.");
                    numberOfEntries++;
                    boolean found = false;
                    for (int i = 0; i < ids.length; i++) {
                        if (id.equals(ids[i]))
                            found = true;
                    }
                    if (passed && !found) {
                        passed = false;
                        System.err.println("Found unexpected transaction!");
                    }
                }
            } while (id.notEquals(Uid.nullUid()));
            if ((numberOfEntries != ids.length) && passed) {
                passed = false;
                System.err.println("Expected " + ids.length + " and got " + numberOfEntries);
            }
        }
    } catch (final Exception ex) {
        ex.printStackTrace();
    }
    assertTrue(passed);
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) LogStore(com.arjuna.ats.internal.arjuna.objectstore.LogStore) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) RecoveryStore(com.arjuna.ats.arjuna.objectstore.RecoveryStore) Test(org.junit.Test)

Example 33 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class PersistenceRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    PersistenceRecord cr = new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject());
    arjPropertyManager.getCoordinatorEnvironmentBean().setClassicPrepare(true);
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.PERSISTENCE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), true);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_ERROR);
    cr = new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr.print(new PrintWriter(new ByteArrayOutputStream()));
    OutputObjectState os = new OutputObjectState();
    assertTrue(cr.save_state(os, ObjectType.ANDPERSISTENT));
    assertTrue(cr.restore_state(new InputObjectState(os), ObjectType.ANDPERSISTENT));
    assertEquals(cr.topLevelCleanup(), TwoPhaseOutcome.FINISH_OK);
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 34 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class RecoveryRecordUnitTest method test.

@Test
public void test() {
    RecoveryRecord cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
    assertFalse(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.RECOVERY);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertTrue(cr.value() != null);
    cr.setValue(new OutputObjectState());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_ERROR);
    cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_ERROR);
    cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new RecoveryRecord();
    cr.merge(new RecoveryRecord());
    cr.alter(new RecoveryRecord());
    assertTrue(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
    assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
}
Also used : InputObjectState(com.arjuna.ats.arjuna.state.InputObjectState) RecoveryRecord(com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord) ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) Test(org.junit.Test)

Example 35 with InputObjectState

use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.

the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterCommit.

@Test
public void testRMFAILAfterCommit() 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 {
            super.commit(arg0, arg1);
            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);
    assertTrue(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
    // This will complete the atomicaction
    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) 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

InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)133 Uid (com.arjuna.ats.arjuna.common.Uid)83 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)55 Test (org.junit.Test)47 ObjectStoreException (com.arjuna.ats.arjuna.exceptions.ObjectStoreException)42 IOException (java.io.IOException)30 RecoveryStore (com.arjuna.ats.arjuna.objectstore.RecoveryStore)23 ObjectStoreEnvironmentBean (com.arjuna.ats.arjuna.common.ObjectStoreEnvironmentBean)17 XidImple (com.arjuna.ats.jta.xa.XidImple)9 XAException (javax.transaction.xa.XAException)9 ArrayList (java.util.ArrayList)8 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)7 Xid (javax.transaction.xa.Xid)6 SubordinateAtomicAction (com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.SubordinateAtomicAction)5 Date (java.util.Date)5 Vector (java.util.Vector)5 AtomicAction (com.arjuna.ats.arjuna.AtomicAction)4 HashedActionStore (com.arjuna.ats.internal.arjuna.objectstore.HashedActionStore)4 NullActionStore (com.arjuna.ats.internal.arjuna.objectstore.NullActionStore)4 TransactionImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple)4