[jboss-svn-commits] JBL Code SVN: r37616 - in labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed: server and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 19 15:23:21 EDT 2011


Author: tomjenkinson
Date: 2011-10-19 15:23:20 -0400 (Wed, 19 Oct 2011)
New Revision: 37616

Modified:
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java
   labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
Log:
JBTM-917 added a test to make sure that the orphan filter for subordinate nodes is working

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java	2011-10-19 19:20:42 UTC (rev 37615)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/SimpleIsolatedServers.java	2011-10-19 19:23:20 UTC (rev 37616)
@@ -23,7 +23,6 @@
 
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.LinkedList;
@@ -87,18 +86,88 @@
 	}
 
 	@Test
+	@BMScript("leaveorphan")
+	public void testCreateOrphan() throws Exception {
+		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
+		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
+		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+		final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
+		Thread thread = new Thread(new Runnable() {
+			public void run() {
+				int startingTimeout = 0;
+				try {
+					int startingServer = 1000;
+					LocalServer originalServer = getLocalServer(startingServer);
+					ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+					Thread.currentThread().setContextClassLoader(originalServer.getClass().getClassLoader());
+					TransactionManager transactionManager = originalServer.getTransactionManager();
+					transactionManager.setTransactionTimeout(startingTimeout);
+					transactionManager.begin();
+					Transaction originalTransaction = transactionManager.getTransaction();
+					int remainingTimeout = (int) (originalServer.getTimeLeftBeforeTransactionTimeout() / 1000);
+					Xid currentXid = originalServer.getCurrentXid();
+					originalServer.storeRootTransaction();
+					transactionManager.suspend();
+					performTransactionalWork(null, new LinkedList<Integer>(Arrays.asList(new Integer[] { 2000 })), remainingTimeout, currentXid);
+					transactionManager.resume(originalTransaction);
+					XAResource proxyXAResource = originalServer.generateProxyXAResource(lookupProvider, originalServer.getNodeName(), 2000);
+					originalTransaction.enlistResource(proxyXAResource);
+					originalTransaction.enlistResource(new TestResource(null, originalServer.getNodeName(), false));
+					originalServer.removeRootTransaction(currentXid);
+					transactionManager.commit();
+					Thread.currentThread().setContextClassLoader(classLoader);
+				} catch (ExecuteException e) {
+					System.err.println("Should be a thread death but cest la vie");
+					synchronized (phase2CommitAborted) {
+						phase2CommitAborted.setPhase2CommitAborted(true);
+						phase2CommitAborted.notify();
+					}
+				} catch (Throwable t) {
+					t.printStackTrace();
+				}
+			}
+		}, "Orphan-creator");
+		thread.start();
+		synchronized (phase2CommitAborted) {
+			if (!phase2CommitAborted.isPhase2CommitAborted()) {
+				phase2CommitAborted.wait();
+			}
+		}
+		tearDown();
+		setup();
+		{
+
+			LocalServer server = getLocalServer(2000);
+			assertTrue(server.getCompletionCounter().getCommitCount() == 0);
+			assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
+			server.doRecoveryManagerScan(true);
+			assertTrue(server.getCompletionCounter().getCommitCount() == 0);
+			assertTrue(server.getCompletionCounter().getRollbackCount() == 1);
+		}
+		{
+			LocalServer server = getLocalServer(1000);
+			assertTrue(server.getCompletionCounter().getCommitCount() == 0);
+			assertTrue(server.getCompletionCounter().getRollbackCount() == 0);
+			server.doRecoveryManagerScan(true);
+			assertTrue(server.getCompletionCounter().getCommitCount() == 0);
+			assertTrue(server.getCompletionCounter().getRollbackCount() == 1);
+		}
+	}
+
+	@Test
 	@BMScript("fail2pc")
 	public void testRecovery() throws Exception {
+		tearDown();
+		setup();
 		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 0);
 		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 0);
 		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 0);
