Search in sources :

Example 1 with RecoveryRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord 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 2 with RecoveryRecord

use of com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord in project narayana by jbosstm.

the class StateManager method modified.

/*
     * Protected non-virtual functions.
     */
/**
 * The object's state is about to be modified, and StateManager should take
 * a snapshot of the state if the object is being used within a transaction.
 *
 * @return <code>true</code> on success, <code>false</code> otherwise.
 */
protected synchronized boolean modified() {
    if (tsLogger.logger.isTraceEnabled()) {
        tsLogger.logger.trace("StateManager::modified() for object-id " + get_uid());
    }
    BasicAction action = BasicAction.Current();
    RecoveryRecord record = null;
    if ((myType == ObjectType.NEITHER) || (currentStatus == ObjectStatus.DESTROYED)) /*
                                                               * NEITHER => no
                                                               * recovery info
                                                               */
    {
        return true;
    }
    if (currentStatus == ObjectStatus.PASSIVE) {
        tsLogger.i18NLogger.warn_StateManager_10();
        activate();
    }
    if (currentStatus == ObjectStatus.PASSIVE_NEW)
        currentStatus = ObjectStatus.ACTIVE_NEW;
    if (action != null) {
        /*
             * Check if this is the first call to modified in this action.
             * BasicList insert returns FALSE if the entry is already present.
             */
        createLists();
        synchronized (modifyingActions) {
            if ((modifyingActions.size() > 0) && (modifyingActions.get(action.get_uid()) != null)) {
                return true;
            } else
                modifyingActions.put(action.get_uid(), action);
        }
        /* If here then its a new action */
        OutputObjectState state = new OutputObjectState(objectUid, type());
        int rStatus = AddOutcome.AR_ADDED;
        if (save_state(state, ObjectType.RECOVERABLE)) {
            if ((myType == ObjectType.RECOVERABLE) && (objectModel == ObjectModel.SINGLE)) {
                record = new RecoveryRecord(state, this);
            } else
                record = new PersistenceRecord(state, participantStore, this);
            if ((rStatus = action.add(record)) != AddOutcome.AR_ADDED) {
                synchronized (modifyingActions) {
                    // remember
                    modifyingActions.remove(action.get_uid());
                // to
                // unregister
                // with
                // action
                }
                record = null;
                return false;
            }
        } else
            return false;
    }
    return true;
}
Also used : RecoveryRecord(com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord) BasicAction(com.arjuna.ats.arjuna.coordinator.BasicAction) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)

Aggregations

OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)2 RecoveryRecord (com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord)2 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)1 PersistenceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)1 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)1 Test (org.junit.Test)1