[jboss-svn-commits] JBL Code SVN: r30545 - in labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java: org/jboss/jbossts/performance and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Dec 8 12:28:39 EST 2009
Author: whitingjr
Date: 2009-12-08 12:28:38 -0500 (Tue, 08 Dec 2009)
New Revision: 30545
Added:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiResourceTest.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeResourcesTest.java
Removed:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/TestReadOnly.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java
Modified:
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/auction/test/basic/ProfiledStateTransitions.java
labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java
Log:
Refactored codebase to support blended datasources.
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/auction/test/basic/ProfiledStateTransitions.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/auction/test/basic/ProfiledStateTransitions.java 2009-12-08 17:28:02 UTC (rev 30544)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/auction/test/basic/ProfiledStateTransitions.java 2009-12-08 17:28:38 UTC (rev 30545)
@@ -42,7 +42,6 @@
import javax.xml.xpath.XPathException;
import javax.xml.xpath.XPathFactory;
-import org.apache.commons.dbutils.DbUtils;
import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
import org.dbunit.database.DatabaseConfig;
@@ -97,13 +96,14 @@
{@ColumnResult(name = "IP"), @ColumnResult(name = "SID")
})
-public class ProfiledStateTransitions extends EJB3IntegrationTest
+public abstract class ProfiledStateTransitions extends EJB3IntegrationTest
{
private static Logger logger = Logger.getLogger(ProfiledStateTransitions.class);
protected SessionFactory hSessionFactory;
- private AbstractVendorControl vendorController;
+ private AbstractVendorControl vendorControllerA;
+ private AbstractVendorControl vendorControllerB;
protected String SESSION_FACTORY_JNDI_A;
protected String SESSION_FACTORY_JNDI_B;
@@ -111,6 +111,7 @@
protected String JNDI_NAME_USERTX_B;
protected String JNDI_NAME_EMF_B;
protected boolean isOptionalWriteEnabled;
+ private DefaultDataTypeFactory dataTypeFactoryB;
@Override
public void prepareDataSet(String location, String factory) throws Exception
@@ -120,8 +121,8 @@
@BeforeClass(groups = "integration-warmup")
@Parameters
- ({"basedata_location", "datatype_factory", "integrity-constraint"})
- public void prepareDataSet(String location, String factory, String constraint) throws Exception
+ ({"basedata_location", "datatype_factory_A", "datatype_factory_B", "integrity_constraint_A", "integrity_constraint_B"})
+ public void prepareDataSet(String location, String factoryA, String factoryB, String constraintA, String constraintB) throws Exception
{
// Check if subclass has prepared everything
prepareSettings();
@@ -134,24 +135,43 @@
dataSet = new ReplacementDataSet(new FlatXmlDataSet(input));
dataSet.addReplacementObject("[NULL]", null);
- if (null != factory && !"".equals(factory.trim()))
+ Set<String> tableNames = getTableNames(location);
+
+ this.datatypeFactory = configureDataTypeFactory(factoryA);
+ this.vendorControllerA = configureVendorControlClass(constraintA, tableNames);
+ if (isMultiResourceTest())
{
- this.datatypeFactory = (DefaultDataTypeFactory) Class.forName(factory).newInstance();
+ this.dataTypeFactoryB = configureDataTypeFactory(factoryB);
+ this.vendorControllerB = configureVendorControlClass(constraintB, tableNames);
}
-
- if (null != constraint && !"".equals(constraint.trim()))
+ }
+ private DefaultDataTypeFactory configureDataTypeFactory( String type) throws Exception
+ {
+ DefaultDataTypeFactory returnValue = null;
+ if (null != type && !"".equals(type.trim()))
{
- AbstractVendorControl abconstraint = (AbstractVendorControl) Class.forName(constraint).newInstance();
- abconstraint.setTableNames(getTableNames(location));
- this.vendorController = abconstraint;
+ returnValue = (DefaultDataTypeFactory) Class.forName(type).newInstance();
}
+ return returnValue;
}
+ private AbstractVendorControl configureVendorControlClass(String type, Set tableNames)
+ throws Exception
+ {
+ AbstractVendorControl returnValue = null;
+
+ if (null != type && !"".equals(type.trim()))
+ {
+ returnValue = (AbstractVendorControl) Class.forName(type).newInstance();
+ returnValue.setTableNames(tableNames);
+ }
+ return returnValue;
+ }
- private SessionFactory getSessionFactoryA()
+ protected SessionFactory getSessionFactoryA()
{
return getSessionFactory(SESSION_FACTORY_JNDI_A);
}
- private SessionFactory getSessionFactoryB()
+ protected SessionFactory getSessionFactoryB()
{
return getSessionFactory(SESSION_FACTORY_JNDI_B);
}
@@ -190,7 +210,7 @@
}
- private IDatabaseConnection getConnection(String jndiDataSource) throws Exception
+ private IDatabaseConnection getConnection(String jndiDataSource, DefaultDataTypeFactory factory) throws Exception
{
// Get a JDBC connection from JNDI datasource
@@ -202,18 +222,18 @@
if (null != this.datatypeFactory)
{
DatabaseConfig config = dbUnitCon.getConfig();
- config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, this.datatypeFactory);
+ config.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, factory);
}
return dbUnitCon;
}
protected IDatabaseConnection getConnectionA() throws Exception
{
- return this.getConnection(this.JNDI_DATASOURCE);
+ return this.getConnection(this.JNDI_DATASOURCE, this.datatypeFactory);
}
protected IDatabaseConnection getConnectionB() throws Exception
{
- return this.getConnection(this.JNDI_DATASOURCE_B);
+ return this.getConnection(this.JNDI_DATASOURCE_B, this.dataTypeFactoryB);
}
protected void prepareSettings()
@@ -221,17 +241,6 @@
beforeTestOperations.add(DatabaseOperation.CLEAN_INSERT);
}
- /*
- @BeforeGroups(groups = "integration-warmup")
- @Parameters(
- {"session_jndi"})
- public void prepareParameters(String jndiSessionFactory) throws Exception
- {
- logger.debug("Setting Hibernate SessionFactory JNDI");
- this.SESSION_FACTORY_JNDI = jndiSessionFactory;
- }
- */
-
@Override
public void startContainer(String deployBeansXml, String scanClasspath, String jndiDatasource, String jndiNameEMF,
String jndiNameUserTx) throws Exception
@@ -282,11 +291,14 @@
@Parameters ({"basedata_location"})
public void beforeTestMethod(String basedataLocation) throws Exception
{
- this.beforeTestMethod(basedataLocation, getSessionFactoryA(), getConnectionA());
- this.beforeTestMethod(basedataLocation, getSessionFactoryB(), getConnectionB());
+ this.beforeTestMethod(basedataLocation, getSessionFactoryA(), getConnectionA(), this.vendorControllerA);
+ if (isMultiResourceTest())
+ {
+ this.beforeTestMethod(basedataLocation, getSessionFactoryB(), getConnectionB(), this.vendorControllerB);
+ }
}
- private void beforeTestMethod(String basedataLocation, SessionFactory hSessionFactory, IDatabaseConnection iDatabaseConn) throws Exception
+ private void beforeTestMethod(String basedataLocation, SessionFactory hSessionFactory, IDatabaseConnection iDatabaseConn, AbstractVendorControl controller) throws Exception
{
SessionFactoryImpl sessionFactory = (SessionFactoryImpl) hSessionFactory;
Configuration configuration = null;
@@ -295,60 +307,29 @@
Connection connection = iDatabaseConn.getConnection();
try
{
- if (null != this.vendorController)
+ if (null != controller)
{
- //connectionConstraintModify
- if (this.vendorController.isDisablePreferedOverDrop())
+ if (controller.isDisablePreferedOverDrop())
{
- this.vendorController.relax(connection);
+ controller.relax(connection);
}
else
{
configuration = getConfiguration();
dropStatements = configuration.generateDropSchemaScript(sessionFactory.getDialect());
- this.vendorController.relax(connection, dropStatements);
+ controller.relax(connection, dropStatements);
}
- this.vendorController.purge(connection);
- }
- }
- catch (SQLException sqle)
- {
- logger.error(sqle.getMessage(), sqle);
- }
- finally
- {
- /*DbUtils.closeQuietly(connectionConstraintModify );
- connectionConstraintModify = null;*/
- }
+ controller.purge(connection);
- for (DatabaseOperation op : beforeTestOperations )
- {
- //Connection connection = null;
- try
- {
- //connection = iDatabaseConn.getConnection();
- op.execute(iDatabaseConn , dataSet);
- }
- catch (SQLException sqle)
- {
- logger.error(sqle);
- }
- finally
- {
- //DbUtils.closeQuietly(connection);
- }
- }
-
- try
- {
- //connectionConstraintModify = iDatabaseConn.getConnection();
- if (null != this.vendorController)
- {
- if (this.vendorController.isDisablePreferedOverDrop())
+ for (DatabaseOperation op : beforeTestOperations )
{
- this.vendorController.constrain (connection);
+ op.execute(iDatabaseConn , dataSet);
}
+ if (controller.isDisablePreferedOverDrop())
+ {
+ controller.constrain (connection);
+ }
else
{
DatabaseMetadata metadata= new DatabaseMetadata(connection, sessionFactory.getDialect());
@@ -357,7 +338,7 @@
configuration.setProperty( Environment.TRANSACTION_STRATEGY, sessionFactory.getSettings().getTransactionFactory().getClass().getName());
configuration.setProperty( Environment.TRANSACTION_MANAGER_STRATEGY , sessionFactory.getSettings().getTransactionManagerLookup().getClass().getName());
String[] constrainStatements = configuration.generateSchemaUpdateScript(sessionFactory.getDialect(), metadata);
- this.vendorController.constrain (connection,constrainStatements);
+ controller.constrain (connection,constrainStatements);
}
}
}
@@ -367,41 +348,48 @@
}
finally
{
- //DbUtils.closeQuietly(connectionConstraintModify );
+ try
+ {
+ connection.close();
+ }
+ catch (SQLException sqle)
+ {
+ Assert.fail(sqle.getMessage(), sqle);
+ }
}
- try
- {
- connection.close();
- }
- catch (SQLException sqle)
- {
- Assert.fail(sqle.getMessage(), sqle);
- }
}
@Override
@AfterGroups(groups = "integration-persistence")
public void afterTestMethod() throws Exception
{
+ cleanTables(getConnectionA());
+ if (isMultiResourceTest())
+ {
+ cleanTables(getConnectionB());
+ }
+ }
+
+ private void cleanTables( IDatabaseConnection iDBconnetion)
+ throws Exception
+ {
for (DatabaseOperation op : afterTestOperations)
{
- IDatabaseConnection connection = null;
- try
+ try
+ {
+ op.execute(iDBconnetion, dataSet);
+ }
+ catch (SQLException sqle)
+ {
+ logger.error(sqle);
+ }
+ finally
+ {
+ if (null != iDBconnetion && null != iDBconnetion.getConnection())
{
- connection= getConnection();
- op.execute(connection, dataSet);
+ iDBconnetion.getConnection();
}
- catch (SQLException sqle)
- {
- logger.error(sqle);
- }
- finally
- {
- if (null != connection)
- {
- connection.getConnection().close();
- }
- }
+ }
}
}
@@ -421,7 +409,6 @@
Object result = xpath.evaluate ("/dataset/*", new InputSource(iStream), XPathConstants.NODESET);
- //TODO: test what happens when result tree == 1, is a Node interface returned instead
NodeList resultTree = (NodeList)result;
logger.trace("Size of element list ["+resultTree.getLength()+"]");
for (int position = 0 ; position < resultTree.getLength() ; position += 1)
@@ -474,6 +461,10 @@
protected EntityManagerFactory getEntityManagerFactoryB() throws Exception{
return (EntityManagerFactory)jndi.lookup(JNDI_NAME_EMF_B);
}
+
+ abstract protected boolean isMultiResourceTest();
+
+
}
Copied: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiResourceTest.java (from rev 30530, labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java)
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiResourceTest.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiResourceTest.java 2009-12-08 17:28:38 UTC (rev 30545)
@@ -0,0 +1,68 @@
+ /*
+ * 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;
+
+import javax.persistence.EntityManager;
+import javax.transaction.Synchronization;
+
+import org.apache.log4j.Logger;
+import org.hibernate.Transaction;
+
+
+
+public abstract class MultiResourceTest extends WarmedUpTest
+{
+
+ protected static class SessionSynchronization implements Synchronization
+ {
+ private static final Logger logger = Logger.getLogger(SessionSynchronization.class);
+ private EntityManager manager;
+ private boolean closeAtTxCompletion;
+
+ public SessionSynchronization(EntityManager session, Transaction tx, boolean close)
+ {
+ this.manager = session;
+ closeAtTxCompletion = close;
+ }
+
+ public void beforeCompletion()
+ {
+ }
+
+ public void afterCompletion(int status)
+ {
+ if (closeAtTxCompletion)
+ {
+ logger.debug("************** closing entity managersession **************");
+ manager.close();
+ }
+ }
+ }
+
+ @Override
+ protected boolean isMultiResourceTest()
+ {
+ return true;
+ }
+}
+
Modified: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java 2009-12-08 17:28:02 UTC (rev 30544)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/JPAExampleTests.java 2009-12-08 17:28:38 UTC (rev 30545)
@@ -189,5 +189,10 @@
}
}
}
+ @Override
+ protected boolean isMultiResourceTest()
+ {
+ return false;
+ }
}
Deleted: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/TestReadOnly.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/TestReadOnly.java 2009-12-08 17:28:02 UTC (rev 30544)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/readonly/TestReadOnly.java 2009-12-08 17:28:38 UTC (rev 30545)
@@ -1,145 +0,0 @@
- /*
- * 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.readonly;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.Calendar;
-import java.util.Currency;
-import java.util.GregorianCalendar;
-
-import javax.persistence.EntityManager;
-
-import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.Transaction;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import auction.dao.ItemDAO;
-import auction.dao.UserDAO;
-import auction.dao.ejb3.GenericEJB3DAO;
-import auction.dao.ejb3.ItemDAOBean;
-import auction.dao.ejb3.UserDAOBean;
-import auction.model.Item;
-import auction.model.MonetaryAmount;
-import auction.model.User;
-import auction.test.basic.ProfiledStateTransitions;
-
-public class TestReadOnly extends ProfiledStateTransitions
-{
- private static final Logger logger = Logger.getLogger(TestReadOnly.class);
- @BeforeClass (groups="integration-persistence")
- public void warmupMethod()
- {
-
- }
- @Test (groups="integration-persistence")
- public void actualTest()
- {
-
- }
-
- /* Test case using Hibernate API and JTA UserTransaction behind the scenes. */
- private void testBody()
- {
- SessionFactory factory = getSessionFactory();
- if (null != factory)
- {
- Session hSession = factory.openSession();
- Transaction hTransaction = null;
- try
- {
- hTransaction = hSession.beginTransaction();
-
- hTransaction.commit();
- }
- catch (HibernateException he)
- {
- logger.error(he.getMessage(), he);
- }
- catch (Exception e)
- {
- logger.error(e.getMessage(), e);
- }
- finally
- {
- hSession.close();
- }
- }
-
- /*
- // Prepare the DAOs (manually, no Seam)
- ItemDAO itemDAO = new ItemDAOBean();
- ((GenericEJB3DAO) itemDAO).setEntityManager(em);
-
- UserDAO userDAO = new UserDAOBean();
- ((GenericEJB3DAO) userDAO).setEntityManager(em);
-
- // Prepare a user object
- User user = userDAO.findById(1l, false);
-
- // Make a new auction item persistent
- Calendar startDate = GregorianCalendar.getInstance();
- Calendar endDate = GregorianCalendar.getInstance();
- endDate.add(Calendar.DAY_OF_YEAR, 3);
-
- MonetaryAmount initialPrice =
- new MonetaryAmount(new BigDecimal(123), Currency.getInstance("USD"));
- MonetaryAmount reservePrice =
- new MonetaryAmount(new BigDecimal(333), Currency.getInstance("USD"));
-
- Item newItem =
- new Item( "Testitem", "Test Description", user,
- initialPrice, reservePrice,
- startDate.getTime(), endDate.getTime() );
-
- // Don't forget to take the return value, this is basically a merge()
- newItem = itemDAO.makePersistent(newItem);
-
- // End the unit of work
- getUserTransaction().commit();
- em.close();
-
- // Direct SQL query for database state in auto-commit mode
- em = getEntityManagerFactory().createEntityManager();
- Object[] result = (Object[])
- em.createNativeQuery(
- "select INITIAL_PRICE as IP," +
- " SELLER_ID as SID from ITEM where ITEM_ID = :itemId")
- .setParameter("itemId", newItem.getId())
- .getSingleResult();
- em.close();
-
-
- // Assert correctness of state
- assert result[0].getClass() == BigDecimal.class;
- assert 0 == ((BigDecimal)result[0]).compareTo( ((newItem.getInitialPrice().getValue())));
- // The SQL resultset mapping returns a BigInteger
- assert result[1].equals(new BigInteger("1"));
- */
- }
-
-}
Deleted: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java 2009-12-08 17:28:02 UTC (rev 30544)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java 2009-12-08 17:28:38 UTC (rev 30545)
@@ -1,129 +0,0 @@
- /*
- * 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.resource;
-
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceException;
-import javax.transaction.Synchronization;
-
-import org.apache.log4j.Logger;
-import org.hibernate.HibernateException;
-import org.hibernate.Transaction;
-import org.hibernate.ejb.EntityManagerImpl;
-import org.jboss.jbossts.performance.WarmedUpTest;
-import org.jboss.tm.TransactionLocal;
-import org.testng.Assert;
-
-import auction.dao.ejb3.persistence.UserDAOBeanMultiResource;
-import auction.model.User;
-
-
-public class MultiResourceTest extends WarmedUpTest
-{
-
- @Override
- protected void runTestBody()
- throws Exception
- {
- EntityManagerImpl emA = null;
- EntityManagerImpl emB = null;
- try
- {
- emA = (EntityManagerImpl) getEntityManagerFactory().createEntityManager();
- emB = (EntityManagerImpl) getEntityManagerFactoryB().createEntityManager();
- Transaction transaction =emA.getSession().beginTransaction();
- TransactionLocal session = new TransactionLocal();
- transaction.registerSynchronization(new SessionSynchronization(emA, transaction, true));
-
- transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
-
- session.set(emB);
- emB.joinTransaction();
-
- /**
- * A read
- * A [write]
- * B write
- */
- UserDAOBeanMultiResource userDAO_A = new UserDAOBeanMultiResource();
- userDAO_A.setEntityManagerA(emA);
- UserDAOBeanMultiResource userDAO_B = new UserDAOBeanMultiResource ();
- userDAO_B.setEntityManagerB(emB);
-
- // Prepare a user object
- User user = userDAO_A.findById(1l, false);
-
- long time = System.currentTimeMillis();
- if (this.isOptionalWriteEnabled)
- {
- user.setFirstname("Ben"+time);
- userDAO_A.makePersistent(user);
- }
- // Don't forget to take the return value, this is basically a merge()
- User userB = userDAO_B.findById(1l, false);
- userB.setFirstname("Ben"+time);
- userDAO_B.makePersistent(userB);
-
- emA.getSession().getTransaction().commit();
- Assert.assertFalse(emA.isOpen());
- Assert.assertFalse(emB.isOpen());
- }
- catch (HibernateException e) {
- Assert.fail(e.getMessage());
- }
- catch (PersistenceException pe)
- {
- Assert.fail(pe.getMessage());
- }
- finally
- {
- }
- }
-
- private static class SessionSynchronization implements Synchronization
- {
- private static final Logger logger = Logger.getLogger(SessionSynchronization.class);
- private EntityManager manager;
- private boolean closeAtTxCompletion;
-
- public SessionSynchronization(EntityManager session, Transaction tx, boolean close)
- {
- this.manager = session;
- closeAtTxCompletion = close;
- }
-
- public void beforeCompletion()
- {
- }
-
- public void afterCompletion(int status)
- {
- if (closeAtTxCompletion)
- {
- logger.debug("************** closing entity managersession **************");
- manager.close();
- }
- }
- }
-
-}
Added: 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 (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeResourcesTest.java 2009-12-08 17:28:38 UTC (rev 30545)
@@ -0,0 +1,99 @@
+ /*
+ * 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.resource;
+
+import javax.persistence.PersistenceException;
+
+import org.hibernate.HibernateException;
+import org.hibernate.Transaction;
+import org.hibernate.ejb.EntityManagerImpl;
+import org.jboss.jbossts.performance.MultiResourceTest;
+import org.jboss.tm.TransactionLocal;
+import org.testng.Assert;
+
+import auction.dao.ejb3.persistence.UserDAOBeanMultiResource;
+import auction.model.User;
+
+public class SynchronizeResourcesTest extends MultiResourceTest
+{
+
+ @Override
+ protected void runTestBody()
+ throws Exception
+ {
+ EntityManagerImpl emA = null;
+ EntityManagerImpl emB = null;
+ try
+ {
+ emA = (EntityManagerImpl) getEntityManagerFactory().createEntityManager();
+ emB = (EntityManagerImpl) getEntityManagerFactoryB().createEntityManager();
+ Transaction transaction =emA.getSession().beginTransaction();
+ TransactionLocal session = new TransactionLocal();
+ transaction.registerSynchronization(new SessionSynchronization(emA, transaction, true));
+
+ transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true ) );
+
+ session.set(emB);
+ emB.joinTransaction();
+
+ /**
+ * A read
+ * A [write]
+ * B write
+ */
+ UserDAOBeanMultiResource userDAO_A = new UserDAOBeanMultiResource();
+ userDAO_A.setEntityManagerA(emA);
+ UserDAOBeanMultiResource userDAO_B = new UserDAOBeanMultiResource ();
+ userDAO_B.setEntityManagerB(emB);
+
+ // Prepare a user object
+ User user = userDAO_A.findById(1l, false);
+
+ long time = System.currentTimeMillis();
+ if (this.isOptionalWriteEnabled)
+ {
+ user.setFirstname("Ben"+time);
+ userDAO_A.makePersistent(user);
+ }
+ // Don't forget to take the return value, this is basically a merge()
+ User userB = userDAO_B.findById(1l, false);
+ userB.setFirstname("Ben"+time);
+ userDAO_B.makePersistent(userB);
+
+ emA.getSession().getTransaction().commit();
+ Assert.assertFalse(emA.isOpen());
+ Assert.assertFalse(emB.isOpen());
+ }
+ catch (HibernateException e) {
+ Assert.fail(e.getMessage());
+ }
+ catch (PersistenceException pe)
+ {
+ Assert.fail(pe.getMessage());
+ }
+ finally
+ {
+ }
+ }
+
+}
More information about the jboss-svn-commits
mailing list