use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class InheritenceLockManagerProxyUnitTest method testInheritSaveRestore.
public void testInheritSaveRestore() {
Inherit obj = new Inherit();
LockManagerProxy<Inherit> proxy = new LockManagerProxy<Inherit>(obj);
OutputObjectState os = new OutputObjectState();
assertTrue(proxy.save_state(os, ObjectType.RECOVERABLE));
obj.myString = "";
InputObjectState ios = new InputObjectState(os);
assertTrue(proxy.restore_state(ios, ObjectType.RECOVERABLE));
assertEquals(obj.myString, "");
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class InheritenceLockManagerProxyUnitTest method testSaveRestore.
public void testSaveRestore() {
BasicLockable obj = new BasicLockable();
LockManagerProxy<BasicLockable> proxy = new LockManagerProxy<BasicLockable>(obj);
OutputObjectState os = new OutputObjectState();
assertTrue(proxy.save_state(os, ObjectType.RECOVERABLE));
obj._saved = 4567;
// make sure it's ignored by save/restore.
obj._isState = 0;
((Base) obj).valid = false;
InputObjectState ios = new InputObjectState(os);
assertTrue(proxy.restore_state(ios, ObjectType.RECOVERABLE));
assertEquals(obj._saved, 1234);
assertEquals(obj._isState, 0);
assertTrue(((Base) obj).valid);
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class OptimisticLockManager method loadState.
/*
* Lock and load the concurrency control state. First we grab the semaphore
* to ensure exclusive access and then we build the held lock list by
* retreiving the locks from the lock repository. If there is only one
* server we do not bother doing this since all the locks can stay in the
* server's memory. This is yet another consequence of not having
* multi-threaded servers. Does not require synchronized since it can only
* be called from other synchronized methods.
*/
protected final boolean loadState() {
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::loadState()");
}
if (super.objectModel == ObjectModel.SINGLE) {
stateLoaded = true;
return true;
} else {
InputObjectState S = null;
if ((systemKey == null) && !initialise()) {
return false;
/* init failed */
}
if ((mutex == null) || (!mutex.tryLock())) {
return false;
}
stateLoaded = false;
objectLocked = true;
try {
S = lockStore.read_state(get_uid(), type());
if (S != null) {
Uid u = null;
/*
* avoid system calls in Uid
* creation
*/
Lock current = null;
int count = 0;
try {
count = S.unpackInt();
boolean cleanLoad = true;
if (txojLogger.logger.isTraceEnabled()) {
txojLogger.logger.trace("LockManager::loadState() loading " + count + " lock(s)");
}
for (int i = 0; (i < count) && cleanLoad; i++) {
try {
u = UidHelper.unpackFrom(S);
current = new OptimisticLock(u);
if (current != null) {
if (current.restore_state(S, ObjectType.ANDPERSISTENT)) {
locksHeld.push(current);
} else {
current = null;
cleanLoad = false;
}
} else {
cleanLoad = false;
}
} catch (IOException e) {
cleanLoad = false;
}
}
if (cleanLoad)
stateLoaded = true;
else {
while ((current = locksHeld.pop()) != null) current = null;
}
} catch (IOException e) {
}
S = null;
} else
stateLoaded = true;
} catch (LockStoreException e) {
txojLogger.logger.warn(e);
}
}
if (!stateLoaded) {
if (// means object model != SINGLE
mutex != null) {
// and exit mutual exclusion
mutex.unlock();
}
objectLocked = false;
}
return stateLoaded;
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class ObjectStoreTest method testVolatileStore.
@Test
public void testVolatileStore() throws Exception {
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
objectStoreEnvironmentBean.setLocalOSRoot("tmp");
VolatileStore as = new VolatileStore(objectStoreEnvironmentBean);
final OutputObjectState buff = new OutputObjectState();
final String tn = "/StateManager/junit";
for (int i = 0; i < 100; i++) {
Uid u = new Uid();
InputObjectState ios = new InputObjectState();
try {
as.allObjUids("", ios);
} catch (final Exception ex) {
}
try {
assertTrue(as.read_uncommitted(u, tn) == null);
} catch (final Exception ex) {
}
try {
as.commit_state(u, tn);
} catch (final Exception ex) {
}
as.write_committed(u, tn, buff);
assertTrue(as.currentState(u, tn) == StateStatus.OS_COMMITTED);
as.read_committed(u, tn);
try {
assertTrue(as.remove_uncommitted(u, tn));
} catch (final Exception ex) {
}
as.remove_committed(u, tn);
try {
assertTrue(as.hide_state(u, tn));
} catch (final Exception ex) {
}
try {
assertTrue(as.reveal_state(u, tn));
} catch (final Exception ex) {
}
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class ObjectStoreTest method testHashedStore.
@Test
public void testHashedStore() throws Exception {
ObjectStoreEnvironmentBean objectStoreEnvironmentBean = new ObjectStoreEnvironmentBean();
objectStoreEnvironmentBean.setLocalOSRoot("tmp");
HashedStore as = new HashedStore(objectStoreEnvironmentBean);
final OutputObjectState buff = new OutputObjectState();
final String tn = "/StateManager/junit";
for (int i = 0; i < 100; i++) {
Uid u = new Uid();
as.write_uncommitted(u, tn, buff);
as.commit_state(u, tn);
assertTrue(as.currentState(u, tn) != StateStatus.OS_UNCOMMITTED);
InputObjectState ios = new InputObjectState();
as.allObjUids("", ios);
assertTrue(as.read_uncommitted(u, tn) == null);
as.write_committed(u, tn, buff);
as.read_committed(u, tn);
assertTrue(!as.remove_uncommitted(u, tn));
as.remove_committed(u, tn);
assertTrue(!as.hide_state(u, tn));
assertTrue(!as.reveal_state(u, tn));
}
}
Aggregations