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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Feb 3 04:32:01 EST 2010


Author: whitingjr
Date: 2010-02-03 04:32:00 -0500 (Wed, 03 Feb 2010)
New Revision: 31373

Added:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.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/jdbc/JDBCTest.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java
Log:
Updated classes to include a profiled count.


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-02-03 09:28:17 UTC (rev 31372)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/MultiThreadedTest.java	2010-02-03 09:32:00 UTC (rev 31373)
@@ -9,7 +9,7 @@
 {
    private static final Logger logger = Logger.getLogger(MultiThreadedTest.class);
    @Override
-   public void startConcurrentExecutions(int recurseCount, int threadCount)
+   public void startConcurrentExecutions(int recurseCount, int threadCount, final int profiledCount)
          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-02-03 09:28:17 UTC (rev 31372)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/WarmedUpTest.java	2010-02-03 09:32:00 UTC (rev 31373)
@@ -47,20 +47,20 @@
 
    @Test(groups = "integration-warmup")
    @Parameters(
-   { "warmup_count" , "concurrency_count" })
-   public void warmupTest(final String warmupCountConfig, final String threadCountConfig)
+   { "warmup_count" , "concurrency_count" , "profiled_count"})
+   public void warmupTest(final String warmupCountConfig, final String threadCountConfig, final String profiledCountConfig)
       throws Exception
    {
       NDC.push("warmup");
-      startConcurrentExecutions(Integer.parseInt(warmupCountConfig), Integer.parseInt(threadCountConfig));
+      startConcurrentExecutions(Integer.parseInt(warmupCountConfig), Integer.parseInt(threadCountConfig), Integer.parseInt(profiledCountConfig));
       NDC.remove();
    }
 
    @Test(groups = "integration-persistence", dependsOnGroups = "integration-warmup")
    @Parameters(
-   { "test_count", "concurrency_count" })
+   { "test_count", "concurrency_count", "profiled_count" })
    public void profiledTest(final String testCountConfig,
-         final String concurrentCountConfig)
+         final String concurrentCountConfig, final String profiledCountConfig)
       throws Exception
    {
       NDC.push("profiled");
@@ -71,7 +71,7 @@
       {
          logger.warn(e.getMessage());
       }
-      startConcurrentExecutions(Integer.parseInt(testCountConfig), Integer.parseInt(concurrentCountConfig));
+      startConcurrentExecutions(Integer.parseInt(testCountConfig), Integer.parseInt(concurrentCountConfig), Integer.parseInt(profiledCountConfig));
       try
       {
          getProfiler().stop();
@@ -89,7 +89,7 @@
     * @param threadCount 
     * @throws Exception 
     */
-   public abstract void startConcurrentExecutions(int recurseCount, int threadCount)  throws Exception;
+   public abstract void startConcurrentExecutions(final int recurseCount,final  int threadCount,final int profiledCount)  throws Exception;
    
    public abstract Runnable getTask(int recurseCount, CyclicBarrier completionBarrier, int threadId) throws Exception;
    

Added: 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	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java	2010-02-03 09:32:00 UTC (rev 31373)
@@ -0,0 +1,246 @@
+ /*
+  * 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.jdbc;
+
+import java.util.Stack;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.CyclicBarrier;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
+import javax.transaction.Synchronization;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.NDC;
+import org.hibernate.Transaction;
+import org.hibernate.ejb.EntityManagerImpl;
+import org.jboss.tm.TransactionLocal;
+import org.testng.Assert;
+
+public class JDBCTask implements Runnable
+{
+   private final EntityManagerFactory emfA;
+   private final EntityManagerFactory emfB;
+   private final boolean isOptionalWriteEnabled;
+   private final int recurseCount;
+   private final Logger logger = Logger.getLogger(JDBCTask.class);
+   private final CyclicBarrier completionBarrier;
+   private final Long threadId;
+   private final CountDownLatch latch;
+   private final Stack parentNDC;
+   public JDBCTask(final EntityManagerFactory factoryA, final EntityManagerFactory factoryB, final int count, final CyclicBarrier barrier, final int id, final boolean isWEnabled, Stack stack)
+   {
+      this.emfA = factoryA;
+      this.emfB = factoryB;
+      this.recurseCount = count;
+      this.completionBarrier = barrier;
+      this.threadId = new Long(id);
+      this.isOptionalWriteEnabled = isWEnabled;
+      this.latch = null;
+      this.parentNDC = stack;
+   }
+   
+   public JDBCTask(final EntityManagerFactory factoryA, final EntityManagerFactory factoryB, final int count, final CyclicBarrier barrier, final int id, final boolean isWEnabled, final CountDownLatch countDown, Stack stack)
+   {
+      this.emfA = factoryA;
+      this.emfB = factoryB;
+      this.recurseCount = count;
+      this.completionBarrier = barrier;
+      this.threadId = new Long(id);
+      this.isOptionalWriteEnabled = isWEnabled;
+      this.latch = countDown;
+      this.parentNDC = stack;
+   }
+   
+   
+   @Override
+   public void run()
+   {
+      try
+      {/* use the barrier to wait for all concurrent threads, when finished decrement the latch and fall out of 
+      method. Means the profiler does not 
+      */
+         NDC.inherit(this.parentNDC);
+         NDC.push(this.threadId.toString());
+         this.completionBarrier.await();// await all threads ready to start
+         recurse(this.recurseCount);
+         logger.info("Finished recursing. Awaiting on synch point.");
+
+         if (!this.completionBarrier.isBroken())
+         {// fall out of thread without waiting.
+            this.completionBarrier.await();// await all threads have finished
+         }
+      }
+      catch (Exception e)
+      {
+         logger.error(e.getMessage(), e);
+         this.completionBarrier.reset();
+         Assert.fail(e.getMessage());
+      }
+      catch (AssertionError ae)
+      {
+         this.completionBarrier.reset();
+         throw ae;
+      }
+      finally
+      {
+         NDC.clear();
+      }
+   }
+   
+   /**
+    * Run the test sequentially.
+    * 
+    * @param count
+    */
+   private void recurse(final int count)
+   {
+      for (int i = 1; i <= count; i += 1)
+      {
+         try
+         {
+            task(i);
+            logger.debug("Completed profiled run of testbody for thread ["+this.threadId.toString()+"] count ["+i+"].");
+            
+         } catch (Exception e)
+         {
+            this.completionBarrier.reset();
+            logger.error("Failed profiled run of testbody for thread ["+this.threadId.toString()+"] count ["+i+"].");
+            Assert.fail(e.getMessage(), e);
+         }
+      }
+   }
+   public void task(final int iteration)
+      throws Exception
+   {
+      String readSQL = String.format("select user0_.USER_ID as USER1_4_1_, user0_.CREATED as CREATED4_1_, user0_.DEFAULT_BILLING_DETAILS_ID as DEFAULT13_4_1_, user0_.EMAIL as EMAIL4_1_, user0_.FIRSTNAME as FIRSTNAME4_1_, user0_.HOME_CITY as HOME5_4_1_, user0_.HOME_STREET as HOME6_4_1_, user0_.HOME_ZIPCODE as HOME7_4_1_, user0_.LASTNAME as LASTNAME4_1_, user0_.PASSWD as PASSWD4_1_, user0_.RANK as RANK4_1_, user0_.USERNAME as USERNAME4_1_, user0_.OBJ_VERSION as OBJ12_4_1_, user0_1_.CITY as CITY5_1_, user0_1_.STREET as STREET5_1_, user0_1_.ZIPCODE as ZIPCODE5_1_, addressent1_.ADDRESS_ID as ADDRESS1_2_0_, addressent1_.CITY as CITY2_0_, addressent1_.STREET as STREET2_0_, addressent1_.OBJ_VERSION as OBJ4_2_0_, addressent1_.ZIPCODE as ZIPCODE2_0_ 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=%1$d", this.threadId);
+      
+      EntityManagerImpl emA = null;
+      EntityManagerImpl emB = null;
+      emA = (EntityManagerImpl) getEMFactoryA().createEntityManager();
+      emB = (EntityManagerImpl) getEMFactoryB().createEntityManager();
+      Transaction transaction =emA.getSession().beginTransaction();
+      TransactionLocal session = new TransactionLocal();
+      
+      transaction.registerSynchronization(new SessionSynchronization(emA, transaction, true));
+      transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true  ) );
+      
+      //Object obj = emA.createNamedQuery("findUserById").setParameter("identifier", this.threadId).getSingleResult();
+      session.set(emA);
+      Object[] usrA = (Object[])findUsingResourceA(emA, readSQL);//discard details
+      Number version = (Number ) usrA[12];
+      //logger.debug(usrA.toString());
+      
+      long time = System.currentTimeMillis();
+      String writeSQLResA = String.format("update USERS set DEFAULT_BILLING_DETAILS_ID=%1$d, EMAIL='%2$s', FIRSTNAME='%3$s', HOME_CITY='%4$s', HOME_STREET='%5$s', HOME_ZIPCODE='%6$s', LASTNAME='%7$s', PASSWD='%8$s', RANK=%9$d, USERNAME='%10$s', OBJ_VERSION=%11$d where USER_ID=%12$d and OBJ_VERSION=%13$d", 
+            null, "anotheruser at mail.tld", "Ben"+time, "Foocity", "Foostreet", "22222", "User", "secret", 0, "anotheruser110"+this.threadId, version.intValue()+1, this.threadId, version.intValue());
+      version = null;
+      
+      if (this.isOptionalWriteEnabled)
+      {
+         writeUserA(emA, writeSQLResA);
+      }
+      session.set(emB);
+      Object[] usrB = (Object[])findUsingResourceB(emB, readSQL);//discard details
+      version = (Number) usrB[12];
+      //logger.debug(usrB.toString());
+      String writeSQLResB = String.format("update USERS set DEFAULT_BILLING_DETAILS_ID=%1$d, EMAIL='%2$s', FIRSTNAME='%3$s', HOME_CITY='%4$s', HOME_STREET='%5$s', HOME_ZIPCODE='%6$s', LASTNAME='%7$s', PASSWD='%8$s', RANK=%9$d, USERNAME='%10$s', OBJ_VERSION=%11$d where USER_ID=%12$d and OBJ_VERSION=%13$d", 
+            null, "anotheruser at mail.tld", "Ben"+time, "Foocity", "Foostreet", "22222", "User", "secret", 0, "anotheruser110"+this.threadId, version.intValue()+1, this.threadId, version.intValue());
+      
+      writeUserB(emB, writeSQLResB);
+      //resourceAFlush(emA); flush not necessary
+      //resourceBFlush(emB); flush not necessary
+      emA.getSession().getTransaction().commit();
+      Assert.assertFalse(emA.isOpen());
+   }
+   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()) ;
+   }
+   private void resourceAFlush(EntityManager entityManager)
+   {
+      entityManager.flush();
+   }
+   private void resourceBFlush(EntityManager entityManager)
+   {
+      entityManager.flush();
+   }
+   private Object findUsingResourceA(final EntityManager em, final String sql)
+   {
+      return findUsingResource(em, sql);
+   }
+   private Object findUsingResourceB(final EntityManager em, final String sql)
+   {
+      return findUsingResource(em, sql);
+   }
+   private Object findUsingResource(final EntityManager em, final String sql)
+   {
+      return em.createNativeQuery(sql).getSingleResult();         
+   }
+   
+   public EntityManagerFactory getEMFactoryA()
+   {
+      return this.emfA;
+   }
+   
+   public EntityManagerFactory getEMFactoryB()
+   {
+      return this.emfB;
+   }
+   public class SessionSynchronization implements Synchronization
+   {
+      private 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();
+         }
+      }
+   }
+
+}
\ No newline at end of file

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-02-03 09:28:17 UTC (rev 31372)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTest.java	2010-02-03 09:32:00 UTC (rev 31373)
@@ -22,24 +22,17 @@
 
 package org.jboss.jbossts.performance.jdbc;
 
