Search in sources :

Example 16 with RecoveryManager

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);
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) XAResource(javax.transaction.xa.XAResource) AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver) Driver(org.h2.Driver) Properties(java.util.Properties) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) TransactionalDriver(com.arjuna.ats.jdbc.TransactionalDriver) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) BMRule(org.jboss.byteman.contrib.bmunit.BMRule) Test(org.junit.Test)

Example 17 with RecoveryManager

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;
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Enumeration(java.util.Enumeration) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector)

Example 18 with RecoveryManager

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());
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 19 with RecoveryManager

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");
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Test(org.junit.Test)

Example 20 with RecoveryManager

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);
}
Also used : XAResourceRecovery(com.arjuna.ats.jta.recovery.XAResourceRecovery) RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) JDBCStore(com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)23 Test (org.junit.Test)15 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)6 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)5 Enumeration (java.util.Enumeration)3 Properties (java.util.Properties)3 Vector (java.util.Vector)3 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)2 TransactionalDriver (com.arjuna.ats.jdbc.TransactionalDriver)2 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)2 XAResource (javax.transaction.xa.XAResource)2 Driver (org.h2.Driver)2 BMRule (org.jboss.byteman.contrib.bmunit.BMRule)2 InboundBridgeRecoveryModule (org.jboss.narayana.rest.bridge.inbound.InboundBridgeRecoveryModule)2 ExpiryScanner (com.arjuna.ats.arjuna.recovery.ExpiryScanner)1 RecoveryDriver (com.arjuna.ats.arjuna.recovery.RecoveryDriver)1 LogStore (com.arjuna.ats.internal.arjuna.objectstore.LogStore)1 JDBCStore (com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore)1 PropertyFileDynamicClass (com.arjuna.ats.internal.jdbc.drivers.PropertyFileDynamicClass)1 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)1