Search in sources :

Example 1 with RecoveryManagerImple

use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.

the class ObjStoreBrowserTest method setUp.

@Before
public void setUp() throws Exception {
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    rcm = new RecoveryManagerImple(false);
    rcm.addModule(new AtomicActionRecoveryModule());
}
Also used : AtomicActionRecoveryModule(com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule) RecoveryManagerImple(com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple) Before(org.junit.Before)

Example 2 with RecoveryManagerImple

use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.

the class JTSSynchronizationTest method test.

@Test
public void test() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("com.arjuna.orbportability.orb.PreInit1", "com.arjuna.ats.internal.jts.context.ContextPropagationManager");
    map.put("com.arjuna.orbportability.orb.PostInit", "com.arjuna.ats.jts.utils.ORBSetup");
    map.put("com.arjuna.orbportability.orb.PostInit2", "com.arjuna.ats.internal.jts.recovery.RecoveryInit");
    map.put("com.arjuna.orbportability.orb.PostSet1", "com.arjuna.ats.jts.utils.ORBSetup");
    opPropertyManager.getOrbPortabilityEnvironmentBean().setOrbInitializationProperties(map);
    ORB myORB = ORB.getInstance("test");
    RootOA myOA = OA.getRootOA(myORB);
    final Properties initORBProperties = new Properties();
    initORBProperties.setProperty("com.sun.CORBA.POA.ORBServerId", "1");
    initORBProperties.setProperty("com.sun.CORBA.POA.ORBPersistentServerPort", "" + jtsPropertyManager.getJTSEnvironmentBean().getRecoveryManagerPort());
    myORB.initORB(new String[] {}, initORBProperties);
    myOA.initOA();
    ORBManager.setORB(myORB);
    ORBManager.setPOA(myOA);
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryActivatorClassNames(Arrays.asList(new String[] { "com.arjuna.ats.internal.jts.orbspecific.recovery.RecoveryEnablement" }));
    final TransactionSynchronizationRegistry tsr = new com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple();
    new RecoveryManagerImple(false);
    final javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
    tm.getStatus();
    tm.begin();
    javax.transaction.Transaction theTransaction = tm.getTransaction();
    assertTrue(theTransaction.enlistResource(new XARMERRXAResource(false)));
    assertTrue(theTransaction.enlistResource(new XARMERRXAResource(false)));
    tsr.registerInterposedSynchronization(new Synchronization() {

        @Override
        public void beforeCompletion() {
        }

        @Override
        public void afterCompletion(int arg0) {
            try {
                Transaction transaction = tm.getTransaction();
                Transaction suspend = tm.suspend();
                assertTrue(tm.getStatus() == javax.transaction.Status.STATUS_NO_TRANSACTION);
                Transaction suspend2 = tm.suspend();
                assertTrue(suspend2 == null);
                tm.begin();
                assertTrue(tm.getStatus() == javax.transaction.Status.STATUS_ACTIVE);
                tm.commit();
                assertTrue(tm.getStatus() == javax.transaction.Status.STATUS_NO_TRANSACTION);
                tm.resume(suspend);
                assertTrue(tm.getStatus() == arg0);
                Transaction transaction2 = tm.getTransaction();
                assertTrue(transaction == transaction2);
            } catch (SystemException | IllegalStateException | SecurityException | InvalidTransactionException | NotSupportedException | RollbackException | HeuristicMixedException | HeuristicRollbackException e) {
                failed = true;
                e.printStackTrace();
            }
        }
    });
    tm.commit();
    myOA.destroy();
    myORB.shutdown();
    if (failed) {
        fail("Issues");
    }
}
Also used : Transaction(javax.transaction.Transaction) HashMap(java.util.HashMap) RootOA(com.arjuna.orbportability.RootOA) Properties(java.util.Properties) RecoveryManagerImple(com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple) Synchronization(javax.transaction.Synchronization) Transaction(javax.transaction.Transaction) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) ORB(com.arjuna.orbportability.ORB) Test(org.junit.Test)

Example 3 with RecoveryManagerImple

use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.

the class RecoveryManagerService method start.

/**
 * Called when the service is started.
 * @param args The arguments
 * @return The exit code to return if the task didn't start successfully, otherwise null.
 */
public Integer start(String[] args) {
    Integer returnCode = null;
    try {
        new Uid();
        _rm = new RecoveryManagerImple(true);
    } catch (Throwable e) {
        e.printStackTrace(System.err);
        returnCode = new Integer(FAILED_TO_START_RETURN_CODE);
    }
    return returnCode;
}
Also used : Uid(com.arjuna.ats.arjuna.common.Uid) RecoveryManagerImple(com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple)

