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);
}
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;
}
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);
}
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()));
}
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());
}
Aggregations