Search in sources :

Example 21 with RecoveryManager

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

the class RecoveryShutdownTest method test.

/**
 * test that the call sequence
 *
 * XARecoveryModule#getNewXAResource()
 * RecoveryManager#terminate();
 * XARecoveryModule#removeXAResourceRecoveryHelper
 *
 * does not hang
 *
 * @throws InterruptedException if the test is interrupted
 */
@Test
public void test() throws InterruptedException {
    recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryBackoffPeriod(1);
    RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
    XARecoveryModule xarm = new XARecoveryModule();
    final SimpleResource testXAResource = new SimpleResource() {

        @Override
        public Xid[] recover(int i) throws XAException {
            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 {
            return new XAResource[] { testXAResource };
        }
    };
    xarm.addXAResourceRecoveryHelper(xaResourceRecoveryHelper);
    manager.removeAllModules(false);
    manager.addModule(xarm);
    manager.scan();
    manager.terminate();
    xarm.getNewXAResource(new XAResourceRecord(null, null, new XidImple(), null));
    final boolean[] removedHelper = { false };
    Runnable r = () -> {
        // the next call will hang unless JBTM-2837 is fixed
        xarm.removeXAResourceRecoveryHelper(xaResourceRecoveryHelper);
        removedHelper[0] = true;
    };
    Thread t = new Thread(r);
    t.start();
    Thread.sleep(100);
    assertTrue("removal of an XAResourceRecoveryHelper hung", removedHelper[0]);
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) XidImple(com.arjuna.ats.jta.xa.XidImple) Xid(javax.transaction.xa.Xid) XAResource(javax.transaction.xa.XAResource) XAResourceRecord(com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord) XAResourceRecoveryHelper(com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper) XARecoveryModule(com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule) Test(org.junit.Test)

Example 22 with RecoveryManager

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

the class Test01 method main.

public static void main(String[] args) {
    System.setProperty("com.arjuna.ats.jta.xaRecoveryNode", "1");
    System.setProperty("XAResourceRecovery1", "com.hp.mwtests.ts.jta.recovery.DummyXARecoveryResource");
    try {
        RecoveryManager manager = RecoveryManager.manager(RecoveryManager.DIRECT_MANAGEMENT);
        manager.scan();
        manager.scan();
        System.out.println("Passed.");
    } catch (Exception ex) {
        System.out.println("Failed.");
    }
    System.clearProperty("com.arjuna.ats.jta.xaRecoveryNode");
    System.clearProperty("XAResourceRecovery1");
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager)

Example 23 with RecoveryManager

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

the class ExecutionWrapper method main.

public static void main(String[] args) throws Exception {
    String className = args[0];
    String[] subArgs = new String[args.length - 1];
    System.arraycopy(args, 1, subArgs, 0, args.length - 1);
    if (className.equals("com.arjuna.ats.arjuna.recovery.RecoveryManager")) {
        if (!recMgrFile.createNewFile()) {
            System.err.println("Recovery manager already running?");
            System.exit(-1);
        }
        recMgrFile.deleteOnExit();
        System.out.println("Ready");
        Thread.sleep(Long.MAX_VALUE);
    } else if (className.equals("org.jboss.jbossts.qa.Utils.EmptyObjectStore")) {
        String objectStoreBaseDirBaseName = System.getProperty("ObjectStoreBaseDir");
        // strip off the trailing '/emptyObjectStore' to get the test rather than task dir
        objectStoreBaseDirBaseName = objectStoreBaseDirBaseName.substring(0, objectStoreBaseDirBaseName.lastIndexOf(System.getProperty("file.separator")));
        File directory = new File(objectStoreBaseDirBaseName);
        for (File candidateFile : directory.listFiles()) {
            if (candidateFile.isDirectory()) {
                System.err.println("emptying " + candidateFile.getCanonicalPath());
                EmptyObjectStore.removeContents(candidateFile);
            }
        }
        System.out.println("Passed");
    } else {
        int portOffset = Integer.valueOf(System.getProperty("portOffsetId")) * 20;
        int recoveryOrbPortBase = jtsPropertyManager.getJTSEnvironmentBean().getRecoveryManagerPort();
        int recoveryOrbPort = recoveryOrbPortBase + portOffset;
        jtsPropertyManager.getJTSEnvironmentBean().setRecoveryManagerPort(recoveryOrbPort);
        int recoveryManagerPortBase = recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryPort();
        int recoveryManagerPort = recoveryManagerPortBase + portOffset;
        recoveryPropertyManager.getRecoveryEnvironmentBean().setRecoveryPort(recoveryManagerPort);
        System.out.println("using ports " + recoveryOrbPort + " and " + recoveryManagerPort);
        String objectStoreBaseDirBaseName = System.getProperty("ObjectStoreBaseDir");
        // full path incl taskName, see TestGroupBase
        File directory = new File(objectStoreBaseDirBaseName);
        File hornetqStoreDir = new File(directory, "HornetQStore");
        // additionalCommandLineElements.add("-DHornetqJournalEnvironmentBean.storeDir="+hornetqStoreDir);
        BeanPopulator.getDefaultInstance(HornetqJournalEnvironmentBean.class).setStoreDir(hornetqStoreDir.getCanonicalPath());
        BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class).setObjectStoreType("com.arjuna.ats.internal.arjuna.objectstore.hornetq.HornetqObjectStoreAdaptor");
        /*

    [junit] Running org.jboss.jbossts.qa.junit.testgroup.TestGroup_txcore_recovery
    [junit] Tests run: 36, Failures: 24, Errors: 0, Time elapsed: 971.637 sec
    [junit] Test org.jboss.jbossts.qa.junit.testgroup.TestGroup_txcore_recovery FAILED
 */
        File ostoreDir = new File(directory, "ObjectStore");
        BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class).setObjectStoreDir(ostoreDir.getCanonicalPath());
        BeanPopulator.getNamedInstance(ObjectStoreEnvironmentBean.class, "communicationStore").setObjectStoreDir(ostoreDir.getCanonicalPath());
        BeanPopulator.getNamedInstance(ObjectStoreEnvironmentBean.class, "stateStore").setObjectStoreDir(ostoreDir.getCanonicalPath());
        final Properties p = new Properties();
        p.setProperty("OAPort", "" + recoveryOrbPort);
        // for persistent servers the JavaIdl orb requires you to explicitly define which port the
        // server will run on and to provide a unique id per server per machine:
        p.setProperty("com.sun.CORBA.POA.ORBPersistentServerPort", "" + recoveryOrbPort);
        p.setProperty("com.sun.CORBA.POA.ORBServerId", "" + recoveryOrbPort);
        initOrb(p, 10, recoveryOrbPort, args);
        RecoveryManager manager = RecoveryManager.manager();
        Class clazz = Class.forName(className);
        Method mainMethod = clazz.getMethod("main", new Class[] { subArgs.getClass() });
        before();
        mainMethod.invoke(null, new Object[] { subArgs });
        after();
        manager.terminate();
        System.exit(0);
    }
}
Also used : RecoveryManager(com.arjuna.ats.arjuna.recovery.RecoveryManager) Method(java.lang.reflect.Method) Properties(java.util.Properties) File(java.io.File)

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