use of com.arjuna.ats.arjuna.objectstore.ParticipantStore in project narayana by jbosstm.
the class BasicActionFinalizer method activate.
/**
* Overloaded version of activate -- sets up the store, performs read_state
* followed by restore_state. The root of the object store to use is
* specified in the <code>root</code> parameter.
*
* @return <code>true</code> if successful, <code>false</code>
* otherwise.
*/
public boolean activate(String root) {
if (tsLogger.logger.isTraceEnabled()) {
tsLogger.logger.trace("BasicAction::activate() for action-id " + get_uid());
}
boolean restored = false;
// Set up store
ParticipantStore aaStore = getStore();
if (aaStore == null)
return false;
try {
// Read object state
InputObjectState oState = aaStore.read_committed(getSavingUid(), type());
if (oState != null) {
synchronized (this) {
restored = restore_state(oState, ObjectType.ANDPERSISTENT);
}
oState = null;
} else {
tsLogger.i18NLogger.warn_coordinator_BasicAction_5(get_uid(), type());
restored = false;
}
return restored;
} catch (ObjectStoreException e) {
tsLogger.logger.warn(e);
return false;
}
}
use of com.arjuna.ats.arjuna.objectstore.ParticipantStore 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.arjuna.objectstore.ParticipantStore 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.arjuna.objectstore.ParticipantStore in project narayana by jbosstm.
the class DisposeRecordUnitTest method test.
@Test
public void test() {
ParticipantStore store = StoreManager.setupStore(null, StateType.OS_UNSHARED);
DisposeRecord cr = new DisposeRecord(store, new ExtendedObject());
assertFalse(cr.propagateOnAbort());
assertTrue(cr.propagateOnCommit());
assertEquals(cr.typeIs(), RecordType.DISPOSE);
assertTrue(cr.type() != null);
assertEquals(cr.doSave(), true);
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_OK);
cr = new DisposeRecord(store, new ExtendedObject());
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new DisposeRecord(store, new ExtendedObject());
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_OK);
cr = new DisposeRecord(store, new ExtendedObject());
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_OK);
assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new DisposeRecord();
assertFalse(cr.shouldAdd(new PersistenceRecord()));
assertFalse(cr.shouldAlter(new PersistenceRecord()));
assertFalse(cr.shouldMerge(new PersistenceRecord()));
assertFalse(cr.shouldReplace(new PersistenceRecord()));
assertFalse(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
}
use of com.arjuna.ats.arjuna.objectstore.ParticipantStore in project narayana by jbosstm.
the class PersistenceTest method test.
@Test
public void test() {
boolean passed = false;
boolean threaded = false;
long stime = Calendar.getInstance().getTime().getTime();
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
for (int i = 0; i < 1000; i++) {
try {
ParticipantStore store = null;
if (!threaded)
store = new ShadowingStore(objectStoreEnvironmentBean);
else
store = new CacheStore(objectStoreEnvironmentBean);
byte[] data = new byte[10240];
OutputObjectState state = new OutputObjectState();
Uid u = new Uid();
state.packBytes(data);
if (store.write_committed(u, "/StateManager/LockManager/foo", state)) {
passed = true;
} else
passed = false;
} catch (ObjectStoreException e) {
System.out.println(e.getMessage());
passed = false;
} catch (IOException ex) {
ex.printStackTrace();
passed = false;
}
}
try {
Thread.currentThread().sleep(1000);
} catch (Exception ex) {
}
long ftime = Calendar.getInstance().getTime().getTime();
long timeTaken = ftime - stime;
System.out.println("time for 1000 write transactions is " + timeTaken);
try {
Thread.currentThread().sleep(1000);
} catch (Exception ex) {
}
assertTrue(passed);
}
Aggregations