Search in sources :

Example 1 with PersistenceRecord

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

use of com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord 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)

Example 3 with PersistenceRecord

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

the class CadaverActivationUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    CadaverActivationRecord cr = new CadaverActivationRecord(new ExtendedObject());
    assertTrue(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.ACTIVATION);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    assertFalse(cr.shouldReplace(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject())));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverActivationRecord(new ExtendedObject());
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
}
Also used : ExtendedObject(com.hp.mwtests.ts.arjuna.resources.ExtendedObject) OutputObjectState(com.arjuna.ats.arjuna.state.OutputObjectState) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) ParticipantStore(com.arjuna.ats.arjuna.objectstore.ParticipantStore) CadaverActivationRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord) Test(org.junit.Test)

Example 4 with PersistenceRecord

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

the class CadaverRecordUnitTest method test.

@Test
public void test() {
    ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
    CadaverRecord cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
    assertTrue(cr.propagateOnAbort());
    assertTrue(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.PERSISTENCE);
    assertTrue(cr.type() != null);
    assertEquals(cr.doSave(), false);
    cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(), store, new ExtendedObject()));
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject());
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    cr.merge(new PersistenceRecord(new OutputObjectState(new Uid(), "foobar"), store, new ExtendedObject()));
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new CadaverRecord();
    cr.print(new PrintWriter(new ByteArrayOutputStream()));
    assertFalse(cr.shouldMerge(new DisposeRecord()));
    assertFalse(cr.shouldReplace(new DisposeRecord()));
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) 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) DisposeRecord(com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord) CadaverRecord(com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 5 with PersistenceRecord

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

the class LastResourceUnitTest method test.

@Test
public void test() {
    // force errors!
    LastResourceRecord cr = new LastResourceRecord(null);
    assertFalse(cr.propagateOnAbort());
    assertFalse(cr.propagateOnCommit());
    assertEquals(cr.typeIs(), RecordType.LASTRESOURCE);
    assertTrue(cr.type() != null);
    assertFalse(cr.doSave());
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_NOTOK);
    assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new LastResourceRecord(null);
    assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_NOTOK);
    assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_ERROR);
    cr = new LastResourceRecord(null);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_NOTOK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr = new LastResourceRecord(null);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_NOTOK);
    assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
    cr = new LastResourceRecord(null);
    assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_NOTOK);
    assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
    cr.print(new PrintWriter(new ByteArrayOutputStream()));
    assertEquals(cr.value(), null);
    cr.setValue(null);
    assertFalse(cr.shouldAdd(new PersistenceRecord()));
    assertFalse(cr.shouldAlter(new PersistenceRecord()));
    assertFalse(cr.shouldMerge(new PersistenceRecord()));
    assertFalse(cr.shouldReplace(new PersistenceRecord()));
    cr = new LastResourceRecord();
    cr.merge(new PersistenceRecord());
    cr.alter(new PersistenceRecord());
}
Also used : LastResourceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PersistenceRecord(com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

PersistenceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.PersistenceRecord)6 OutputObjectState (com.arjuna.ats.arjuna.state.OutputObjectState)5 Test (org.junit.Test)5 ParticipantStore (com.arjuna.ats.arjuna.objectstore.ParticipantStore)4 ExtendedObject (com.hp.mwtests.ts.arjuna.resources.ExtendedObject)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintWriter (java.io.PrintWriter)3 InputObjectState (com.arjuna.ats.arjuna.state.InputObjectState)2 DisposeRecord (com.arjuna.ats.internal.arjuna.abstractrecords.DisposeRecord)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 BasicAction (com.arjuna.ats.arjuna.coordinator.BasicAction)1 CadaverActivationRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverActivationRecord)1 CadaverRecord (com.arjuna.ats.internal.arjuna.abstractrecords.CadaverRecord)1 LastResourceRecord (com.arjuna.ats.internal.arjuna.abstractrecords.LastResourceRecord)1 RecoveryRecord (com.arjuna.ats.internal.arjuna.abstractrecords.RecoveryRecord)1