+		assertTrue(getLocalServer(3000).getCompletionCounter().getRollbackCount() == 0);
+		assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 0);
+		assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
 		final Phase2CommitAborted phase2CommitAborted = new Phase2CommitAborted();
 		Thread thread = new Thread(new Runnable() {
 			public void run() {
-				File file = new File(System.getProperty("user.dir") + "/tmp/");
-				if (file.exists()) {
-					file.delete();
-				}
 				int startingTimeout = 0;
 				List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
 				try {
@@ -150,21 +219,19 @@
 		// Start out at the first server
 		// getLocalServer(3000).doRecoveryManagerScan();
 		// getLocalServer(2000).doRecoveryManagerScan();
-		getLocalServer(1000).doRecoveryManagerScan();
+		getLocalServer(1000).doRecoveryManagerScan(false);
 
-		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 3);
-		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 3);
+		assertTrue(getLocalServer(1000).getCompletionCounter().getCommitCount() == 4);
+		assertTrue(getLocalServer(2000).getCompletionCounter().getCommitCount() == 4);
 		assertTrue(getLocalServer(3000).getCompletionCounter().getCommitCount() == 3);
+		assertTrue(getLocalServer(3000).getCompletionCounter().getRollbackCount() == 0);
+		assertTrue(getLocalServer(2000).getCompletionCounter().getRollbackCount() == 0);
+		assertTrue(getLocalServer(1000).getCompletionCounter().getRollbackCount() == 0);
 	}
 
 	@Test
 	public void testMigrateTransactionCommit() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
 			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
 		int startingTimeout = 0;
 		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
 		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true);
@@ -174,10 +241,6 @@
 	public void testMigrateTransactionCommitDiamond() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
 			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
 
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
 		int startingTimeout = 0;
 		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
 		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, true);
@@ -186,11 +249,6 @@
 	@Test
 	public void testMigrateTransactionRollback() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
 			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
 		int startingTimeout = 0;
 		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 3000, 2000, 1000, 2000, 3000, 1000, 3000 }));
 		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false);
@@ -199,11 +257,6 @@
 	@Test
 	public void testMigrateTransactionRollbackDiamond() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
 			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
 		int startingTimeout = 0;
 		List<Integer> nodesToFlowTo = new LinkedList<Integer>(Arrays.asList(new Integer[] { 1000, 2000, 1000, 3000, 1000, 2000, 3000 }));
 		doRecursiveTransactionalWork(startingTimeout, nodesToFlowTo, false);
