[jboss-svn-commits] JBL Code SVN: r32622 - in labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance: configuration and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Apr 23 13:56:22 EDT 2010
Author: whitingjr
Date: 2010-04-23 13:56:21 -0400 (Fri, 23 Apr 2010)
New Revision: 32622
Added:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/XACachedConnection.java
Modified:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiThreadedTest.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/WarmedUpTest.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/ConcurrentTaskConfiguration.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/JPAConfiguration.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTest.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTest.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeResourcesTest.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/RecursiveTask.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java
Log:
Updated test cases.
Added cached connection classes to remove pooling overhead.
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiThreadedTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiThreadedTest.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiThreadedTest.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -17,6 +17,7 @@
* Use this method to start concurrent executions of the test. This should be used for
* initial warm up run of the compiler and stable runs.
*/
+ @SuppressWarnings("static-access")
@Override
public void startConcurrentExecutions(final TestConfiguration configuration, final boolean printSummary)
throws Exception
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/WarmedUpTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/WarmedUpTest.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/WarmedUpTest.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -27,10 +27,16 @@
import java.util.List;
import java.util.concurrent.Executor;
+import org.apache.commons.exec.CommandLine;
+import org.apache.commons.exec.DefaultExecutor;
+import org.apache.commons.exec.ExecuteWatchdog;
+import org.apache.commons.exec.PumpStreamHandler;
+import org.apache.commons.exec.ShutdownHookProcessDestroyer;
import org.apache.log4j.Logger;
import org.apache.log4j.NDC;
import org.jboss.jbossts.performance.configuration.MultithreadedTestConfiguration;
import org.jboss.jbossts.performance.configuration.TestConfiguration;
+import org.jboss.jbossts.performance.process.DstatHandler;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
@@ -46,7 +52,7 @@
public abstract class WarmedUpTest extends ProfiledStateTransitions
{
private static final Logger logger = Logger.getLogger(WarmedUpTest.class);
- //private static final Logger csvLogger = Logger.getLogger("csv.file.logger");
+ private static final String DSTAT_PROPERTY = "dstat-file-name";
@Test(groups = "integration-warmup")
@Parameters(
@@ -68,51 +74,52 @@
throws Exception
{
NDC.push("profiled");
+ ExecuteWatchdog watchdog = null;
try
{
+ /* Start asynchronously a system process to capture system
+ * performance metrics during execution. */
+ CommandLine commandLine = CommandLine.parse("dstat");
+ commandLine.addArgument("--output");
+ commandLine.addArgument(System.getProperty(DSTAT_PROPERTY));
+ DefaultExecutor executor = new DefaultExecutor();
+ if (logger.isDebugEnabled())
+ {
+ logger.debug(String.format("Redirecting dstat output stream to file [%1$s]", System.getProperty(DSTAT_PROPERTY)));
+ }
+ PumpStreamHandler handler = new PumpStreamHandler(null, null);
+ /* Setting this destroyer stops the dstat when the JVM shutsdown. */
+
+ watchdog = new ExecuteWatchdog (Integer.MAX_VALUE);
+ executor.setWatchdog(watchdog);
+ executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
+
+ executor.setStreamHandler(handler);
+ executor.execute(commandLine, new DstatHandler());
getProfiler().start();
- } catch (Exception e)
+ getProfiler().startCPURecording();
+ }
+ catch (Exception e)
{
- logger.warn(e.getMessage());
+ logger.error(e.getMessage(), e);
}
int threadCount = Integer.parseInt(concurrentCountConfig);
List<Long> results = Collections.synchronizedList(new ArrayList<Long>(threadCount));
startConcurrentExecutions(new TestConfiguration(Integer.parseInt(testCountConfig), Integer.parseInt(concurrentCountConfig), results), true);
- //logResults(results, threadCount, Integer.parseInt(testCountConfig));
try
{
getProfiler().stop();
+ if (null != watchdog)
+ {
+ watchdog.destroyProcess();
+ }
} catch (Exception e)
{
- logger.warn(e.getMessage());
+ logger.error(e.getMessage(), e);
}
NDC.remove();
}
- /*
- * This method will log the results to file. The method takes all the results and devides
- * by the number of threads to calculate an average amount.
- * format: thread count, average per thread, tx per second, time (in seconds), tx
- */
- private void logResults(List<Long> results, Integer threadCount, Integer testCount)
- {
- long total = 0l;
- for(Long result : results)
- {
- total += result;
- }
- /*
- if (this.csvLogger.isDebugEnabled())
- {
- long average = total / threadCount;
- float timeInSecs = total / 1000;
- int tx = threadCount * testCount;
- float txPerSec = tx / timeInSecs;
-
- //this.csvLogger.debug(String.format("%1$d,%2$d,%3$f,%4$f,%5$d", threadCount, average, txPerSec, timeInSecs, tx));
- }*/
- }
-
/**
* The implementing method has to fulfil the contract that before the method
* completes all threads will have finished their work.
@@ -131,6 +138,10 @@
@Override
public void execute(Runnable command)
{
+ if (logger.isDebugEnabled())
+ {
+ logger.debug("Starting worker thread.");
+ }
Thread job = new Thread(command);
job.start();
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/ConcurrentTaskConfiguration.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/ConcurrentTaskConfiguration.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/ConcurrentTaskConfiguration.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -12,8 +12,10 @@
{
private final int iterationCount;
private final boolean isOptionalWriteEnabled;
+ @SuppressWarnings("unchecked")
private final Stack NDCstack;
private final MultithreadedTestConfiguration testConfiguration;
+ @SuppressWarnings("unchecked")
public ConcurrentTaskConfiguration( final int iterations,
final boolean isOptionalWEnabled, final Stack stack, final MultithreadedTestConfiguration testConf)
{
@@ -34,6 +36,7 @@
{
return isOptionalWriteEnabled;
}
+ @SuppressWarnings("unchecked")
public Stack getNDCstack()
{
return NDCstack;
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/JPAConfiguration.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/JPAConfiguration.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/configuration/JPAConfiguration.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -23,8 +23,9 @@
private final UserTransaction userTransaction;
private final ConnectionHandler connectionHandler;
+ @SuppressWarnings("unchecked")
public JPAConfiguration(final ConnectionHandler handler, final UserTransaction userT ,final EntityManagerFactory sFactoryA, final EntityManagerFactory sFactoryB, final int iterations,
- final boolean isOptionalWEnabled, final Stack stack, final MultithreadedTestConfiguration testConf)
+ final boolean isOptionalWEnabled, final Stack stack, final MultithreadedTestConfiguration testConf/*, final DataSource dsA, final DataSource dsB*/)
{
super(iterations, isOptionalWEnabled, stack, testConf);
this.entityManagerFactoryA = sFactoryA;
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTest.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTest.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -22,18 +22,24 @@
package org.jboss.jbossts.performance.jdbc;
+import java.lang.reflect.Constructor;
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
import org.apache.log4j.NDC;
import org.jboss.jbossts.performance.MultiThreadedTest;
import org.jboss.jbossts.performance.configuration.JPAConfiguration;
import org.jboss.jbossts.performance.configuration.MultithreadedTestConfiguration;
-import org.jboss.jbossts.performance.task.pooling.PooledConnectionHandler;
+import org.jboss.jbossts.performance.task.pooling.ConnectionHandler;
public class HibernateNativeTest extends MultiThreadedTest
{
@Override
public Runnable getTask(final MultithreadedTestConfiguration taskConfiguration) throws Exception
{
- return new HibernateNativeTask(new JPAConfiguration(new PooledConnectionHandler(getDataSourceA(), getDataSourceB()), getUserTransaction(), getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration));
+ Constructor<ConnectionHandler> handlerConstructor = taskConfiguration.getConnectionHandlerClass().getConstructor(DataSource.class, DataSource.class, TransactionManager.class );
+ return new HibernateNativeTask(new JPAConfiguration(handlerConstructor.newInstance (getDataSourceA(), getDataSourceB(), getTransactionManager()), getUserTransaction(), getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration));
}
@Override
protected boolean isMultiResourceTest()
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -28,6 +28,7 @@
import java.sql.SQLException;
import org.apache.commons.dbutils.DbUtils;
+import org.apache.log4j.Logger;
import org.jboss.jbossts.performance.configuration.JPAConfiguration;
import org.jboss.jbossts.performance.task.RecursiveTask;
import org.testng.Assert;
@@ -35,13 +36,17 @@
/**
*
* This object performs a read and write on two resources using native SQL. The
- * sql query uses the EntityManager to execute the query.
+ * sql query uses the EntityManager to execute the query.
+ * This code can be executed using local-tx or xa transactions
+ * without changes.
*
* @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
* @version $Revision: 1.1 $
*/
public class JDBCTask extends RecursiveTask
{
+ private Logger logger = Logger.getLogger(JDBCTask.class);
+
public JDBCTask(final JPAConfiguration taskConfiguration)
{
super(taskConfiguration);
@@ -67,11 +72,9 @@
{
getTaskConfiguration().getUserTransaction().begin();
connectionA = getTaskConfiguration().getConnectionHandler().getConnectionA();
- //pStatementARead = connectionA.prepareStatement("select user0_.USER_ID , user0_.CREATED , user0_.DEFAULT_BILLING_DETAILS_ID , user0_.EMAIL , user0_.FIRSTNAME , user0_.HOME_CITY , user0_.HOME_STREET as HOME6_4_1_, user0_.HOME_ZIPCODE , user0_.LASTNAME , user0_.PASSWD , user0_.RANK , user0_.USERNAME , user0_.OBJ_VERSION , user0_1_.CITY , user0_1_.STREET , user0_1_.ZIPCODE , addressent1_.ADDRESS_ID , addressent1_.CITY , addressent1_.STREET , addressent1_.OBJ_VERSION , addressent1_.ZIPCODE from USERS user0_ left outer join BILLING_ADDRESS user0_1_ on user0_.USER_ID=user0_1_.USER_ID left outer join ADDRESS addressent1_ on user0_.USER_ID=addressent1_.ADDRESS_ID where user0_.USER_ID=?");
pStatementARead = connectionA.prepareStatement("SELECT USER_ID , OBJ_VERSION FROM USERS WHERE USER_ID=?");
resultA = findUsingResourceA(pStatementARead, this.getTaskConfiguration().getTestConfiguration().getThreadIdentity());
Assert.assertTrue(resultA.next());
- //int version = resultA.getInt(13);
int version = resultA.getInt(2);
if (this.isOptionalWriteEnabled)
@@ -93,17 +96,18 @@
try
{
connectionB= getTaskConfiguration().getConnectionHandler().getConnectionB();
- //pStatementBRead = connectionB.prepareStatement("select user0_.USER_ID , user0_.CREATED , user0_.DEFAULT_BILLING_DETAILS_ID , user0_.EMAIL , user0_.FIRSTNAME , user0_.HOME_CITY , user0_.HOME_STREET as HOME6_4_1_, user0_.HOME_ZIPCODE , user0_.LASTNAME , user0_.PASSWD , user0_.RANK , user0_.USERNAME , user0_.OBJ_VERSION , user0_1_.CITY , user0_1_.STREET , user0_1_.ZIPCODE , addressent1_.ADDRESS_ID , addressent1_.CITY , addressent1_.STREET , addressent1_.OBJ_VERSION , addressent1_.ZIPCODE from USERS user0_ left outer join BILLING_ADDRESS user0_1_ on user0_.USER_ID=user0_1_.USER_ID left outer join ADDRESS addressent1_ on user0_.USER_ID=addressent1_.ADDRESS_ID where user0_.USER_ID=?");
pStatementBRead = connectionB.prepareStatement("SELECT USER_ID, OBJ_VERSION FROM USERS WHERE USER_ID=?");
resultB = findUsingResourceB(pStatementBRead, this.getTaskConfiguration().getTestConfiguration().getThreadIdentity());
Assert.assertTrue(resultB.next());
- //int version = resultB.getInt(13);
int version = resultB.getInt(2);
pStatementBWrite = connectionB.prepareStatement("update USERS set FIRSTNAME=?, OBJ_VERSION=? where USER_ID=? and OBJ_VERSION=?");
writeUsingResourceB(pStatementBWrite, time, version);
completed = true;
}
+ catch (Exception e) {
+ logger.error(e.getMessage(), e);
+ }
finally
{
DbUtils.closeQuietly(resultB);
@@ -122,6 +126,7 @@
else
{
getTaskConfiguration().getUserTransaction().rollback();
+ Assert.fail("The test case had a problem and the transaction was rolled back.");
}
}
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTest.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTest.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -25,6 +25,7 @@
import java.lang.reflect.Constructor;
import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
import org.apache.log4j.NDC;
import org.jboss.jbossts.performance.MultiThreadedTest;
@@ -43,8 +44,8 @@
@Override
public Runnable getTask(final MultithreadedTestConfiguration taskConfiguration) throws Exception
{
- Constructor<ConnectionHandler> handlerConstructor = taskConfiguration.getConnectionHandlerClass().getConstructor(DataSource.class, DataSource.class );
- return new JDBCTask(new JPAConfiguration(handlerConstructor.newInstance (getDataSourceA(), getDataSourceB()), getUserTransactionA(), getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration));
+ Constructor<ConnectionHandler> handlerConstructor = taskConfiguration.getConnectionHandlerClass().getConstructor(DataSource.class, DataSource.class, TransactionManager.class );
+ return new JDBCTask(new JPAConfiguration(handlerConstructor.newInstance (getDataSourceA(), getDataSourceB(), getTransactionManager()), getUserTransactionA(), getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration));
}
@Override
protected boolean isMultiResourceTest()
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeResourcesTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeResourcesTest.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeResourcesTest.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -22,11 +22,16 @@
package org.jboss.jbossts.performance.resource;
+import java.lang.reflect.Constructor;
+
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+
import org.apache.log4j.NDC;
import org.jboss.jbossts.performance.MultiThreadedTest;
import org.jboss.jbossts.performance.configuration.JPAConfiguration;
import org.jboss.jbossts.performance.configuration.MultithreadedTestConfiguration;
-import org.jboss.jbossts.performance.task.pooling.PooledConnectionHandler;
+import org.jboss.jbossts.performance.task.pooling.ConnectionHandler;
/**
* This is in all intents and purposes has ended up being a factory.
@@ -39,7 +44,8 @@
public Runnable getTask(final MultithreadedTestConfiguration taskConfiguration)
throws Exception
{
- return new SynchronizeTask(new JPAConfiguration(new PooledConnectionHandler(getDataSourceA(), getDataSourceB()), getUserTransaction(), getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration));
+ Constructor<ConnectionHandler> handlerConstructor = taskConfiguration.getConnectionHandlerClass().getConstructor(DataSource.class, DataSource.class, TransactionManager.class );
+ return new SynchronizeTask(new JPAConfiguration(handlerConstructor.newInstance (getDataSourceA(), getDataSourceB(), getTransactionManager()), getUserTransaction(), getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration));
}
@Override
protected boolean isMultiResourceTest()
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -1,12 +1,10 @@
package org.jboss.jbossts.performance.resource;
import javax.persistence.EntityManager;
-import javax.persistence.Query;
import org.hibernate.Transaction;
import org.hibernate.ejb.EntityManagerImpl;
import org.jboss.jbossts.performance.configuration.JPAConfiguration;
-import org.jboss.jbossts.performance.synchronization.SessionSynchronization;
import org.jboss.jbossts.performance.task.RecursiveTask;
import org.jboss.tm.TransactionLocal;
import org.testng.Assert;
@@ -49,8 +47,10 @@
/* emA automatically has a synch established because it is associated with the em factory A.
* Whereas emB isn't and therefore the EM persistence context for B needs a synch added to
- * flush updates. */
- transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
+ * flush updates.
+ * This has been removed to allow a flush on emB. This allows the update duration to be
+ * separated from the commit.*/
+// transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
/**
* A read
@@ -69,7 +69,7 @@
final User userA = findUsingResourceA(userDAO_A);
Assert.assertNotNull(userA, String.format( "User A should not be null.[%1$d][%2$d]", this.getTaskConfiguration().getTestConfiguration().getThreadIdentity(), iteration));
-
+
if (this.isOptionalWriteEnabled)
{
userA.setFirstname(name);
@@ -81,17 +81,19 @@
Assert.assertNotNull(userB, "The userB object was null.");
userB.setFirstname(name);
emB.merge(userB);
- /*Need to flush here to avoid profiling on the class SessionImpl. Otherwise the
- * profiler generates Mb of profiling data not needed including all methods of
- * SessionImpl.*/
+ /*Need to flush here to avoid profiling on the class SessionImpl. */
resourceAFlush(emA);
+ resourceBFlush(emB);
/* want to detatch the entities in emA persistence context to avoid
* expensive flush later. */
emA.clear();
+ emB.clear();
- /* the commit call will cause hibernate to check for changes to entities,
- * flushing any changes in the queue (write behind) before commit. At this
+ /* The write behind behaviour of hibernate should not be occuring
+ * in the commit as is the usual case. Both entities have been flushed
+ * beforehand.
+ * At this
* point only EM B's persistence context has any pending writes. */
transaction.commit();
}
@@ -103,6 +105,10 @@
{
entityManager.flush();
}
+ private void resourceBFlush(EntityManager entityManager)
+ {
+ entityManager.flush();
+ }
private User findUsingResourceA(UserDAOBeanMultiResource daoBean)
{
return daoBean.findById(this.getTaskConfiguration().getTestConfiguration().getThreadIdentity(), false);
@@ -112,17 +118,5 @@
return daoBean.findById(this.getTaskConfiguration().getTestConfiguration().getThreadIdentity(), false);
}
- private void writeUserA(final EntityManager em, final String sql)
- {
- performWrite(em, sql);
- }
- private void writeUserB(final EntityManager em, final String sql)
- {
- performWrite(em, sql);
- }
- private void performWrite(final EntityManager em, final String sql)
- {
- Query query = em.createNativeQuery(sql);
- Assert.assertEquals(1, query.executeUpdate(), "The expected modification count was not 1.") ;
- }
+
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/RecursiveTask.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/RecursiveTask.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/RecursiveTask.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -22,7 +22,6 @@
package org.jboss.jbossts.performance.task;
-import java.sql.SQLException;
import java.util.Stack;
import org.apache.commons.dbutils.DbUtils;
@@ -45,6 +44,7 @@
protected final boolean isOptionalWriteEnabled;
private final int recurseCount;
private final static Logger logger = Logger.getLogger(SynchronizeTask.class);
+ @SuppressWarnings("unchecked")
private final Stack parentNDC;
private final JPAConfiguration taskConfiguration;
public RecursiveTask(final JPAConfiguration configuration)
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/CachedConnection.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -26,31 +26,28 @@
import java.sql.SQLException;
import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
-import org.apache.log4j.Logger;
-
/**
- * This object provides Connection objects using lazy loading. This
- * is necessary to ensure the Connection objects are loaded in
- * separate threads just before demand.
+ * This object provides the connection handling to be changed. It
+ * is intended for use with local-tx transactions.
+ * This implementation intecepts the call to close a connection and
+ * does not pass it through. Which allows the connection to be
+ * used again in the same thread.
+ * This is highly specfic to the use case of caching a connection and
+ * is not appropriate when using a managed environment/application
+ * server. This implementation stops pooling from working and will
+ * prevent connection sharing.
*
* @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
* @version $Revision: 1.1 $
*/
public class CachedConnection implements ConnectionHandler
{
- private final DataSource resA;
+ protected final DataSource resA;
+ protected final DataSource resB;
- private final DataSource resB;
-
- protected Connection connectionA;
-
- protected Connection connectionB;
-
- private final Logger logger = Logger.getLogger(CachedConnection.class);
-
-
- public CachedConnection(final DataSource dataSourceA, final DataSource dataSourceB)
+ public CachedConnection(final DataSource dataSourceA, final DataSource dataSourceB, final TransactionManager tm)
{
this.resA = dataSourceA;
this.resB = dataSourceB;
@@ -58,36 +55,32 @@
/**
* Retrieve a Connection from the first resource.
+ * This implementation ignores any doEnlist parameter values.
*/
@Override
public Connection getConnectionA() throws SQLException
{
- if (null == connectionA)
- {
- this.connectionA = resA.getConnection();
- }
-
- return this.connectionA;
+ return resA.getConnection();
}
+ /**
+ * Retrieve a Connection from the second resource.
+ * This implementation ignores any doEnlist parameter values.
+ */
@Override
public Connection getConnectionB() throws SQLException
{
- if (null == connectionB)
- {
- this.connectionB = this.resB.getConnection();
- }
- return this.connectionB;
+ return this.resB.getConnection();
}
/**
- * Fake closing the connection.
+ * NOOP the behaviour for closing the connection.
*/
@Override
public Connection closeQuietly(Connection conn) throws SQLException
{
- /* This method is a NOOP. The intention is not to release the
- * connection back to the pool but to retain it open instead.*/
+ /* This method is a NOOP. The intention is to keep the connection
+ * open which stops the JCA pooling allocating the connection again.*/
return conn;
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/ConnectionHandler.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -33,7 +33,23 @@
*/
public interface ConnectionHandler
{
+ /**
+ * Call this method to obtain a Connection object from the first
+ * resource.
+ *
+ * @param doEnlist
+ * @return
+ * @throws SQLException
+ */
public Connection getConnectionA() throws SQLException;
+ /**
+ * Call this method to obtain a Connection object from the second
+ * resource.
+ *
+ * @param doEnlist
+ * @return
+ * @throws SQLException
+ */
public Connection getConnectionB() throws SQLException;
public Connection closeQuietly(Connection conn) throws SQLException;
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java 2010-04-23 17:54:58 UTC (rev 32621)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/PooledConnectionHandler.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -26,13 +26,14 @@
import java.sql.SQLException;
import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
import org.apache.commons.dbutils.DbUtils;
/**
* A PooledConnectionHandler to allocate Connection objects from the
* underlying JCA. It does not change the pooling behaviour in any
- * way.
+ * way.
*
* @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
* @version $Revision: 1.1 $
@@ -42,12 +43,16 @@
private final DataSource dataSourceA;
private final DataSource dataSourceB;
- public PooledConnectionHandler(DataSource resA, DataSource resB)
+ public PooledConnectionHandler(DataSource resA, DataSource resB, TransactionManager tm)
{
this.dataSourceA = resA;
this.dataSourceB = resB;
}
+ /**
+ * Get a connection.
+ * Parameters are ignored.
+ */
@Override
public Connection getConnectionA()
throws SQLException
@@ -55,6 +60,10 @@
return this.dataSourceA.getConnection();
}
+ /**
+ * Get a connection.
+ * Parameters are ignored.
+ */
@Override
public Connection getConnectionB()
throws SQLException
Added: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/XACachedConnection.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/XACachedConnection.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/task/pooling/XACachedConnection.java 2010-04-23 17:56:21 UTC (rev 32622)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jbossts.performance.task.pooling;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+import javax.transaction.SystemException;
+import javax.transaction.Transaction;
+import javax.transaction.TransactionManager;
+import javax.transaction.xa.XAResource;
+
+import org.apache.log4j.Logger;
+import org.jboss.jbossts.performance.xa.managed.XAWrappedConnection;
+
+/**
+ *
+ * This object is responsible for demarcating the transaction boundary.
+ * This should be used for xa transactions.
+ * Typically this is performed by an EJB container. This object uses
+ * the calls to getConnection and close to enlist and delist a connection
+ * to transaction association using the XAResource.
+ *
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class XACachedConnection extends CachedConnection
+{
+ /**
+ * Logging object
+ */
+ private Logger logger = Logger.getLogger(XACachedConnection.class);
+
+ /**
+ * Reference to the transaction manager used for handling transaction
+ * demarcation.
+ */
+ private TransactionManager transManager;
+
+ public XACachedConnection(final DataSource dataSourceA, final DataSource dataSourceB, final TransactionManager tm)
+ {
+ super(dataSourceA, dataSourceB, tm);
+ this.transManager = tm;
+ }
+
+ @Override
+ public Connection closeQuietly(Connection conn) throws SQLException
+ {
+ /**
+ * Here the connection is delisted from the transaction.
+ */
+ if (null != conn)
+ {
+ try
+ {
+ XAWrappedConnection xaConn = (XAWrappedConnection)conn;
+ Transaction transaction = this.transManager.getTransaction();
+ if (null != transaction && null != conn && null != xaConn.getXAResource())
+ {
+ if (!transaction.delistResource(xaConn.getManagedConnection(), XAResource.TMSUCCESS))
+ {
+ throw new SQLException("Failed to delist connection.");
+ }
+ }
+ }
+ catch (SystemException se)
+ {
+ logger.error(se.getMessage());
+ throw new SQLException(se);
+ }
+ }
+ return conn;
+ }
+
+ @Override
+ public Connection getConnectionA() throws SQLException
+ {
+ Connection returnValue = super.getConnectionA();
+// if (1 == doEnlist.length && doEnlist[0])
+// {
+// enlist((XAWrappedConnection) returnValue);
+// }
+ return returnValue;
+ }
+
+ @Override
+ public Connection getConnectionB() throws SQLException
+ {
+ Connection returnValue = super.getConnectionB();
+// if (1 == doEnlist.length && doEnlist[0])
+// {
+// enlist((XAWrappedConnection) returnValue);
+// }
+ return returnValue;
+ }
+
+// @SuppressWarnings("unused")
+// private void enlist(XAWrappedConnection xaConn) throws SQLException
+// {
+// /**
+// * Enlist the connection with the transation.
+// */
+// try
+// {
+// if (null != this.transManager.getTransaction() && null != xaConn && null != xaConn.getXAResource())
+// {
+// if (!this.transManager.getTransaction().enlistResource(xaConn.getManagedConnection()))
+// {
+// throw new SQLException("Failed to enlist connection.");
+// }
+// }
+// }
+// catch (SystemException se)
+// {
+// logger.error(se.getMessage());
+// throw new SQLException(se);
+// }
+// catch (RollbackException re)
+// {
+// logger.error(re.getMessage());
+// throw new SQLException(re);
+// }
+// }
+}
More information about the jboss-svn-commits
mailing list