use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.
the class ObjectStoreTest method testIterator.
@Test
public void testIterator() throws Exception {
Uid u1 = new Uid();
Uid u2 = new Uid();
assertTrue(StoreManager.getTxLog().write_committed(u1, "foo", new OutputObjectState()));
assertTrue(StoreManager.getTxLog().write_committed(u2, "foo", new OutputObjectState()));
ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), "foo");
// iteration ordering is not guaranteed.
List<Uid> uids = new ArrayList<Uid>();
do {
Uid uid = iter.iterate();
if (uid.equals(Uid.nullUid())) {
break;
}
uids.add(uid);
} while (true);
boolean foundU1 = false;
boolean foundU2 = false;
StringBuffer listOfUids = new StringBuffer("u1:" + u1.stringForm() + "u2:" + u2.stringForm());
for (Uid uid : uids) {
if (u1.equals(uid)) {
foundU1 = true;
} else if (u2.equals(uid)) {
foundU2 = true;
}
listOfUids.append("1:" + uid.toString());
}
assertTrue("U1 search " + listOfUids.toString(), foundU1);
assertTrue("U2 search " + listOfUids.toString(), foundU2);
}
use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.
the class ObjectStoreAPIJMXTest method testIterator.
// @Test
// TODO this test only works on an initially empty store
public void testIterator() throws Exception {
Uid u1 = new Uid();
Uid u2 = new Uid();
prs.write_committed(u1, "foo", new OutputObjectState());
prs.write_committed(u2, "foo", new OutputObjectState());
ObjectStoreIterator iter = new ObjectStoreIterator(prs, "foo");
// iteration ordering is not guaranteed.
Uid x = iter.iterate();
assertTrue(x.notEquals(Uid.nullUid()));
assertTrue(x.equals(u1) || x.equals(u2));
Uid y = iter.iterate();
assertTrue(y.notEquals(Uid.nullUid()));
assertTrue(y.equals(u1) || y.equals(u2));
assertTrue(iter.iterate().equals(Uid.nullUid()));
}
use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.
the class LogBrowser method supportedLog.
/*
* Is this a type/instance in the log that we support?
*/
private final boolean supportedLog(String logID) throws ObjectStoreException, IOException {
Uid id = new Uid(logID);
if (id.equals(Uid.nullUid()))
return false;
ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), TransactionTypeManager.getInstance().getTransactionType(_transactionType));
Uid u;
do {
u = iter.iterate();
if (u.equals(id))
return true;
} while (Uid.nullUid().notEquals(u));
return false;
}
use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.
the class ObjStoreBrowser method getUids.
private Collection<Uid> getUids(String type) throws MBeanException {
Collection<Uid> uids = new ArrayList<Uid>();
try {
ObjectStoreIterator iter = new ObjectStoreIterator(StoreManager.getRecoveryStore(), type);
while (true) {
Uid u = iter.iterate();
if (u == null || Uid.nullUid().equals(u))
break;
uids.add(u);
}
} catch (ObjectStoreException | IOException e) {
throw new MBeanException(e);
}
return uids;
}
use of com.arjuna.ats.arjuna.objectstore.ObjectStoreIterator in project narayana by jbosstm.
the class XATerminatorImpleUnitTest method testMoveToAssumedComplete.
@Test
public void testMoveToAssumedComplete() throws Exception {
Implementations.initialise();
Implementationsx.initialise();
Uid uid = new Uid();
Xid xid = XidUtils.getXid(uid, false);
XATerminatorImple xaTerminator = new XATerminatorImple();
TransactionImporter importer = SubordinationManager.getTransactionImporter();
SubordinateTransaction subordinateTransaction = importer.importTransaction(xid);
Uid subordinateTransactionUid = getImportedSubordinateTransactionUid(subordinateTransaction);
com.hp.mwtests.ts.jta.subordinate.TestXAResource xares = new com.hp.mwtests.ts.jta.subordinate.TestXAResource();
xares.setCommitException(new XAException(XAException.XAER_RMFAIL));
subordinateTransaction.enlistResource(xares);
subordinateTransaction.doPrepare();
boolean commitFailed = subordinateTransaction.doCommit();
Assert.assertFalse("Commit should fail as XAResource defined XAException on commit being thrown", commitFailed);
int assumedCompletedRetryOriginalValue = jtsPropertyManager.getJTSEnvironmentBean().getCommitedTransactionRetryLimit();
jtsPropertyManager.getJTSEnvironmentBean().setCommitedTransactionRetryLimit(1);
try {
SubordinateTransaction recoveredTxn = importer.recoverTransaction(subordinateTransactionUid);
Xid xidRecovered = recoveredTxn.baseXid();
Assert.assertEquals("recovered subordinate xid should be equal to imported one", xid, xidRecovered);
Runnable runCommitExpectingException = () -> {
try {
// importing transaction
xaTerminator.recover(XAResource.TMSTARTRSCAN);
xaTerminator.recover(XAResource.TMENDRSCAN);
// try to commit the imported transaction
xaTerminator.commit(xid, false);
Assert.fail("XAException is expected to be thrown as txn was not yet moved to assumed complete state");
} catch (XAException expected) {
Assert.assertTrue("Commit expect to throw exception indicating that othe commit call is expected, but error code is " + expected.errorCode, XAException.XA_RETRY == expected.errorCode || XAException.XAER_RMFAIL == expected.errorCode);
}
};
// replay first
runCommitExpectingException.run();
// assume completed check first time
runCommitExpectingException.run();
// importing transaction
xaTerminator.recover(XAResource.TMSTARTRSCAN);
xaTerminator.recover(XAResource.TMENDRSCAN);
// moving to assumed completed state
xaTerminator.commit(xid, false);
} finally {
jtsPropertyManager.getJTSEnvironmentBean().setCommitedTransactionRetryLimit(assumedCompletedRetryOriginalValue);
}
try {
importer.recoverTransaction(subordinateTransactionUid);
Assert.fail("Transaction '" + subordinateTransaction + "' should fail to recover as it should be moved " + "to category AssumedCompleteServerTrasactions");
} catch (IllegalArgumentException expected) {
}
ObjectStoreIterator objectStoreIterator = new ObjectStoreIterator(StoreManager.getRecoveryStore(), AssumedCompleteServerTransaction.typeName());
List<Uid> assumedCompletedUids = new ArrayList<Uid>();
Uid iteratedUid = objectStoreIterator.iterate();
while (Uid.nullUid().notEquals(iteratedUid)) {
assumedCompletedUids.add(iteratedUid);
iteratedUid = objectStoreIterator.iterate();
}
Assert.assertTrue("the subordinate transaction has to be moved under assumed completed in object store", assumedCompletedUids.contains(subordinateTransactionUid));
}
Aggregations