Search in sources :

Example 16 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.

the class XAResourceRecord method getXAResourceDeserializers.

private List<SerializableXAResourceDeserializer> getXAResourceDeserializers() {
    if (serializableXAResourceDeserializers != null) {
        return serializableXAResourceDeserializers;
    }
    synchronized (this) {
        if (serializableXAResourceDeserializers != null) {
            return serializableXAResourceDeserializers;
        }
        serializableXAResourceDeserializers = new ArrayList<SerializableXAResourceDeserializer>();
        for (RecoveryModule recoveryModule : RecoveryManager.manager().getModules()) {
            if (recoveryModule instanceof XARecoveryModule) {
                XARecoveryModule xaRecoveryModule = (XARecoveryModule) recoveryModule;
                serializableXAResourceDeserializers.addAll(xaRecoveryModule.getSeriablizableXAResourceDeserializers());
                return serializableXAResourceDeserializers;
            }
        }
    }
    return serializableXAResourceDeserializers;
}
Also used : SerializableXAResourceDeserializer(com.arjuna.ats.jta.recovery.SerializableXAResourceDeserializer) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) RecoveryModule(com.arjuna.ats.arjuna.recovery.RecoveryModule) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 17 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.

the class XARecoveryModuleHelpersUnitTest method testTimelyXAResourceRecoveryHelperRemoval.

private void testTimelyXAResourceRecoveryHelperRemoval(final boolean somethingToRecover) throws Exception {
    final XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    final long xAResourcesSleepMillis = 2000;
    final long betweenPassesSleepMillis = 100;
    final long millis = System.currentTimeMillis();
    final SimpleResource testXAResource = new SimpleResource() {

        @Override
        public Xid[] recover(int i) throws XAException {
            if (!somethingToRecover)
                return new Xid[0];
            return new Xid[] { new Xid() {

                @Override
                public int getFormatId() {
                    return 0;
                }

                @Override
                public byte[] getGlobalTransactionId() {
                    return new byte[0];
                }

                @Override
                public byte[] getBranchQualifier() {
                    return new byte[0];
                }
            } };
        }
    };
    final XAResourceRecoveryHelper xaResourceRecoveryHelper = new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            return true;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            System.out.printf("getXAResources sleep (%d)%n", System.currentTimeMillis() - millis);
            Thread.sleep(xAResourcesSleepMillis);
            System.out.printf("getXAResources return (%d)%n", System.currentTimeMillis() - millis);
            return new XAResource[] { testXAResource };
        }
    };
    final XAResourceRecoveryHelper xaResourceRecoveryHelper2 = new XAResourceRecoveryHelper() {

        @Override
        public boolean initialise(String p) throws Exception {
            return true;
        }

        @Override
        public XAResource[] getXAResources() throws Exception {
            return new XAResource[0];
        }
    };
    /*
         * Remove helpers in the background whilst recovery is running to check that they are removed when
         * the scanner is in the correct state.
         * The sleep time param is tuned to ensure that the add/remove recovery helper operation occurs
         * during pass 1.
         */
    XAHelperRemover remover = new XAHelperRemover(xaResourceRecoveryHelper, xaRecoveryModule, xAResourcesSleepMillis / 2, false);
    XAHelperRemover remover2 = new XAHelperRemover(xaResourceRecoveryHelper2, xaRecoveryModule, xAResourcesSleepMillis / 2, true);
    xaRecoveryModule.addXAResourceRecoveryHelper(xaResourceRecoveryHelper);
    remover.start();
    remover2.start();
    System.out.printf("Before pass 1 (%d)%n", System.currentTimeMillis() - millis);
    xaRecoveryModule.periodicWorkFirstPass();
    System.out.printf("Finished pass 1 (%d)%n", System.currentTimeMillis() - millis);
    Thread.sleep(betweenPassesSleepMillis);
    System.out.printf("Starting pass 2 (%d)%n", System.currentTimeMillis() - millis);
    xaRecoveryModule.periodicWorkSecondPass();
    System.out.printf("Finished pass 2 (%d)%n", System.currentTimeMillis() - millis);
    // wait for helper removal threads to finish
    try {
        remover.join();
        remover2.join();
    } catch (InterruptedException e) {
        fail("Test was interrupted whilst waiting for xa resource helper threads: " + e.getMessage());
    }
    if (somethingToRecover) {
        assertEquals("helper removed in wrong state", 0, remover.getRemoveState());
    } else {
        // See https://issues.jboss.org/browse/JBTM-2717
        assertEquals("helper removed in wrong state", 2, remover.getRemoveState());
    }
    // the unused helper should have been removed after pass 1
    assertEquals("helper2 removed in wrong state", 2, remover2.getRemoveState());
}
Also used : Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)

Example 18 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.

the class XARecoveryModuleHelpersUnitTest method testTimelyXAResourceRecoveryHelperRemoval3.