Example 4 with RecoveryManagerImple

use of com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple in project narayana by jbosstm.

the class TestCommitMarkableResourceFailAfterPrepareTwoXAResources method testFailAfterPrepare.

@Test
@BMScript("commitMarkableResourceFailAfterPrepare")
public void testFailAfterPrepare() throws Exception {
    final DataSource dataSource = new JdbcDataSource();
    ((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 recoveryModule = null;
    XARecoveryModule xarm = null;
    Vector recoveryModules = manager.getModules();
    if (recoveryModules != null) {
        Enumeration modules = recoveryModules.elements();
        while (modules.hasMoreElements()) {
            RecoveryModule m = (RecoveryModule) modules.nextElement();
            if (m instanceof CommitMarkableResourceRecordRecoveryModule) {
                recoveryModule = (CommitMarkableResourceRecordRecoveryModule) m;
            } else if (m instanceof 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, xaResource2 };
                    }
                });
            }
        }
    }
    // final Object o = new Object();
    // synchronized (o) {
    Thread foo = new Thread(new Runnable() {

        public void run() {
            try {
                javax.transaction.TransactionManager tm = com.arjuna.ats.jta.TransactionManager.transactionManager();
                tm.begin();
                Connection localJDBCConnection = dataSource.getConnection();
                localJDBCConnection.setAutoCommit(false);
                nonXAResource = new JDBCConnectableResource(localJDBCConnection);
                tm.getTransaction().enlistResource(nonXAResource);
                xaResource = new SimpleXAResource();
                tm.getTransaction().enlistResource(xaResource);
                xaResource2 = new SimpleXAResource2();
                tm.getTransaction().enlistResource(xaResource2);
                localJDBCConnection.createStatement().execute("INSERT INTO foo (bar) VALUES (1)");
                tm.commit();
            } catch (ExecuteException t) {
            } catch (Exception t) {
                t.printStackTrace();
                failed = true;
            } catch (Error t) {
            }
        }
    });
    foo.start();
    foo.join();
    assertFalse(failed);
    // This is test code, it allows us to verify that the
    // correct XID was
    // removed
    Xid committed = ((JDBCConnectableResource) nonXAResource).getStartedXid();
    assertNotNull(committed);
    // The recovery module has to perform lookups
    new InitialContext().rebind("commitmarkableresource", dataSource);
    // Run the first pass it will load the committed Xids into memory
    manager.scan();
    assertFalse(recoveryModule.wasCommitted("commitmarkableresource", committed));
    // Now we need to correctly complete the transaction
    assertFalse(xaResource.wasCommitted());
    assertFalse(xaResource.wasRolledback());
    SimpleXAResource2.injectRollbackError();
    boolean scanned = false;
    try {
        manager.scan();
        scanned = true;
    } catch (Error error) {
        // This is expected from xaResource2, it is intended to simulate a
        // crash
        // Should clear off the scanning flag only
        xarm.periodicWorkSecondPass();
    }
    if (scanned) {
        fail("Should have failed scan");
    }
    assertFalse(xaResource.wasCommitted());
    assertTrue(xaResource.wasRolledback());
    assertFalse(xaResource2.commitCalled());
    assertFalse(xaResource2.rollbackCalled());
    RecoveryManagerImple recoveryManagerImple = new RecoveryManagerImple(false);
    recoveryManagerImple.scan();
    assertFalse(xaResource2.commitCalled());
    assertTrue(xaResource2.rollbackCalled());
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) RecoveryManagerImple(com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) Vector(java.util.Vector) Enumeration(java.util.Enumeration) Connection(java.sql.Connection) ExecuteException(org.jboss.byteman.rule.exception.ExecuteException) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) XAResource(javax.transaction.xa.XAResource) Xid(javax.transaction.xa.Xid) CommitMarkableResourceRecordRecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Aggregations

RecoveryManagerImple (com.arjuna.ats.internal.arjuna.recovery.RecoveryManagerImple)4 Test (org.junit.Test)2 Uid (com.arjuna.ats.arjuna.common.Uid)1 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)1 AtomicActionRecoveryModule (com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule)1 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)1 XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)1 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)1 ORB (com.arjuna.orbportability.ORB)1 RootOA (com.arjuna.orbportability.RootOA)1 Connection (java.sql.Connection)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 Vector (java.util.Vector)1 InitialContext (javax.naming.InitialContext)1 DataSource (javax.sql.DataSource)1 Synchronization (javax.transaction.Synchronization)1 Transaction (javax.transaction.Transaction)1 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)1