-import java.util.Stack;
-import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.CyclicBarrier;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.transaction.Synchronization;
-
-import org.apache.log4j.Logger;
 import org.apache.log4j.NDC;
-import org.hibernate.Transaction;
-import org.hibernate.ejb.EntityManagerImpl;
 import org.jboss.jbossts.performance.MultiThreadedTest;
-import org.jboss.tm.TransactionLocal;
-import org.testng.Assert;
 
-import auction.model.User;
-
+/**
+ * This class creates an instance of the underlying task.
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
 public class JDBCTest extends MultiThreadedTest
 {
    @Override
@@ -52,185 +45,4 @@
    {
       return true;
    }
-   
-   public class JDBCTask implements Runnable
-   {
-      private final EntityManagerFactory emfA;
-      private final EntityManagerFactory emfB;
-      private final boolean isOptionalWriteEnabled;
-      private final int recurseCount;
-      private final Logger logger = Logger.getLogger(JDBCTask.class);
-      private final CyclicBarrier completionBarrier;
-      private final Long threadId;
-      private final CountDownLatch latch;
-      private final Stack parentNDC;
-      public JDBCTask(final EntityManagerFactory factoryA, final EntityManagerFactory factoryB, final int count, final CyclicBarrier barrier, final int id, final boolean isWEnabled, Stack stack)
-      {
-         this.emfA = factoryA;
-         this.emfB = factoryB;
-         this.recurseCount = count;
-         this.completionBarrier = barrier;
-         this.threadId = new Long(id);
-         this.isOptionalWriteEnabled = isWEnabled;
-         this.latch = null;
-         this.parentNDC = stack;
-      }
-      
-      public JDBCTask(final EntityManagerFactory factoryA, final EntityManagerFactory factoryB, final int count, final CyclicBarrier barrier, final int id, final boolean isWEnabled, final CountDownLatch countDown, Stack stack)
-      {
-         this.emfA = factoryA;
-         this.emfB = factoryB;
-         this.recurseCount = count;
-         this.completionBarrier = barrier;
-         this.threadId = new Long(id);
-         this.isOptionalWriteEnabled = isWEnabled;
-         this.latch = countDown;
-         this.parentNDC = stack;
-      }
-      
-      
-      @Override
-      public void run()
-      {
-         try
-         {/* use the barrier to wait for all concurrent threads, when finished decrement the latch and fall out of 
-         method. Means the profiler does not 
-         */
-            NDC.inherit(this.parentNDC);
-            NDC.push(this.threadId.toString());
-            this.completionBarrier.await();// await all threads ready to start
-            recurse(this.recurseCount);
-            logger.info("Finished recursing. Awaiting on synch point.");
-
-            if (!this.completionBarrier.isBroken())
-            {// fall out of thread without waiting.
-               this.completionBarrier.await();// await all threads have finished
-            }
-         }
-         catch (Exception e)
-         {
-            logger.error(e.getMessage(), e);
-            this.completionBarrier.reset();
-            Assert.fail(e.getMessage());
-         }
-         catch (AssertionError ae)
-         {
-            this.completionBarrier.reset();
-            throw ae;
-         }
-         finally
-         {
-            NDC.clear();
-         }
-      }
-      
-      /**
-       * Run the test sequentially.
-       * 
-       * @param count
-       */
-      private void recurse(final int count)
-      {
-         for (int i = 0; i < count; i += 1)
-         {
-            try
-            {
-               task(count);
-               logger.debug("Completed profiled run of testbody for thread ["+this.threadId.toString()+"] count ["+i+"].");
-               
-            } catch (Exception e)
-            {
-               this.completionBarrier.reset();
-               logger.error("Failed profiled run of testbody for thread ["+this.threadId.toString()+"] count ["+i+"].");
-               Assert.fail(e.getMessage(), e);
-            }
-         }
-      }
-      public void task(final int iteration)
-         throws Exception
-      {
-         String readSQL = String.format("select user0_.USER_ID as USER1_4_1_, user0_.CREATED as CREATED4_1_, user0_.DEFAULT_BILLING_DETAILS_ID as DEFAULT13_4_1_, user0_.EMAIL as EMAIL4_1_, user0_.FIRSTNAME as FIRSTNAME4_1_, user0_.HOME_CITY as HOME5_4_1_, user0_.HOME_STREET as HOME6_4_1_, user0_.HOME_ZIPCODE as HOME7_4_1_, user0_.LASTNAME as LASTNAME4_1_, user0_.PASSWD as PASSWD4_1_, user0_.RANK as RANK4_1_, user0_.USERNAME as USERNAME4_1_, user0_.OBJ_VERSION as OBJ12_4_1_, user0_1_.CITY as CITY5_1_, user0_1_.STREET as STREET5_1_, user0_1_.ZIPCODE as ZIPCODE5_1_, addressent1_.ADDRESS_ID as ADDRESS1_2_0_, addressent1_.CITY as CITY2_0_, addressent1_.STREET as STREET2_0_, addressent1_.OBJ_VERSION as OBJ4_2_0_, addressent1_.ZIPCODE as ZIPCODE2_0_ 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=%1$d", this.threadId);
-         
-         EntityManagerImpl emA = null;
-         EntityManagerImpl emB = null;
-         emA = (EntityManagerImpl) getEMFactoryA().createEntityManager();
-         emB = (EntityManagerImpl) getEMFactoryB().createEntityManager();
-         Transaction transaction =emA.getSession().beginTransaction();
-         TransactionLocal session = new TransactionLocal();
-         
-         transaction.registerSynchronization(new SessionSynchronization(emA, transaction, true));
-         transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true  ) );
-         
-         findUsingResourceA(emA, readSQL);//discard details
-         findUsingResourceB(emA, readSQL);//discard details
-         long time = System.currentTimeMillis();
-         String writeSQLResA = String.format("update USERS set DEFAULT_BILLING_DETAILS_ID=%1$d, EMAIL='%2$s', FIRSTNAME='%3$s', HOME_CITY='%4$s', HOME_STREET='%5$s', HOME_ZIPCODE='%6$s', LASTNAME='%7$s', PASSWD='%8$s', RANK=%9$d, USERNAME='%10$s', OBJ_VERSION=%11$d where USER_ID=%12$d and OBJ_VERSION=%13$d", 
-               1, "anotheruser at mail.tld", "Ben"+time, "Foocity", "Foostreet", "a222a2", "User", "secret", 0, "anotheruser110"+this.threadId, iteration+1, iteration+1, iteration);
-         
-         writeUserA(emA, writeSQLResA);
-         writeUserB(emB, writeSQLResA);
-         resourceAFlush(emA);
-         resourceBFlush(emB);
-         emA.getSession().getTransaction().commit();
-      }
-      private void writeUserA(final EntityManager em, final String sql)
-      {
-         em.createNativeQuery(sql).executeUpdate();
-      }
-      private void writeUserB(final EntityManager em, final String sql)
-      {
-         em.createNativeQuery(sql).executeUpdate();
-      }
-      private void resourceAFlush(EntityManager entityManager)
-      {
-         entityManager.flush();
-      }
-      private void resourceBFlush(EntityManager entityManager)
-      {
-         entityManager.flush();
-      }
-      private Object findUsingResourceA(final EntityManager em, final String sql)
-      {
-         return  em.createNativeQuery(sql).getSingleResult();
-      }
-      private Object findUsingResourceB(final EntityManager em, final String sql)
-      {
-         return em.createNativeQuery(sql).getSingleResult();
-      }
-      public EntityManagerFactory getEMFactoryA()
-      {
-         return this.emfA;
-      }
-      
-      public EntityManagerFactory getEMFactoryB()
-      {
-         return this.emfB;
-      }
-   }
-   
-   public class SessionSynchronization implements Synchronization
-   {
-      private 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();
-         }
-      }
-   }
 }

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-02-03 09:28:17 UTC (rev 31372)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/resource/SynchronizeTask.java	2010-02-03 09:32:00 UTC (rev 31373)
@@ -6,6 +6,7 @@
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
 import javax.transaction.Synchronization;
 
 import org.apache.log4j.Logger;
