[jboss-svn-commits] JBL Code SVN: r30460 - in labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance: resource and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Dec 3 12:01:43 EST 2009


Author: whitingjr
Date: 2009-12-03 12:01:43 -0500 (Thu, 03 Dec 2009)
New Revision: 30460

Added:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java
Log:
New test case to run multiple resources.

Added: 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	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/MultiResourceTest.java	2009-12-03 17:01:43 UTC (rev 30460)
@@ -0,0 +1,105 @@
+ /*
+  * 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.ejb.EntityManagerImpl;
+import org.jboss.jbossts.performance.WarmedUpTest;
+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();
+         emA.getSession().beginTransaction();
+         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); 
+   
+         if (this.isOptionalWriteEnabled)
+         {
+            user.setFirstname("Ben");
+            userDAO_A.makePersistent(user);
+         }
+         // Don't forget to take the return value, this is basically a merge()
+         userDAO_B.makePersistent(user);
+         
+         emA.getSession().getTransaction().commit();
+         Assert.assertFalse(emA.getSession().getTransaction().isActive());
+          
+      }
+      catch (HibernateException e) {
+         Assert.fail(e.getMessage());
+      }
+      catch (PersistenceException pe)
+      {
+         Assert.fail(pe.getMessage());         
+      }
+      finally 
+      {
+         try
+         {
+            if (null != emA)
+            {
+               emA.close();
+            }
+         } 
+         finally {}
+         try
+         {
+            if (null != emB)
+            {
+               emB.close();
+            }
+         }
+         finally {}
+      }
+   }
+
+}



More information about the jboss-svn-commits mailing list