use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class AtomicActionRecoveryModule method periodicWorkFirstPass.
/**
* This is called periodically by the RecoveryManager
*/
public void periodicWorkFirstPass() {
// Transaction type
boolean AtomicActions = false;
// uids per transaction type
InputObjectState aa_uids = new InputObjectState();
try {
if (tsLogger.logger.isDebugEnabled()) {
tsLogger.logger.debug("AtomicActionRecoveryModule first pass");
}
AtomicActions = _recoveryStore.allObjUids(_transactionType, aa_uids);
} catch (ObjectStoreException ex) {
tsLogger.i18NLogger.warn_recovery_AtomicActionRecoveryModule_1(ex);
}
if (AtomicActions) {
_transactionUidVector = processTransactions(aa_uids);
}
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class LogStoreTest method test.
@Test
public void test() {
arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(LogStore.class.getName());
RecoveryStore recoveryStore = StoreManager.getRecoveryStore();
final int numberOfTransactions = 1000;
final Uid[] ids = new Uid[numberOfTransactions];
final int fakeData = 0xdeedbaaf;
final String type = "/StateManager/BasicAction/TwoPhaseCoordinator/AtomicAction/Test";
for (int i = 0; i < numberOfTransactions; i++) {
OutputObjectState dummyState = new OutputObjectState();
try {
dummyState.packInt(fakeData);
ids[i] = new Uid();
recoveryStore.write_committed(ids[i], type, dummyState);
} catch (final Exception ex) {
ex.printStackTrace();
}
}
InputObjectState ios = new InputObjectState();
boolean passed = false;
try {
if (recoveryStore.allObjUids(type, ios, StateStatus.OS_UNKNOWN)) {
Uid id = new Uid(Uid.nullUid());
int numberOfEntries = 0;
do {
try {
id = UidHelper.unpackFrom(ios);
} catch (Exception ex) {
id = Uid.nullUid();
}
if (id.notEquals(Uid.nullUid())) {
passed = true;
System.err.println("Located transaction log " + id + " in object store.");
numberOfEntries++;
boolean found = false;
for (int i = 0; i < ids.length; i++) {
if (id.equals(ids[i]))
found = true;
}
if (passed && !found) {
passed = false;
System.err.println("Found unexpected transaction!");
}
}
} while (id.notEquals(Uid.nullUid()));
if ((numberOfEntries != ids.length) && passed) {
passed = false;
System.err.println("Expected " + ids.length + " and got " + numberOfEntries);
}
}
} catch (final Exception ex) {
ex.printStackTrace();
}
assertTrue(passed);
}
use of com.arjuna.ats.arjuna.state.InputObjectState 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.arjuna.state.InputObjectState in project narayana by jbosstm.
the class RecoveryRecordUnitTest method test.
@Test
public void test() {
RecoveryRecord cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
assertFalse(cr.propagateOnAbort());
assertTrue(cr.propagateOnCommit());
assertEquals(cr.typeIs(), RecordType.RECOVERY);
assertTrue(cr.type() != null);
assertEquals(cr.doSave(), false);
assertTrue(cr.value() != null);
cr.setValue(new OutputObjectState());
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.nestedAbort(), TwoPhaseOutcome.FINISH_ERROR);
cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
assertEquals(cr.nestedPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.nestedCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.topLevelAbort(), TwoPhaseOutcome.FINISH_ERROR);
cr = new RecoveryRecord(new OutputObjectState(), new ExtendedObject());
assertEquals(cr.topLevelPrepare(), TwoPhaseOutcome.PREPARE_READONLY);
assertEquals(cr.topLevelCommit(), TwoPhaseOutcome.FINISH_OK);
cr = new RecoveryRecord();
cr.merge(new RecoveryRecord());
cr.alter(new RecoveryRecord());
assertTrue(cr.save_state(new OutputObjectState(), ObjectType.ANDPERSISTENT));
assertFalse(cr.restore_state(new InputObjectState(), ObjectType.ANDPERSISTENT));
}
use of com.arjuna.ats.arjuna.state.InputObjectState in project narayana by jbosstm.
the class TestCommitMarkableResourceReturnUnknownOutcomeFrom1PCCommit method testRMFAILAfterCommit.
@Test
public void testRMFAILAfterCommit() throws Exception {
jtaPropertyManager.getJTAEnvironmentBean().setNotifyCommitMarkableResourceRecoveryModuleOfCompleteBranches(false);
final JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL("jdbc:h2:mem:JBTMDB;MVCC=TRUE;DB_CLOSE_DELAY=-1");
// Test code
Utils.createTables(dataSource.getConnection());
// We can't just instantiate one as we need to be using the
// same one as
// the transaction
// manager would have used to mark the transaction for GC
CommitMarkableResourceRecordRecoveryModule commitMarkableResourceRecoveryModule = null;
Vector recoveryModules = manager.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
commitMarkableResourceRecoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
} else if (m instanceof XARecoveryModule) {
XARecoveryModule xarm = (XARecoveryModule) m;
xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
public boolean initialise(String p) throws Exception {
return true;
}
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { xaResource };
}
});
}
}
}
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
Uid get_uid = ((TransactionImple) tm.getTransaction()).get_uid();
Connection localJDBCConnection = dataSource.getConnection();
localJDBCConnection.setAutoCommit(false);
nonXAResource = new JDBCConnectableResource(localJDBCConnection) {
@Override
public void commit(Xid arg0, boolean arg1) throws XAException {
super.commit(arg0, arg1);
throw new XAException(XAException.XAER_RMFAIL);
}
};
tm.getTransaction().enlistResource(nonXAResource);
xaResource = new SimpleXAResource();
tm.getTransaction().enlistResource(xaResource);
localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
tm.commit();
assertTrue(xaResource.wasCommitted());
Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
assertNotNull(committed);
InputObjectState uids = new InputObjectState();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
Uid uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(get_uid));
// Belt and braces but we don't expect the CMR to be removed anyway as
// the RM is "offline"
manager.scan();
manager.scan();
// The recovery module has to perform lookups
new InitialContext().rebind("commitmarkableresource", dataSource);
assertTrue(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
// This will complete the atomicaction
manager.scan();
StoreManager.getRecoveryStore().allObjUids(new AtomicAction().type(), uids);
uid = UidHelper.unpackFrom(uids);
assertTrue(uid.equals(Uid.nullUid()));
// This is when the CMR deletes are done due to ordering
manager.scan();
// of the recovery modules
assertFalse(commitMarkableResourceRecoveryModule.wasCommitted("commitmarkableresource", committed));
}
Aggregations