[jboss-cvs] JBossAS SVN: r71477 - branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 31 05:48:18 EDT 2008
Author: vicky.kak at jboss.com
Date: 2008-03-31 05:48:18 -0400 (Mon, 31 Mar 2008)
New Revision: 71477
Modified:
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestCase.java
branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java
Log:
[JBPAPP-662]-Needed for stress tests for JDBC and JMS activity competing with asynchronous rollback
Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestCase.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestCase.java 2008-03-31 09:44:28 UTC (rev 71476)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestCase.java 2008-03-31 09:48:18 UTC (rev 71477)
@@ -30,6 +30,8 @@
import junit.framework.TestCase;
import junit.framework.TestResult;
+import org.jboss.logging.Logger;
+
/**
* An ejb test case is an extension to test case where the test is executed
* in the ejb server's virtual machine.
@@ -68,6 +70,8 @@
*/
public class EJBTestCase extends TestCase
{
+ private static final Logger log = Logger.getLogger(EJBTestCase.class);
+
private boolean serverSide = false;
protected Properties props;
@@ -220,7 +224,28 @@
{
// empty
}
+
+ protected int getThreadCount()
+ {
+ int result = Integer.getInteger("jbosstest.threadcount", 10).intValue();
+ log.debug("jbosstest.threadcount=" + result);
+ return result;
+ }
+ protected int getIterationCount()
+ {
+ int result = Integer.getInteger("jbosstest.iterationcount", 100).intValue();
+ log.debug("jbosstest.iterationcount=" + result);
+ return result;
+ }
+
+ protected int getBeanCount()
+ {
+ int result = Integer.getInteger("jbosstest.beancount", 100).intValue();
+ log.debug("jbosstest.beancount=" + result);
+ return result;
+ }
+
/** Tears down the ejb test case. This method is called after
* each test is executed and is run in a private transaction.
* @param props the properties passed in from the client
Modified: branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java 2008-03-31 09:44:28 UTC (rev 71476)
+++ branches/JBPAPP_4_2_0_GA_CP/testsuite/src/main/org/jboss/test/util/ejb/EJBTestRunnerBean.java 2008-03-31 09:48:18 UTC (rev 71477)
@@ -32,7 +32,12 @@
import javax.naming.NamingEnumeration;
import javax.transaction.Status;
import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import org.jboss.logging.Logger;
+import org.jboss.tm.TransactionManagerLocator;
+
/**
* Implementation of the ejb test runner.
*
@@ -44,6 +49,7 @@
*/
public class EJBTestRunnerBean implements SessionBean
{
+ private static final Logger log = Logger.getLogger(EJBTestRunnerBean.class);
transient private SessionContext ctx;
private String runnerJndiName;
@@ -125,6 +131,11 @@
}
}
+ private static boolean wantUserTransaction(Properties props)
+ {
+ return props == null || props.get("NO_USER_TRANSACTION") == null;
+ }
+
/**
* Runs the setUpEJB method on the specified test case
* @param testCase the actual test case that will be run
@@ -134,9 +145,11 @@
private void setUpEJB(EJBTestCase testCase, Properties props)
throws RemoteTestException
{
+ boolean wantUserTransaction = wantUserTransaction(props);
try
{
- ctx.getUserTransaction().begin();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().begin();
try
{
testCase.setUpEJB(props);
@@ -145,7 +158,7 @@
{
throw new RemoteTestException(e);
}
- if (ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
+ if (wantUserTransaction && ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
{
ctx.getUserTransaction().commit();
}
@@ -154,7 +167,8 @@
{
try
{
- ctx.getUserTransaction().rollback();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().rollback();
}
catch (SystemException unused)
{
@@ -178,35 +192,65 @@
{
try
{
- ctx.getUserTransaction().begin();
+ boolean wantUserTransaction = wantUserTransaction(testCase.getProps());
try
{
- testCase.runBare();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().begin();
+ try
+ {
+ testCase.runBare();
+ }
+ catch (Throwable e)
+ {
+ throw new RemoteTestException(e);
+ }
+ if (wantUserTransaction && ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
+ {
+ ctx.getUserTransaction().commit();
+ }
}
catch (Throwable e)
{
+ try
+ {
+ if (wantUserTransaction)
+ ctx.getUserTransaction().rollback();
+ }
+ catch (SystemException unused)
+ {
+ // eat the exception we are exceptioning out anyway
+ }
+ if (e instanceof RemoteTestException)
+ {
+ throw (RemoteTestException) e;
+ }
throw new RemoteTestException(e);
}
- if (ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
- {
- ctx.getUserTransaction().commit();
- }
}
- catch (Throwable e)
+ finally
{
+ Transaction tx = null;
+ TransactionManager tm = TransactionManagerLocator.getInstance().locate();
try
{
- ctx.getUserTransaction().rollback();
+ tx = tm.getTransaction();
+ if (tx != null)
+ {
+ try
+ {
+ tx.rollback();
+ }
+ finally
+ {
+ tm.suspend();
+ }
+ }
}
- catch (SystemException unused)
+ catch (Exception e)
{
- // eat the exception we are exceptioning out anyway
+ log.error("Error rolling back incomplete transaction: " + tx, e);
}
- if (e instanceof RemoteTestException)
- {
- throw (RemoteTestException) e;
- }
- throw new RemoteTestException(e);
}
}
@@ -219,10 +263,11 @@
private void tearDownEJB(EJBTestCase testCase, Properties props)
throws RemoteTestException
{
-
+ boolean wantUserTransaction = wantUserTransaction(props);
try
{
- ctx.getUserTransaction().begin();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().begin();
try
{
testCase.tearDownEJB(props);
@@ -231,7 +276,7 @@
{
throw new RemoteTestException(e);
}
- if (ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
+ if (wantUserTransaction && ctx.getUserTransaction().getStatus() == Status.STATUS_ACTIVE)
{
ctx.getUserTransaction().commit();
}
@@ -240,7 +285,8 @@
{
try
{
- ctx.getUserTransaction().rollback();
+ if (wantUserTransaction)
+ ctx.getUserTransaction().rollback();
}
catch (SystemException unused)
{
More information about the jboss-cvs-commits
mailing list