[jboss-svn-commits] JBL Code SVN: r37917 - in labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta: tests/classes/com/hp/mwtests/ts/jta/recovery and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Mar 12 13:11:40 EDT 2012
Author: tomjenkinson
Date: 2012-03-12 13:11:40 -0400 (Mon, 12 Mar 2012)
New Revision: 37917
Added:
labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARROne.java
labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTestResource.java
labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTwo.java
Modified:
labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/build.xml
labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryModuleUnitTest.java
Log:
Added a test to demonstrate what can happen when two XARR are configured with the same Xid
Modified: labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/build.xml
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/build.xml 2012-03-12 17:09:44 UTC (rev 37916)
+++ labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/build.xml 2012-03-12 17:11:40 UTC (rev 37917)
@@ -80,6 +80,9 @@
<exclude name="**/TestSynchronization.java"/>
<exclude name="**/TestXAResource.java"/>
<exclude name="**/SimpleNestedDisabledTest.java"/>
+ <exclude name="**/XARROne.java"/>
+ <exclude name="**/XARRTwo.java"/>
+ <exclude name="**/XARRTestResource.java"/>
</fileset>
</tests>
</run.tests.macro>
Added: labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARROne.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARROne.java (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARROne.java 2012-03-12 17:11:40 UTC (rev 37917)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: DummyXARecoveryResource.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.jta.recovery;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.xa.XAResource;
+
+import com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper;
+
+public class XARROne implements XAResourceRecoveryHelper {
+
+ private List<XAResource> resources = new ArrayList<XAResource>();
+
+ public XARROne() throws IOException {
+ File file = new File("XARR.txt");
+ if (file.exists()) {
+ resources.add(new XARRTestResource("XARROne", file));
+ }
+ }
+
+ @Override
+ public XAResource[] getXAResources() {
+ return resources.toArray(new XAResource[] {});
+ }
+
+ @Override
+ public boolean initialise(String p) throws Exception {
+ return true;
+ }
+
+}
Added: labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTestResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTestResource.java (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTestResource.java 2012-03-12 17:11:40 UTC (rev 37917)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: RecoveryXAResource.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.jta.recovery;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.transaction.xa.XAException;
+import javax.transaction.xa.XAResource;
+import javax.transaction.xa.Xid;
+
+public class XARRTestResource implements XAResource {
+
+ private Map<File,Xid> xids = new HashMap<File, Xid>();
+ private File file;
+ private String xarrHelper;
+
+ public XARRTestResource() {
+ }
+
+ public XARRTestResource(String xarrHelper, File file) throws IOException {
+ this.xarrHelper = xarrHelper;
+ this.file = file;
+ DataInputStream fis = new DataInputStream(new FileInputStream(file));
+ final int formatId = fis.readInt();
+ final int gtrid_length = fis.readInt();
+ final byte[] gtrid = new byte[gtrid_length];
+ fis.read(gtrid, 0, gtrid_length);
+ final int bqual_length = fis.readInt();
+ final byte[] bqual = new byte[bqual_length];
+ fis.read(bqual, 0, bqual_length);
+ xids.put(file, new Xid() {
+
+ @Override
+ public byte[] getGlobalTransactionId() {
+ return gtrid;
+ }
+
+ @Override
+ public int getFormatId() {
+ return formatId;
+ }
+
+ @Override
+ public byte[] getBranchQualifier() {
+ return bqual;
+ }
+ });
+ }
+
+ public Xid[] recover(int flag) throws XAException {
+ System.out.println("XARRTestResource XA_RECOVER [" + xarrHelper + "] [" + xids.size() + "]");
+ return xids.values().toArray(new Xid[] {});
+ }
+
+ public int prepare(Xid xid) throws XAException {
+ System.out.println("XARRTestResource XA_PREPARE [" + xid + "]");
+ try {
+ final int formatId = xid.getFormatId();
+ final byte[] gtrid = xid.getGlobalTransactionId();
+ final int gtrid_length = gtrid.length;
+ final byte[] bqual = xid.getBranchQualifier();
+ final int bqual_length = bqual.length;
+
+ File file = new File("XARR.txt");
+ DataOutputStream fos = new DataOutputStream(new FileOutputStream(file));
+ fos.writeInt(formatId);
+ fos.writeInt(gtrid_length);
+ fos.write(gtrid, 0, gtrid_length);
+ fos.writeInt(bqual_length);
+ fos.write(bqual, 0, bqual_length);
+ fos.flush();
+ fos.close();
+ return XAResource.XA_OK;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ throw new XAException();
+ } catch (IOException e) {
+ e.printStackTrace();
+ throw new XAException();
+ }
+ }
+
+ public void commit(Xid xid, boolean onePhase) throws XAException {
+ System.out.println("XARRTestResource XA_COMMIT [" + xarrHelper + "] [" + xid + "]");
+ if (!this.file.exists()) {
+ throw new XAException();
+ } else {
+ file.delete();
+ xids.remove(file);
+ }
+ }
+
+ public void rollback(Xid xid) throws XAException {
+ System.out.println("XARRTestResource XA_ROLLBACK [" + xarrHelper + "] [" + xid + "]");
+ if (!this.file.exists()) {
+ throw new XAException();
+ } else {
+ file.delete();
+ xids.remove(file);
+ }
+ }
+
+ public boolean isSameRM(XAResource xares) throws XAException {
+ return (xares == this);
+ }
+
+ public void start(Xid xid, int flags) throws XAException {
+ }
+
+ public void end(Xid xid, int flags) throws XAException {
+ }
+
+ public void forget(Xid xid) throws XAException {
+ }
+
+ public int getTransactionTimeout() throws XAException {
+ return 0;
+ }
+
+ public boolean setTransactionTimeout(int seconds) throws XAException {
+ return true;
+ }
+
+}
Added: labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTwo.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTwo.java (rev 0)
+++ labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARRTwo.java 2012-03-12 17:11:40 UTC (rev 37917)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+/*
+ * Copyright (C) 2004,
+ *
+ * Arjuna Technologies Ltd,
+ * Newcastle upon Tyne,
+ * Tyne and Wear,
+ * UK.
+ *
+ * $Id: DummyXARecoveryResource.java 2342 2006-03-30 13:06:17Z $
+ */
+
+package com.hp.mwtests.ts.jta.recovery;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.transaction.xa.XAResource;
+
+import com.arjuna.ats.jta.recovery.XAResourceRecoveryHelper;
+
+public class XARRTwo implements XAResourceRecoveryHelper {
+
+ private List<XAResource> resources = new ArrayList<XAResource>();
+
+ public XARRTwo() throws IOException {
+ File file = new File("XARR.txt");
+ if (file.exists()) {
+ resources.add(new XARRTestResource("XARRTwo", file));
+ }
+ }
+
+ @Override
+ public XAResource[] getXAResources() {
+ return resources.toArray(new XAResource[] {});
+ }
+
+ @Override
+ public boolean initialise(String p) throws Exception {
+ return true;
+ }
+
+}
Modified: labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryModuleUnitTest.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryModuleUnitTest.java 2012-03-12 17:09:44 UTC (rev 37916)
+++ labs/jbosstm/branches/JBOSSTS_4_16/ArjunaJTA/jta/tests/classes/com/hp/mwtests/ts/jta/recovery/XARecoveryModuleUnitTest.java 2012-03-12 17:11:40 UTC (rev 37917)
@@ -32,12 +32,16 @@
package com.hp.mwtests.ts.jta.recovery;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.List;
import javax.transaction.xa.XAResource;
import javax.transaction.xa.Xid;
@@ -45,9 +49,20 @@
import org.junit.Test;
import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.arjuna.coordinator.ActionStatus;
+import com.arjuna.ats.arjuna.coordinator.AddOutcome;
+import com.arjuna.ats.arjuna.coordinator.BasicAction;
+import com.arjuna.ats.arjuna.coordinator.RecordType;
import com.arjuna.ats.arjuna.coordinator.TwoPhaseOutcome;
+import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeManager;
+import com.arjuna.ats.arjuna.coordinator.abstractrecord.RecordTypeMap;
+import com.arjuna.ats.arjuna.recovery.RecoverAtomicAction;
+import com.arjuna.ats.arjuna.recovery.RecoveryManager;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.NodeNameXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids;
import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
import com.arjuna.ats.internal.jta.resources.arjunacore.XAResourceRecord;
+import com.arjuna.ats.internal.jta.transaction.arjunacore.AtomicAction;
import com.arjuna.ats.internal.jta.transaction.arjunacore.subordinate.jca.TransactionImple;
import com.arjuna.ats.jta.common.jtaPropertyManager;
import com.arjuna.ats.jta.recovery.XAResourceOrphanFilter;
@@ -67,8 +82,75 @@
assertNotNull(xarm.id());
}
+
@Test
+ public void testRecoverFromMultipleXAResourceRecovery() throws Exception {
+ // Make sure the file doesn't exist
+ assertFalse(new File("XARR.txt").exists());
+
+ ArrayList<String> r = new ArrayList<String>();
+
+ AtomicAction aa = new AtomicAction();
+ aa.begin();
+ assertEquals(AddOutcome.AR_ADDED, aa.add(new XAResourceRecord(null, new XARRTestResource(), new XidImple(aa), null)));
+
+ Class c = BasicAction.class;
+ Method method = c.getDeclaredMethod("prepare", boolean.class);
+ method.setAccessible(true);
+ int result = (Integer) method.invoke(aa, new Object[] { true });
+ assertEquals(result, TwoPhaseOutcome.PREPARE_OK);
+
+ // Make sure the file exists
+ assertTrue(new File("XARR.txt").exists());
+
+// AtomicActionRecoveryModule aaRecoveryModule = new AtomicActionRecoveryModule();
+// aaRecoveryModule.periodicWorkFirstPass();
+// aaRecoveryModule.periodicWorkSecondPass();
+
+ RecordTypeManager.manager().add(new RecordTypeMap() {
+ @SuppressWarnings("unchecked")
+ public Class getRecordClass ()
+ {
+ return XAResourceRecord.class;
+ }
+
+ public int getType ()
+ {
+ return RecordType.JTA_RECORD;
+ }
+ });
+
+ List<String> xarn = new ArrayList<String>();
+ xarn.add(NodeNameXAResourceOrphanFilter.RECOVER_ALL_NODES);
+
+ jtaPropertyManager.getJTAEnvironmentBean().setXaRecoveryNodes(xarn);
+ XARecoveryModule xaRecoveryModule = new XARecoveryModule();
+ Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
+ safetyIntervalMillis.setAccessible(true);
+ safetyIntervalMillis.set(null, 0);
+ xaRecoveryModule.addXAResourceRecoveryHelper(new XARROne());
+ xaRecoveryModule.addXAResourceRecoveryHelper(new XARRTwo());
+ xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter());
+ xaRecoveryModule.addXAResourceOrphanFilter(new com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter());
+ RecoveryManager.manager().addModule(xaRecoveryModule);
+
+
+ // This is done rather than using the AtomicActionRecoveryModule as the transaction is inflight
+ RecoverAtomicAction rcvAtomicAction = new RecoverAtomicAction(aa.get_uid(), ActionStatus.COMMITTED);
+ rcvAtomicAction.replayPhase2();
+
+ // The XARM would execute next
+ xaRecoveryModule.periodicWorkFirstPass();
+ xaRecoveryModule.periodicWorkSecondPass();
+
+ // Make sure the file doesn't exist
+ assertFalse(new File("XARR.txt").exists());
+
+ aa.abort();
+ }
+
+ @Test
public void testRecover () throws Exception
{
ArrayList<String> r = new ArrayList<String>();
More information about the jboss-svn-commits
mailing list