/**
 * Test that recovery helpers can be added and removed during recovery pass 2
 * (and not have to wait until pass 2 is complete)
 * @throws Exception
 */
@BMScript("recovery-helper")
@Test
public void testTimelyXAResourceRecoveryHelperRemoval3() throws Exception {
    final XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    ExecutorService pool = Executors.newFixedThreadPool(1);
    new Thread() {

        public void run() {
            xaRecoveryModule.periodicWorkFirstPass();
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            xaRecoveryModule.periodicWorkSecondPass();
        }
    }.start();
    Future<String> future = pool.submit(new Callable<String>() {

        @Override
        public String call() throws Exception {
            final XAResourceRecoveryHelper xaResourceRecoveryHelper = new XAResourceRecoveryHelper() {

                @Override
                public boolean initialise(String p) throws Exception {
                    return true;
                }

                @Override
                public XAResource[] getXAResources() throws Exception {
                    return new XAResource[0];
                }
            };
            return addHelper(xaRecoveryModule, xaResourceRecoveryHelper, 3);
        }
    });
    String errMsg = future.get();
    assertNull(errMsg, errMsg);
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XAException(javax.transaction.xa.XAException) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 19 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testXAResourceOrphanFilterRegistration.

@Test
public void testXAResourceOrphanFilterRegistration() {
    XARecoveryModule xaRecoveryModule = new XARecoveryModule();
    XAResourceOrphanFilter xaResourceOrphanFilter = new DummyXAResourceOrphanFilter();
    xaRecoveryModule.addXAResourceOrphanFilter(xaResourceOrphanFilter);
    xaRecoveryModule.removeXAResourceOrphanFilter(xaResourceOrphanFilter);
}
Also used : JTANodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter) XAResourceOrphanFilter(com.arjuna.ats.jta.recovery.XAResourceOrphanFilter) NodeNameXAResourceOrphanFilter(com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 20 with XARecoveryModule

use of com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule in project narayana by jbosstm.

the class XARecoveryModuleUnitTest method testFailures.

@Test
public void testFailures() throws Exception {
    XARecoveryModule xarm = new XARecoveryModule();
    Class[] parameterTypes = new Class[2];
    Uid u = new Uid();
    Xid x = new XidImple();
    parameterTypes[0] = Xid.class;
    parameterTypes[1] = Uid.class;
    Method m = xarm.getClass().getDeclaredMethod("addFailure", parameterTypes);
    m.setAccessible(true);
    Object[] parameters = new Object[2];
    parameters[0] = x;
    parameters[1] = u;
    m.invoke(xarm, parameters);
    parameterTypes = new Class[1];
    parameterTypes[0] = Xid.class;
    parameters = new Object[1];
    parameters[0] = x;
    m = xarm.getClass().getDeclaredMethod("previousFailure", parameterTypes);
    m.setAccessible(true);
    Uid ret = (Uid) m.invoke(xarm, parameters);
    assertEquals(ret, u);
    parameterTypes = new Class[2];
    parameterTypes[0] = Xid.class;
    parameterTypes[1] = Uid.class;
    parameters = new Object[2];
    parameters[0] = x;
    parameters[1] = u;
    m = xarm.getClass().getDeclaredMethod("removeFailure", parameterTypes);
    m.setAccessible(true);
    m.invoke(xarm, parameters);
    m = xarm.getClass().getDeclaredMethod("clearAllFailures", (Class[]) null);
    m.setAccessible(true);
    m.invoke(xarm, (Object[]) null);
}
Also used : XidImple(com.arjuna.ats.jta.xa.XidImple) Uid(com.arjuna.ats.arjuna.common.Uid) Xid(javax.transaction.xa.Xid) Method(java.lang.reflect.Method) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Aggregations

XARecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule)37 Test (org.junit.Test)25 XAResourceRecoveryHelper (com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper)19 RecoveryModule (com.arjuna.ats.arjuna.recovery.RecoveryModule)18 XAResource (javax.transaction.xa.XAResource)17 Xid (javax.transaction.xa.Xid)14 Uid (com.arjuna.ats.arjuna.common.Uid)10 XidImple (com.arjuna.ats.jta.xa.XidImple)9 Enumeration (java.util.Enumeration)9 Vector (java.util.Vector)9 XAException (javax.transaction.xa.XAException)9 CommitMarkableResourceRecordRecoveryModule (com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule)8 Connection (java.sql.Connection)8 InitialContext (javax.naming.InitialContext)7 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)7 RecoveryManager (com.arjuna.ats.arjuna.recovery.RecoveryManager)6 ExecuteException (org.jboss.byteman.rule.exception.ExecuteException)6 JTANodeNameXAResourceOrphanFilter (com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter)5 ArrayList (java.util.ArrayList)5 XAResourceRecord (com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord)4