[jboss-cvs] JBossAS SVN: r81738 - trunk/testsuite/src/main/org/jboss/test/jca/test.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Nov 27 11:12:38 EST 2008
Author: adrian at jboss.org
Date: 2008-11-27 11:12:38 -0500 (Thu, 27 Nov 2008)
New Revision: 81738
Modified:
trunk/testsuite/src/main/org/jboss/test/jca/test/TxConnectionManagerStressTestCase.java
Log:
Implement a latch handoff so we can wait longer for the tx timeout - attempt to try to make this test more robust to timing issues
Modified: trunk/testsuite/src/main/org/jboss/test/jca/test/TxConnectionManagerStressTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/jca/test/TxConnectionManagerStressTestCase.java 2008-11-27 15:53:33 UTC (rev 81737)
+++ trunk/testsuite/src/main/org/jboss/test/jca/test/TxConnectionManagerStressTestCase.java 2008-11-27 16:12:38 UTC (rev 81738)
@@ -22,6 +22,7 @@
package org.jboss.test.jca.test;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
@@ -29,6 +30,7 @@
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnectionFactory;
import javax.security.auth.Subject;
+import javax.transaction.Synchronization;
import javax.transaction.Transaction;
import javax.transaction.TransactionManager;
import javax.transaction.NotSupportedException;
@@ -450,94 +452,123 @@
log.info("Timeout test with connections: " + pp.maxSize + " totalThreads: " + totalThreads + " reps: " + reps);
for (int i = 0; i < totalThreads; i++)
{
- Runnable t = new Runnable()
- {
- int id;
- public void run()
- {
- id = startedThreadCount.getAndIncrement();
+ Runnable t = new TestRunnable(reps, cm, trackByTx);
+ new Thread(t).start();
+ }
+ finishedThreadCount.await();
- for (int j = 0; j < reps; j++)
- {
- ConnectionListener cl = null;
- try
- {
- assertNotNull(tm);
- tm.setTransactionTimeout(2);
- tm.begin();
+ assertTrue("Error in timeout test: " + error, !failed);
+ }
+ finally
+ {
+ if (cm != null)
+ shutdown(cm);
+ }
+ }
+
+ public class TestRunnable implements Runnable, Synchronization
+ {
+ int id;
+ int reps;
+ TxConnectionManager cm;
+ boolean trackByTx;
+ CountDownLatch latch = new CountDownLatch(1);
- cl = cm.getManagedConnection(subject, cri);
- cl.enlist();
+ public TestRunnable(int reps, TxConnectionManager cm, boolean trackByTx)
+ {
+ this.reps = reps;
+ this.cm = cm;
+ this.trackByTx = trackByTx;
+ }
- // TX timeout
- Thread.sleep(2500L);
+ public void run()
+ {
+ id = startedThreadCount.getAndIncrement();
- assertNotNull(tm);
+ for (int j = 0; j < reps; j++)
+ {
+ ConnectionListener cl = null;
+ try
+ {
+ assertNotNull(tm);
- Transaction tx = tm.getTransaction();
- if (tx != null && TxUtils.isActive(tx))
- failed = true;
+ tm.setTransactionTimeout(2);
+ tm.begin();
+ Transaction tx = tm.getTransaction();
+ tx.registerSynchronization(this);
- if (!trackByTx)
- {
- cl.delist();
- cm.returnManagedConnection(cl, false);
- }
- cl = null;
+ cl = cm.getManagedConnection(subject, cri);
+ cl.enlist();
- }
- catch (NotSupportedException nse)
- {
- error = nse;
- log.info(nse.getMessage(), nse);
- }
- catch (SystemException se)
- {
- error = se;
- log.info(se.getMessage(), se);
- }
- catch (ResourceException re)
- {
- error = re;
- log.info(re.getMessage(), re);
- }
- catch (InterruptedException ie)
- {
- break;
- }
- finally
- {
- if (cl != null)
- cm.returnManagedConnection(cl, true);
+ latch.await(20, TimeUnit.SECONDS);
- try
- {
- assertNotNull(tm);
- Transaction tx = tm.getTransaction();
- if (tx != null && TxUtils.isActive(tx))
- failed = true;
- }
- catch (SystemException se)
- {
- }
- }
- }
+ assertNotNull(tm);
- finishedThreadCount.countDown();
+ tx = tm.getTransaction();
+ if (tx != null && TxUtils.isActive(tx))
+ failed = true;
+
+ if (!trackByTx)
+ {
+ cl.delist();
+ cm.returnManagedConnection(cl, false);
}
- };
- new Thread(t).start();
+ cl = null;
+
+ }
+ catch (NotSupportedException nse)
+ {
+ error = nse;
+ log.info(nse.getMessage(), nse);
+ }
+ catch (RollbackException se)
+ {
+ error = se;
+ log.info(se.getMessage(), se);
+ }
+ catch (SystemException se)
+ {
+ error = se;
+ log.info(se.getMessage(), se);
+ }
+ catch (ResourceException re)
+ {
+ error = re;
+ log.info(re.getMessage(), re);
+ }
+ catch (InterruptedException ie)
+ {
+ break;
+ }
+ finally
+ {
+ if (cl != null)
+ cm.returnManagedConnection(cl, true);
+
+ try
+ {
+ assertNotNull(tm);
+ Transaction tx = tm.suspend();
+ if (tx != null && TxUtils.isActive(tx))
+ failed = true;
+ }
+ catch (SystemException se)
+ {
+ }
+ }
}
- finishedThreadCount.await();
+ finishedThreadCount.countDown();
+ }
- assertTrue("Error in timeout test: " + error, !failed);
+ public void beforeCompletion()
+ {
}
- finally
+
+ public void afterCompletion(int status)
{
- if (cm != null)
- shutdown(cm);
+ latch.countDown();
}
}
More information about the jboss-cvs-commits
mailing list