use of com.arjuna.ats.arjuna.recovery.RecoveryManager in project narayana by jbosstm.
the class RecoveryTest method test.
@Test
@BMRule(name = "throw lang error exception", targetClass = "org.h2.jdbcx.JdbcXAConnection", targetMethod = "commit", action = "throw new java.lang.Error()", targetLocation = "AT ENTRY")
public void test() throws Exception {
String url = "jdbc:arjuna:";
Properties p = System.getProperties();
p.put("jdbc.drivers", Driver.class.getName());
System.setProperties(p);
transactionalDriver = new TransactionalDriver();
DriverManager.registerDriver(transactionalDriver);
Properties dbProperties = new Properties();
final JdbcDataSource ds = new JdbcDataSource();
ds.setURL("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1");
dbProperties.put(TransactionalDriver.XADataSource, ds);
step0_setupTables(url, dbProperties);
// We need to do this in a different thread as otherwise the transaction would still be associated with the connection due to the java.lang.Error
// RMFAIL on it's own will cause H2 to close connection and that seems to discard the indoubt transactions
step1_leaveXidsInDbTable(url, dbProperties);
step2_checkDbIsNotCommitted(url, dbProperties);
// 3. Perform recovery
{
XARecoveryModule xarm = new XARecoveryModule();
xarm.addXAResourceRecoveryHelper(new XAResourceRecoveryHelper() {
@Override
public boolean initialise(String p) throws Exception {
return false;
}
@Override
public XAResource[] getXAResources() throws Exception {
return new XAResource[] { ds.getXAConnection().getXAResource() };
}
});
RecoveryManager manager = RecoveryManager.manager();
manager.removeAllModules(true);
manager.addModule(xarm);
AtomicActionRecoveryModule aarm = new AtomicActionRecoveryModule();
aarm.periodicWorkFirstPass();
Transformer.disableTriggers(true);
aarm.periodicWorkSecondPass();
Transformer.enableTriggers(true);
}
step4_finalDbCommitCheck(url, dbProperties);
}
use of com.arjuna.ats.arjuna.recovery.RecoveryManager in project narayana by jbosstm.
the class CMRIntegrationTest method getCRRRM.
private CommitMarkableResourceRecordRecoveryModule getCRRRM() {
CommitMarkableResourceRecordRecoveryModule crrrm = null;
RecoveryManager recMan = RecoveryManager.manager();
Vector recoveryModules = recMan.getModules();
if (recoveryModules != null) {
Enumeration modules = recoveryModules.elements();
while (modules.hasMoreElements()) {
RecoveryModule m = (RecoveryModule) modules.nextElement();
if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
return (CommitMarkableResourceRecordRecoveryModule) m;
}
}
}
return null;
}
use of com.arjuna.ats.arjuna.recovery.RecoveryManager in project narayana by jbosstm.
the class CrashRecovery2 method test.
@BMScript("fail2pc")
@Test
public void test() throws NotSupportedException, SystemException, IllegalStateException, RollbackException, SecurityException, HeuristicMixedException, HeuristicRollbackException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
// ok, now drive a TX to completion. the script should ensure that the
// recovery
TestXAResource firstResource = new TestXAResource();
TestXAResource secondResource = new TestXAResource();
javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
tm.begin();
javax.transaction.Transaction theTransaction = tm.getTransaction();
theTransaction.enlistResource(firstResource);
theTransaction.enlistResource(secondResource);
tm.commit();
TestXAResourceRecovery.setResources(firstResource, secondResource);
assertEquals(0, firstResource.commitCount());
assertEquals(0, secondResource.commitCount());
assertEquals(0, firstResource.rollbackCount());
assertEquals(0, secondResource.rollbackCount());
RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
manager.initialize();
manager.scan();
assertEquals(0, firstResource.rollbackCount());
assertEquals(0, secondResource.rollbackCount());
assertEquals(1, firstResource.commitCount());
assertEquals(1, secondResource.commitCount());
}
use of com.arjuna.ats.arjuna.recovery.RecoveryManager in project narayana by jbosstm.
the class RecoveryManagerTest method test.
@Test
public void test() {
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
System.setProperty("com.arjuna.ats.jta.xaRecoveryNode", "1");
System.setProperty("XAResourceRecovery1", "com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
manager.scan();
manager.scan();
System.clearProperty("com.arjuna.ats.jta.xaRecoveryNode");
System.clearProperty("XAResourceRecovery1");
}
use of com.arjuna.ats.arjuna.recovery.RecoveryManager in project narayana by jbosstm.
the class TestJDBCStoreOffline method test.
@Test
public void test() throws NotSupportedException, SystemException, IllegalStateException, RollbackException, SecurityException, HeuristicMixedException, HeuristicRollbackException, NamingException {
arjPropertyManager.getObjectStoreEnvironmentBean().setObjectStoreType(JDBCStore.class.getName());
arjPropertyManager.getObjectStoreEnvironmentBean().setJdbcAccess(TestJDBCAccess.class.getName());
javax.transaction.TransactionManager tm = TransactionManager.transactionManager();
tm.begin();
tm.getTransaction().enlistResource(new DummyXAResource());
tm.getTransaction().enlistResource(new DummyXAResource());
tm.commit();
assertTrue(commitCount == 1);
FAULT_JDBC = true;
jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(Arrays.asList(new String[] { "1" }));
jtaPropertyManager.getJTAEnvironmentBean().setXaResourceOrphanFilters(Arrays.asList(new XAResourceOrphanFilter[] { new com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter(), new com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter() }));
jtaPropertyManager.getJTAEnvironmentBean().setXaResourceRecoveries(Arrays.asList(new XAResourceRecovery[] { new DummyXAResourceRecovery() }));
jtaPropertyManager.getJTAEnvironmentBean().setOrphanSafetyInterval(1);
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(2);
recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryModules(Arrays.asList(new RecoveryModule[] { new XARecoveryModule() }));
RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
manager.scan();
assertFalse(rollbackCalled);
}
Aggregations