[jboss-svn-commits] JBL Code SVN: r31725 - labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 18 06:10:32 EST 2010


Author: whitingjr
Date: 2010-02-18 06:10:31 -0500 (Thu, 18 Feb 2010)
New Revision: 31725

Added:
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTask.java
   labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTest.java
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/JDBCTest.java
Log:
Modified to introduce a pure jdbc test case.

Copied: labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTask.java (from rev 31622, 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/HibernateNativeTask.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTask.java	2010-02-18 11:10:31 UTC (rev 31725)
@@ -0,0 +1,124 @@
+ /*
+  * 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 javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Query;
+
+import org.hibernate.Transaction;
+import org.hibernate.ejb.EntityManagerImpl;
+import org.jboss.jbossts.performance.configuration.ConcurrentTaskConfiguration;
+import org.jboss.jbossts.performance.task.RecursiveTask;
+import org.jboss.tm.TransactionLocal;
+import org.testng.Assert;
+
+/**
+ * 
+ * This object performs a read and write on two resources using native SQL. The 
+ * sql query uses the EntityManager to execute the query. 
+ * 
+ * @author <a href="jwhiting at redhat.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class HibernateNativeTask extends RecursiveTask
+{
+    
+   public HibernateNativeTask(final ConcurrentTaskConfiguration taskConfiguration)
+   {
+      super(taskConfiguration);
+   }
+
+   public void task(final int iteration)
+      throws Exception
+   {
+      String readSQL = String.format("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=%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( emB, transaction, true  ) );
+      
+      session.set(emA);
+      Object[] usrA = (Object[])findUsingResourceA(emA, readSQL);//discard details
+      Number version = (Number ) usrA[12];
+      
+      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);
+      transaction.commit();
+   }
+   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 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;
+   }
+}
\ No newline at end of file

Added: 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	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/HibernateNativeTest.java	2010-02-18 11:10:31 UTC (rev 31725)
@@ -0,0 +1,42 @@
+ /*
+  * 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 org.apache.log4j.NDC;
+import org.jboss.jbossts.performance.MultiThreadedTest;
+import org.jboss.jbossts.performance.configuration.ConcurrentTaskConfiguration;
+import org.jboss.jbossts.performance.configuration.MultithreadedTestConfiguration;
+
+public class HibernateNativeTest extends MultiThreadedTest
+{
+   @Override
+   public Runnable getTask(final MultithreadedTestConfiguration taskConfiguration) throws Exception
+   {
+      return new HibernateNativeTask(new ConcurrentTaskConfiguration(getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), taskConfiguration.getCompletionBarrier(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration.getThreadIdentity(), taskConfiguration.getResults()));
+   }
+   @Override
+   protected boolean isMultiResourceTest()
+   {
+      return true;
+   }
+}

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-02-18 11:09:35 UTC (rev 31724)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTask.java	2010-02-18 11:10:31 UTC (rev 31725)
@@ -22,6 +22,8 @@
 
 package org.jboss.jbossts.performance.jdbc;
 
+import java.sql.PreparedStatement;
+
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Query;
@@ -57,20 +59,17 @@
       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( emB, transaction, true  ) );
-      
       session.set(emA);
-      Object[] usrA = (Object[])findUsingResourceA(emA, readSQL);//discard details
-      Number version = (Number ) usrA[12];
       
+      //PreparedStatement pStatement = emA.get
+      //Number version = (Number ) usrA[12];
+      /*
       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;
+      //version = null;
       
       if (this.isOptionalWriteEnabled)
       {
@@ -78,13 +77,14 @@
       }
       session.set(emB);
       Object[] usrB = (Object[])findUsingResourceB(emB, readSQL);//discard details
-      version = (Number) usrB[12];
+      //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);
       transaction.commit();
+      */
    }
    private void writeUserA(final EntityManager em, final String sql)
    {

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-18 11:09:35 UTC (rev 31724)
+++ labs/jbosstm/workspace/whitingjr/trunk/performance/src/test/java/org/jboss/jbossts/performance/jdbc/JDBCTest.java	2010-02-18 11:10:31 UTC (rev 31725)
@@ -22,8 +22,6 @@
 
 package org.jboss.jbossts.performance.jdbc;
 
-import java.util.concurrent.CyclicBarrier;
-
 import org.apache.log4j.NDC;
 import org.jboss.jbossts.performance.MultiThreadedTest;
 import org.jboss.jbossts.performance.configuration.ConcurrentTaskConfiguration;
@@ -40,7 +38,7 @@
    @Override
    public Runnable getTask(final MultithreadedTestConfiguration taskConfiguration) throws Exception
    {
-      return new JDBCTask(new ConcurrentTaskConfiguration(getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), taskConfiguration.getCompletionBarrier(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration.getThreadIdentity()));
+      return new JDBCTask(new ConcurrentTaskConfiguration(getEntityManagerFactory(), getEntityManagerFactoryB(), taskConfiguration.getIterationCount(), taskConfiguration.getCompletionBarrier(), this.isOptionalWriteEnabled, NDC.cloneStack(), taskConfiguration.getThreadIdentity(), taskConfiguration.getResults()));
    }
    @Override
    protected boolean isMultiResourceTest()



More information about the jboss-svn-commits mailing list