@@ -65,7 +66,7 @@
    {
       try
       {/* use the barrier to wait for all concurrent threads, when finished decrement the latch and fall out of 
-      method. Means the profiler does not 
+      method. 
       */
          NDC.inherit(this.parentNDC);
          NDC.push(this.threadId.toString());
@@ -107,6 +108,7 @@
       
       transaction.registerSynchronization(new SessionSynchronization(emA, transaction, true));
       transaction.registerSynchronization(new SessionSynchronization( emB, transaction, true  ) );
+      //transaction.registerSynchronization(new CacheSynchronization(emB.getSession(), ((SessionImpl)emB.getSession()).getJDBCContext(), transaction, emB.getTransaction())) ;
       
       /**
        * A read
@@ -121,19 +123,23 @@
 
       // Prepare a user object
       //User user = userDAO_A.findById(this.threadId, false);
-      User user = findUsingResourceA(userDAO_A);
+      session.set(emA);
+      User userA = findUsingResourceA(userDAO_A);
 
       long time = System.currentTimeMillis();
-      session.set(emA);
+      
       if (this.isOptionalWriteEnabled)
       {
-         user.setFirstname("Ben"+time);
+         userA.setFirstname("Ben"+time);
+         emA.merge(userA);
       }
       session.set(emB);
       // Don't forget to take the return value, this is basically a merge()
       User userB = findUsingResourceB(userDAO_B);
       Assert.assertNotNull(userB);
       userB.setFirstname("Ben"+time);
+      emB.merge(userB);
+      
       resourceAFlush(emA);
       resourceBFlush(emB);
       //emA.getSession().setReadOnly(user, true);
@@ -219,5 +225,17 @@
       return daoBean.findById(this.threadId, 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()) ;
+   }
 }



More information about the jboss-svn-commits mailing list