@@ -212,11 +265,6 @@
 	@Test
 	public void testMigrateTransactionSubordinateTimeout() throws NotSupportedException, SystemException, IllegalStateException, RollbackException,
 			InvalidTransactionException, XAException, SecurityException, HeuristicMixedException, HeuristicRollbackException, InterruptedException {
-
-		File file = new File(System.getProperty("user.dir") + "/tmp/");
-		if (file.exists()) {
-			file.delete();
-		}
 		int rootTimeout = 10000;
 		int subordinateTimeout = 1;
 

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java	2011-10-19 19:20:42 UTC (rev 37615)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/CompletionCounter.java	2011-10-19 19:23:20 UTC (rev 37616)
@@ -23,8 +23,12 @@
 
 public interface CompletionCounter {
 	public void incrementCommit();
+
 	public void incrementRollback();
+
 	int getCommitCount();
+
 	int getRollbackCount();
+
 	void resetCounters();
 }

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java	2011-10-19 19:20:42 UTC (rev 37615)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/LocalServer.java	2011-10-19 19:23:20 UTC (rev 37616)
@@ -44,7 +44,7 @@
 
 	public TransactionManager getTransactionManager() throws NotSupportedException, SystemException;
 
-	public void doRecoveryManagerScan();
+	public void doRecoveryManagerScan(boolean hackSafetyInterval);
 
 	public long getTimeLeftBeforeTransactionTimeout() throws RollbackException;
 

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java	2011-10-19 19:20:42 UTC (rev 37615)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResource.java	2011-10-19 19:23:20 UTC (rev 37616)
@@ -35,6 +35,7 @@
 import org.jboss.tm.XAResourceWrapper;
 
 import com.arjuna.ats.arjuna.common.Uid;
+import com.arjuna.ats.jta.distributed.server.CompletionCounter;
 import com.arjuna.ats.jta.distributed.server.DummyRemoteException;
 import com.arjuna.ats.jta.distributed.server.LookupProvider;
 
@@ -50,6 +51,7 @@
 	private Integer localServerName;
 	private LookupProvider lookupProvider;
 	private Xid xid;
+	private CompletionCounter completionCounter;
 
 	/**
 	 * Create a new proxy to the remote server.
@@ -58,7 +60,8 @@
 	 * @param localServerName
 	 * @param remoteServerName
 	 */
-	public ProxyXAResource(LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName) {
+	public ProxyXAResource(CompletionCounter completionCounter, LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName) {
+		this.completionCounter = completionCounter;
 		this.lookupProvider = lookupProvider;
 		this.localServerName = localServerName;
 		this.remoteServerName = remoteServerName;
@@ -72,7 +75,8 @@
 	 * @param file
 	 * @throws IOException
 	 */
-	public ProxyXAResource(LookupProvider lookupProvider, Integer localServerName, File file) throws IOException {
+	public ProxyXAResource(CompletionCounter completionCounter, LookupProvider lookupProvider, Integer localServerName, File file) throws IOException {
+		this.completionCounter = completionCounter;
 		this.lookupProvider = lookupProvider;
 		this.localServerName = localServerName;
 		this.file = file;
@@ -177,21 +181,34 @@
 		if (file != null) {
 			file.delete();
 		}
+		if (completionCounter != null) {
+			completionCounter.incrementCommit();
+		}
 	}
 
 	@Override
 	public synchronized void rollback(Xid xid) throws XAException {
 		System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACK[" + xid + "]");
+
 		try {
 			lookupProvider.lookup(remoteServerName).propagateRollback(xid);
 			System.out.println("     ProxyXAResource (" + localServerName + ":" + remoteServerName + ") XA_ROLLBACKED");
 		} catch (DummyRemoteException ce) {
 			throw new XAException(XAException.XA_RETRY);
+		} catch (XAException e) {
+			if (e.errorCode == XAException.XAER_INVAL) {
+				// We know that this means that the transaction is not known at
+				// the remote side
+				e.printStackTrace();
+			}
 		}
 
 		if (file != null) {
 			file.delete();
 		}
+		if (completionCounter != null) {
+			completionCounter.incrementRollback();
+		}
 	}
 
 	/**

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java	2011-10-19 19:20:42 UTC (rev 37615)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ProxyXAResourceRecovery.java	2011-10-19 19:23:20 UTC (rev 37616)
@@ -30,19 +30,20 @@
 
 import org.jboss.tm.XAResourceRecovery;
 
+import com.arjuna.ats.jta.distributed.server.CompletionCounter;
 import com.arjuna.ats.jta.distributed.server.LookupProvider;
 
 public class ProxyXAResourceRecovery implements XAResourceRecovery {
 
 	private List<ProxyXAResource> resources = new ArrayList<ProxyXAResource>();
 
-	public ProxyXAResourceRecovery(LookupProvider lookupProvider, Integer id) throws IOException {
+	public ProxyXAResourceRecovery(CompletionCounter counter, LookupProvider lookupProvider, Integer id) throws IOException {
 		File file = new File(System.getProperty("user.dir") + "/distributedjta/ProxyXAResource/" + id + "/");
 		if (file.exists() && file.isDirectory()) {
 			File[] listFiles = file.listFiles();
 			for (int i = 0; i < listFiles.length; i++) {
 				File currentFile = listFiles[i];
-				resources.add(new ProxyXAResource(lookupProvider, id, currentFile));
+				resources.add(new ProxyXAResource(counter, lookupProvider, id, currentFile));
 			}
 		}
 	}

Modified: labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java
===================================================================
--- labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java	2011-10-19 19:20:42 UTC (rev 37615)
+++ labs/jbosstm/branches/JBOSSTS_4_15_0_Final/atsintegration/tests/classes/com/arjuna/ats/jta/distributed/server/impl/ServerImpl.java	2011-10-19 19:23:20 UTC (rev 37616)
@@ -22,6 +22,7 @@
 package com.arjuna.ats.jta.distributed.server.impl;
 
 import java.io.IOException;
+import java.lang.reflect.Field;
 import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -52,6 +53,7 @@
 import com.arjuna.ats.arjuna.tools.osb.mbean.ObjStoreBrowser;
 import com.arjuna.ats.internal.arjuna.utils.ManualProcessId;
 import com.arjuna.ats.internal.jbossatx.jta.XAResourceRecordWrappingPluginImpl;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.RecoveryXids;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateTransaction;
 import com.arjuna.ats.internal.jta.transaction.arjunacore.jca.SubordinateXidImple;
@@ -133,9 +135,9 @@
 		recoveryEnvironmentBean.setRecoveryActivators(null);
 
 		CoreEnvironmentBean coreEnvironmentBean = com.arjuna.ats.arjuna.common.arjPropertyManager.getCoreEnvironmentBean();
-//		coreEnvironmentBean.setSocketProcessIdPort(4714 + nodeName);
+		// coreEnvironmentBean.setSocketProcessIdPort(4714 + nodeName);
 		coreEnvironmentBean.setNodeIdentifier(nodeName);
-//		coreEnvironmentBean.setSocketProcessIdMaxPorts(1);
+		// coreEnvironmentBean.setSocketProcessIdMaxPorts(1);
 		coreEnvironmentBean.setProcessImplementationClassName(ManualProcessId.class.getName());
 		coreEnvironmentBean.setPid(coreEnvironmentBean.getNodeIdentifier());
 
@@ -182,7 +184,7 @@
 
 		recoveryManagerService = new RecoveryManagerService();
 		recoveryManagerService.create();
-		recoveryManagerService.addXAResourceRecovery(new ProxyXAResourceRecovery(lookupProvider, nodeName));
+		recoveryManagerService.addXAResourceRecovery(new ProxyXAResourceRecovery(counter, lookupProvider, nodeName));
 		recoveryManagerService.addXAResourceRecovery(new TestResourceRecovery(counter, nodeName));
 
 		// recoveryManagerService.start();
@@ -195,13 +197,6 @@
 		transactionManagerService
 				.setTransactionSynchronizationRegistry(new com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple());
 		transactionManagerService.create();
-
-		// Field safetyIntervalMillis =
-		// RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
-		// safetyIntervalMillis.setAccessible(true);
-		// Field modifiersField = Field.class.getDeclaredField("modifiers");
-		// modifiersField.setAccessible(true);
-		// safetyIntervalMillis.set(null, 0);
 	}
 
 	@Override
@@ -211,12 +206,38 @@
 	}
 
 	@Override
-	public void doRecoveryManagerScan() {
+	public void doRecoveryManagerScan(boolean hackSafetyInterval) {
 		ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
 		ClassLoader serversClassLoader = this.getClass().getClassLoader();
 		Thread.currentThread().setContextClassLoader(serversClassLoader);
+		int originalSafetyInterval = -1;
 
+		if (hackSafetyInterval) {
+			try {
+				Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
+				safetyIntervalMillis.setAccessible(true);
+				originalSafetyInterval = (Integer) safetyIntervalMillis.get(null);
+				Field modifiersField = Field.class.getDeclaredField("modifiers");
+				modifiersField.setAccessible(true);
+				safetyIntervalMillis.set(null, 0);
+			} catch (Throwable t) {
+				t.printStackTrace();
+			}
+		}
+
 		_recoveryManager.scan();
+
+		if (hackSafetyInterval) {
+			try {
+				Field safetyIntervalMillis = RecoveryXids.class.getDeclaredField("safetyIntervalMillis");
+				safetyIntervalMillis.setAccessible(true);
+				Field modifiersField = Field.class.getDeclaredField("modifiers");
+				modifiersField.setAccessible(true);
+				safetyIntervalMillis.set(null, originalSafetyInterval);
+			} catch (Throwable t) {
+				t.printStackTrace();
+			}
+		}
 		Thread.currentThread().setContextClassLoader(classLoader);
 	}
 
@@ -271,7 +292,7 @@
 
 	@Override
 	public ProxyXAResource generateProxyXAResource(LookupProvider lookupProvider, Integer localServerName, Integer remoteServerName) {
-		return new ProxyXAResource(lookupProvider, localServerName, remoteServerName);
+		return new ProxyXAResource(counter, lookupProvider, localServerName, remoteServerName);
 	}
 
 	@Override



More information about the jboss-svn-commits mailing list