db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/test/org/apache/ojb/broker PerformanceTest2.java OJBPerfTest.java
Date Fri, 07 Feb 2003 10:58:41 GMT
arminw      2003/02/07 02:58:40

  Modified:    xdocs    performance.xml
               src/test/org/apache/ojb/performance PerfTest.java
                        PerfMain.java PerfHandle.java
               src/test/org/apache/ojb/broker PerformanceTest2.java
                        OJBPerfTest.java
  Log:
  update performance package,
  restore Performance2 version 1.12
  
  Revision  Changes    Path
  1.7       +53 -36    db-ojb/xdocs/performance.xml
  
  Index: performance.xml
  ===================================================================
  RCS file: /home/cvs/db-ojb/xdocs/performance.xml,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- performance.xml	6 Feb 2003 01:25:18 -0000	1.6
  +++ performance.xml	7 Feb 2003 10:58:35 -0000	1.7
  @@ -54,7 +54,9 @@
   use an O/R tool for a specific software system.
   </p>
   <p>
  -This document describes the <i>OJB Performance Test Suite</i>.
  +This document describes the <i>OJB Performance Test Suite</i>
  +which was created to lighten the decision between native JDBC,
  +OJB and other O/R mapper.
   </p>
   </subsection>
   
  @@ -86,11 +88,22 @@
   or if native JDBC programming should be used for performance reasons.
   </p>
   <p>
  +Take care of compareable configuration properties when run
  +performance tests with different O/R tools.
  +</p>
  +<p>
   If the decision made to use an O/R mapping tool the comparison with
   other tools helps to find the best one for the thought scenario.
   <br/>
  -But performance should not be the only reason to take a specific
  -O/R tool.
  +But performance shouldn't be the only reason to take a specific
  +O/R tool. There are many other points to consider:
  +<br/>- Usability of the supported API's
  +<br/>- Flexibility of the framework
  +<br/>- Scalability of the framework
  +<br/>- Community support
  +<br/>- The different licences of Open Source projects
  +<br/>- etcetera ...
  +
   
   <font color="#ff0000"><i><b>
   bla bla TODO
  @@ -171,12 +184,21 @@
   
   <subsection name="OJB performance in multi-threaded environments" anchor="5">
   
  -<font color="#ff0000"><i><b>
  -TODO
  -</b></i></font>
  +<p>
  +This test was created to check the performance and stability of the
  +supported API's (PB-api, ODMG-api, JDO-api) in a multithreaded environment.
  +Running this test out of the box (a virgin OJB version) shouldn't cause any problems.
  +To run the JDO-api test too, see <a href="tutorial4.html">JDO tutorial</a> and comment in
  +the test in target <code>perf-test</code> in <code>build.xml</code>.
  +</p>
  +<p>
  +Per default OJB use hsql as database, by changing the JdbcConnectionDescriptor
  +in the repository.xml file you can point to your specific RDBMS. Please
  +refer to this <a href="platforms.html">document for details</a>.
  +</p>
   
   <p>
  -To test the performance of OJB in an multithreaded environment call
  +To run the multithreaded performance test call
   <code>bin\build.bat perf-test</code> or
   <code>bin/build.sh perf-test</code>.
   </p>
  @@ -184,31 +206,19 @@
   <p>
   A typical output of this test looks like:
   <source>
  - [ojb] ----------------------------------------------------
  - [ojb] TEST SUMMARY - ODMG
  - [ojb] ----------------------------------------------------
  - [ojb] 10 concurrent threads, handle 2000 articles per thread
  - [ojb] Test period: 46.72 [sec]
  - [ojb] Inserting period: 25878 [msec]
  - [ojb] Fetching period: 6551 [msec]
  - [ojb] Deleting period: 10725 [msec]
  -
  - [ojb] Test was successful
  - [ojb] ----------------------------------------------------
  -
  - [ojb] ----------------------------------------------------
  - [ojb] TEST SUMMARY - PB
  - [ojb] ----------------------------------------------------
  - [ojb] 10 concurrent threads, handle 2000 articles per thread
  - [ojb] Test period: 16.697 [sec]
  - [ojb] Inserting period: 11731 [msec]
  - [ojb] Fetching period: 162 [msec]
  - [ojb] Deleting period: 2247 [msec]
  -
  - [ojb] Test was successful
  - [ojb] ----------------------------------------------------
  +[ojb] =================================================================
  +[ojb]              OJB PERFORMANCE TEST SUMMARY
  +[ojb] 10 concurrent threads, handle 2000 articles per thread
  +[ojb]              - performance mode
  +[ojb] =================================================================
  +[ojb]           API  Test Period       Insert        Fetch       Delete
  +[ojb]                      [sec]       [msec]       [msec]       [msec]
  +[ojb] -----------------------------------------------------------------
  +[ojb]          ODMG       46.083        25654         6204         8303
  +[ojb]            PB       16.811        11864          175         2317
  +[ojb] =================================================================
   
  - [ojb] PerfTest takes 201 [sec]
  +[ojb] PerfTest takes 200 [sec]
   </source>
   </p>
   <p>
  @@ -216,12 +226,13 @@
   in the <code>build.xml</code> file and change the program parameter.
   <br/>
   The test needs five parameter:
  -<br/>- A comma separated list of the test implementation classes
  +<br/>- A comma separated list of the test implementation classes (no blanks!)
   <br/>- The number of test loops
   <br/>- The number of concurrent threads
   <br/>- The number of managed objects per thread
   <br/>- The desired test mode. <code>false</code> means run in
  -performance mode, <code>true</code> means run in stress mode.
  +performance mode, <code>true</code> means run in stress mode
  +(useful for developer to check stability).
   </p>
   </subsection>
   
  @@ -229,12 +240,18 @@
   
   
   <subsection name="How OJB compares to other O/R mapping tools?" anchor="6">
  -<p>
   
   <font color="#ff0000"><i><b>
   TODO
   </b></i></font>
   
  +<p>
  +Many user ask this question and we don't know the answer. But OJB was
  +shipped with a simple performance framework which allows a rudimentarily
  +comparision of the OJB with other (java-based) O/R mapping tools.
  +<br/>
  +Call <code>bin\build.bat perf-test-jar</code> or <code>bin/build.sh perf-test-jar</code>
  +to build the jar file contain all necessary classes.
   </p>
   </subsection>
   
  @@ -242,15 +259,15 @@
   
   
   <subsection name="Using OJB to write clean JDBC code" anchor="6">
  -<p>
   
   <font color="#ff0000"><i><b>
   TODO
   </b></i></font>
   
  +<p>
  +
   </p>
   </subsection>
  -
   
   </section>
   </body>
  
  
  
  1.2       +3 -3      db-ojb/src/test/org/apache/ojb/performance/PerfTest.java
  
  Index: PerfTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PerfTest.java	6 Feb 2003 01:20:54 -0000	1.1
  +++ PerfTest.java	7 Feb 2003 10:58:40 -0000	1.2
  @@ -46,7 +46,7 @@
       public abstract PerfHandle newPerfHandle(PerfTest test);
   
       /**
  -     * Returns the count of all found {@link PerformanceArticle}
  +     * Returns the count of all found {@link PerfArticle}
        * in database. Do not use the cache to get the count!
        */
       public abstract int articleCount();
  @@ -55,7 +55,7 @@
       private void checkApi() throws Exception
       {
           PerfHandle handle = newPerfHandle(this);
  -        PerfArticle article = handle.newPerfArticle(testName());
  +        PerfArticle article = handle.getPreparedPerfArticle(testName());
           PerfArticle[] arr = new PerfArticle[]{article};
           handle.init();
           handle.insertNewArticles(arr);
  
  
  
  1.2       +150 -66   db-ojb/src/test/org/apache/ojb/performance/PerfMain.java
  
  Index: PerfMain.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfMain.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PerfMain.java	6 Feb 2003 01:20:54 -0000	1.1
  +++ PerfMain.java	7 Feb 2003 10:58:40 -0000	1.2
  @@ -12,43 +12,36 @@
   import java.util.StringTokenizer;
   
   /**
  - * The OJB stress/performance test - a small performance test framework for
  + * The OJB stress/performance test - a simple performance test framework for
    * testing multi-threaded environments.
    *
  - *
  - *
  - *
  - *
  - *
  - *
    * <p>
    * <b>You have two possibilities to run this test:</b>
    * <p>
    * - use the build script and call
    * <br/>
  - * <code>bin/build.sh performance2</code>
  + * <code>bin/build.sh perf-test</code>
    * or
    * <br/>
  - * <code>bin\build.bat performance2</code>
  + * <code>bin\build.bat perf-test</code>
    * </p>
    * <p>
    * - or perform the test class by yourself
    * <br/>
    * <code>
  - * java -classpath .... MyPerfTest.class 10 2000 false 3 2 true
  + * java -classpath CLASSPATH org.apache.ojb.performance.PerfMain
  + * [comma separated list of PerfTest implementation classes, no blanks!]
  + * [number of test loops]
  + * [number of threads]
  + * [number of insert/fetch/delete loops per thread]
  + * [boolean - run in stress mode if set true, run in performance mode if set false, default false]
    * </code>
    * <br/>
  - * The programm parameter are in order of use:
  - * <ul>
  - * <li>number of concurrent threads</li>
  - * <li>number of handled objects per thread</li>
  - * <li><code>true</code> client side id generation </li>
  - * <li>chose the api: <i>1</i> PB-api test, <i>2</i> ODMG-api test, <i>3</i> both api tests</li>
  - * <li>number of test loops</li>
  - * <li><code>true</code> use a special stress mode (useful for development)</li>
  - * </ul>
  - * </p>
  + * For example:
  + * <br/>
  + * <code>java -classpath CLASSPATH my.MyPerfTest,myMyPerfTest2 3 10 2000 fale</code>
    * </p>
  + *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  @@ -74,7 +67,7 @@
        */
       private static int testLoops = 1;
   
  -    private Map resultMap;
  +    private HashMap resultMap;
       private Map exceptionMap;
   
   
  @@ -206,50 +199,130 @@
               print.println(buf.toString());
           }
   
  -        Iterator it = resultMap.values().iterator();
  -        while (it.hasNext())
  -        {
  -            PerfResult result = (PerfResult) it.next();
  -            print.println(buildTestSummary(result));
  -        }
  +        print.println(buildTestSummary(resultMap.values()));
  +
  +//        Iterator it = resultMap.values().iterator();
  +//        while (it.hasNext())
  +//        {
  +//            PerfResult result = (PerfResult) it.next();
  +//            print.println(buildTestSummary(result));
  +//        }
       }
   
  -    private String buildTestSummary(PerfResult result)
  +    private String buildTestSummary(Collection results)
       {
  -        String sep = System.getProperty("line.separator");
  +        int column = 13;
           StringBuffer buf = new StringBuffer();
  -        buf.append(sep);
  -        buf.append("----------------------------------------------------");
  -        buf.append(sep);
  -        buf.append("TEST SUMMARY - " + result.getTestName());
  -        buf.append(sep);
  -        buf.append("----------------------------------------------------");
  -        buf.append(sep);
  -        buf.append(PerfMain.getConcurrentThreads() + " concurrent threads, handle " + PerfMain.getIterationsPerThread() + " articles per thread");
  -        buf.append(sep);
  -        buf.append("Test period: " + (double) (((double) result.getTestPeriod()) / 1000) + " [sec]");
  -        buf.append(sep);
  -        buf.append("Inserting period: " + result.getInsertPeriod() + " [msec]");
  -        buf.append(sep);
  -        buf.append("Fetching period: " + result.getFetchPeriod() + " [msec]");
  -        buf.append(sep);
  -        buf.append("Deleting period: " + result.getDeletePeriod() + " [msec]");
  -        buf.append(sep);
  -
  -        if (result.isValid())
  +        // table header
  +        buf.append(EOL);
  +        for(int i=0;i<5;i++)
  +        {
  +            buf.append(getFilledUpToLength("", column, "="));
  +        }
  +        buf.append(EOL);
  +        buf.append(getFilledUpToLength("", column, " "));
  +        buf.append(getFilledUpToLength("OJB PERFORMANCE TEST SUMMARY", column, " "));
  +        buf.append(EOL);
  +
  +        buf.append(PerfMain.getConcurrentThreads() + " concurrent threads, handle " +
  +                PerfMain.getIterationsPerThread() + " objects per thread");
  +        buf.append(EOL);
  +        buf.append(getFilledUpToLength("", column, " "));
  +        buf.append("- " + (isUseStressMode()==false ? "performance mode" : "stress mode -"));
  +        buf.append(EOL);
  +        for(int i=0;i<5;i++)
           {
  -            buf.append(sep + "Test was successful" + sep);
  +            buf.append(getFilledUpToLength("", column, "="));
           }
  -        else
  +        buf.append(EOL);
  +        buf.append(getFilledUpToLength("API", column, " "));
  +        buf.append(getFilledUpToLength("Test Period", column, " "));
  +        buf.append(getFilledUpToLength("Insert", column, " "));
  +        buf.append(getFilledUpToLength("Fetch", column, " "));
  +        buf.append(getFilledUpToLength("Delete", column, " "));
  +        buf.append(EOL);
  +        buf.append(getFilledUpToLength("", column, " "));
  +        buf.append(getFilledUpToLength("[sec]", column, " "));
  +        buf.append(getFilledUpToLength("[msec]", column, " "));
  +        buf.append(getFilledUpToLength("[msec]", column, " "));
  +        buf.append(getFilledUpToLength("[msec]", column, " "));
  +        buf.append(EOL);
  +        for(int i=0;i<5;i++)
           {
  -            buf.append(sep + buildObjectBeforeAfterList(result.consistentList) + sep);
  +            buf.append(getFilledUpToLength("", column, "-"));
           }
   
  -        buf.append("----------------------------------------------------");
  -
  +        // fill table
  +        Iterator it = results.iterator();
  +        while(it.hasNext())
  +        {
  +            buf.append(EOL);
  +            PerfResult res = (PerfResult) it.next();
  +            buf.append(getFilledUpToLength(res.getTestName(), column, " "));
  +            buf.append(getFilledUpToLength(new Double((double) (((double) res.getTestPeriod()) / 1000)).toString(), column, " "));
  +            buf.append(getFilledUpToLength(new Long(res.getInsertPeriod()).toString(), column, " "));
  +            buf.append(getFilledUpToLength(new Long(res.getFetchPeriod()).toString(), column, " "));
  +            buf.append(getFilledUpToLength(new Long(res.getDeletePeriod()).toString(), column, " "));
  +        }
  +        buf.append(EOL);
  +        for(int i=0;i<5;i++)
  +        {
  +            buf.append(getFilledUpToLength("", column, "="));
  +        }
           return buf.toString();
       }
   
  +    private String getFilledUpToLength(String target, int length, String fillCharacter)
  +    {
  +        if(target.length() > length) return target;
  +
  +        int count = length - target.length();
  +        String blanks = "";
  +        for(int i=0;i<count;i++)
  +        {
  +            blanks = blanks + fillCharacter;
  +        }
  +        return blanks + target;
  +    }
  +
  +//    private String buildTestSummary(PerfResult result)
  +//    {
  +//        String EOL = System.getProperty("line.separator");
  +//        StringBuffer buf = new StringBuffer();
  +//        buf.append(EOL);
  +//        buf.append("----------------------------------------------------");
  +//        buf.append(EOL);
  +//        buf.append("TEST SUMMARY - " + result.getTestName());
  +//        buf.append(EOL);
  +//        buf.append("----------------------------------------------------");
  +//        buf.append(EOL);
  +//        buf.append(PerfMain.getConcurrentThreads() + " concurrent threads, handle " + PerfMain.getIterationsPerThread() + " articles per thread");
  +//        buf.append(EOL);
  +//        buf.append("- " + (result.isStressMode()==false ? "performance mode" : "stress mode -"));
  +//        buf.append(EOL);
  +//        buf.append("Test period: " + (double) (((double) result.getTestPeriod()) / 1000) + " [sec]");
  +//        buf.append(EOL);
  +//        buf.append("Inserting period: " + result.getInsertPeriod() + " [msec]");
  +//        buf.append(EOL);
  +//        buf.append("Fetching period: " + result.getFetchPeriod() + " [msec]");
  +//        buf.append(EOL);
  +//        buf.append("Deleting period: " + result.getDeletePeriod() + " [msec]");
  +//        buf.append(EOL);
  +//
  +//        if (result.isValid())
  +//        {
  +//            buf.append(EOL + "Test was successful" + EOL);
  +//        }
  +//        else
  +//        {
  +//            buf.append(EOL + buildObjectBeforeAfterList(result.consistentList) + EOL);
  +//        }
  +//
  +//        buf.append("----------------------------------------------------");
  +//
  +//        return buf.toString();
  +//    }
  +
       private String buildObjectBeforeAfterList(List consistentList)
       {
           StringBuffer buf = new StringBuffer();
  @@ -277,6 +350,7 @@
           {
               result = new PerfResult();
               result.setTestName(testName);
  +            result.setStressMode(isUseStressMode());
               result.setIterationsPerThread(getIterationsPerThread());
               result.setNumberOfThreads(getConcurrentThreads());
               result.setTestLoops(getTestLoops());
  @@ -338,6 +412,7 @@
       {
           private String testName;
           private long testPeriod;
  +        private boolean stressMode;
   
           private int testLoops;
           private int numberOfThreads;
  @@ -359,19 +434,18 @@
   
           public String toString()
           {
  -            String eol = System.getProperty("line.separator");
               StringBuffer buf = new StringBuffer();
  -            buf.append(eol + "[" + this.getClass().getName());
  -            buf.append(eol + "testName=" + testName);
  -            buf.append(eol + "testPeriod=" + testPeriod);
  -            buf.append(eol + "testLoops=" + testLoops);
  -            buf.append(eol + "numberOfThreads=" + numberOfThreads);
  -            buf.append(eol + "iterationsPerThread=" + iterationsPerThread);
  -            buf.append(eol + "isValid=" + isValid());
  -            buf.append(eol + "insertPeriod=" + getInsertPeriod());
  -            buf.append(eol + "fetchPeriod=" + getFetchPeriod());
  -            buf.append(eol + "deletePeriod=" + getDeletePeriod());
  -            buf.append(eol + "consistentList: " + consistentList);
  +            buf.append(EOL + "[" + this.getClass().getName());
  +            buf.append(EOL + "testName=" + testName);
  +            buf.append(EOL + "testPeriod=" + testPeriod);
  +            buf.append(EOL + "testLoops=" + testLoops);
  +            buf.append(EOL + "numberOfThreads=" + numberOfThreads);
  +            buf.append(EOL + "iterationsPerThread=" + iterationsPerThread);
  +            buf.append(EOL + "isValid=" + isValid());
  +            buf.append(EOL + "insertPeriod=" + getInsertPeriod());
  +            buf.append(EOL + "fetchPeriod=" + getFetchPeriod());
  +            buf.append(EOL + "deletePeriod=" + getDeletePeriod());
  +            buf.append(EOL + "consistentList: " + consistentList);
               buf.append("]");
               return buf.toString();
           }
  @@ -380,6 +454,16 @@
           {
               this.consistentList.add(entry);
               valid = valid && entry.isPassed();
  +        }
  +
  +        public boolean isStressMode()
  +        {
  +            return stressMode;
  +        }
  +
  +        public void setStressMode(boolean stressMode)
  +        {
  +            this.stressMode = stressMode;
           }
   
           public boolean isValid()
  
  
  
  1.2       +41 -9     db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java
  
  Index: PerfHandle.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/performance/PerfHandle.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- PerfHandle.java	6 Feb 2003 01:20:54 -0000	1.1
  +++ PerfHandle.java	7 Feb 2003 10:58:40 -0000	1.2
  @@ -2,6 +2,7 @@
   
   import java.util.Collection;
   import java.util.Iterator;
  +import java.math.BigDecimal;
   
   /**
    * Derivate this class to implement a test client for the performance test.
  @@ -28,6 +29,11 @@
       public abstract void init() throws Exception;
   
       /**
  +     * Do clean up.
  +     */
  +    public abstract void tearDown() throws Exception;
  +
  +    /**
        * Store the given articles to database. Do optimize
        * performance.
        */
  @@ -61,6 +67,20 @@
       public abstract void deleteArticlesStress(PerfArticle[] arr) throws Exception;
   
       /**
  +     * Called to get a new instance class of the {@link org.apache.ojb.performance.PerfArticle}
  +     * interface, override this method if you need your own implementation
  +     * (with default constructor) of the PerfArticle-Interface.
  +     * <br/>
  +     * By default this method returns a new instance of the
  +     * {@link org.apache.ojb.performance.PerfArticleImpl} class.
  +     *
  +     */
  +    public PerfArticle newPerfArticle()
  +    {
  +        return new PerfArticleImpl();
  +    }
  +
  +    /**
        * The returned name was used as 'articleName' for all
        * created <code>PerfArticles</code> for this thread.
        * This allows an easy build of the query statement
  @@ -76,14 +96,26 @@
       }
   
       /**
  -     * Return a new instance of a {@link PerfArticle} implementation.
  -     */
  -    public abstract PerfArticle newPerfArticle(String articleName);
  -
  -    /**
  -     * Do clean up.
  +     * Factory method that creates an {@link org.apache.ojb.performance.PerfArticle}
  +     * using the {@link org.apache.ojb.performance.PerfArticleImpl} class,
  +     * override this method if you need your own implementation
  +     * of the PerfArticle-Interface.
  +     *
  +     * @param articleName set the 'articleName'
  +     * @return the created PerfArticle object
        */
  -    public abstract void tearDown() throws Exception;
  +    protected PerfArticle getPreparedPerfArticle(String articleName)
  +    {
  +        PerfArticle a = newPerfArticle();
  +        a.setArticleName(articleName);
  +        a.setMinimumStock(100);
  +        a.setPrice(new BigDecimal(0.45));
  +        a.setProductGroupId(1);
  +        a.setStock(234);
  +        a.setSupplierId(4);
  +        a.setUnit("bottle");
  +        return a;
  +    }
   
       /**
        * Runnable implementation method.
  @@ -93,7 +125,7 @@
           arr = new PerfArticle[PerfMain.getIterationsPerThread()];
           for (int i = 0; i < PerfMain.getIterationsPerThread(); i++)
           {
  -            PerfArticle a = newPerfArticle(getTestObjectName());
  +            PerfArticle a = getPreparedPerfArticle(getTestObjectName());
               arr[i] = a;
           }
   
  
  
  
  1.15      +300 -438  db-ojb/src/test/org/apache/ojb/broker/PerformanceTest2.java
  
  Index: PerformanceTest2.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/PerformanceTest2.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- PerformanceTest2.java	31 Jan 2003 17:50:04 -0000	1.14
  +++ PerformanceTest2.java	7 Feb 2003 10:58:40 -0000	1.15
  @@ -8,89 +8,42 @@
   import org.apache.ojb.broker.query.Query;
   import org.apache.ojb.broker.query.QueryByCriteria;
   import org.apache.ojb.broker.util.ObjectModificationDefaultImpl;
  +import org.apache.ojb.broker.util.logging.Logger;
  +import org.apache.ojb.broker.util.logging.LoggerFactory;
   import org.apache.ojb.odmg.OJB;
  +import org.odmg.DList;
   import org.odmg.Database;
   import org.odmg.Implementation;
  -import org.odmg.ODMGException;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
   import java.util.Iterator;
  -import java.util.List;
   
   /**
  - * A stress/performance test for the PB- and ODMG-api
  - * in multi-threaded environments.
  - * <p>
  - * <b>You have two possibilities to run this test:</b>
  - * <p>
  - * - use the build script and call
  - * <br/>
  - * <code>bin/build.sh performance2</code>
  - * or
  - * <br/>
  - * <code>bin\build.bat performance2</code>
  - * </p>
  - * <p>
  - * - or perform the test class by yourself
  - * <br/>
  - * <code>
  - * java -classpath .... PerformanceTest2 10 2000 false 3 2 true
  - * </code>
  - * <br/>
  - * The programm parameter are in order of use:
  - * <ul>
  - * <li>number of concurrent threads</li>
  - * <li>number of handled objects per thread</li>
  - * <li><code>true</code> client side id generation </li>
  - * <li>chose the api: <i>1</i> PB-api test, <i>2</i> ODMG-api test, <i>3</i> both api tests</li>
  - * <li>number of test loops</li>
  - * <li><code>true</code> use a special stress mode (useful for development)</li>
  - * </ul>
  - * </p>
  - * </p>
  - *
  + * stress test against one database using several threads
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>.
    * @version $Id$
    */
   public class PerformanceTest2 //extends TestCase
   {
  -    private static final String PREFIX_LOG = "[" + PerformanceTest2.class.getName() + "] ";
  -    /**
  -     * iterations per thread
  -     */
       private static int iterationsPerThread = 1000;
  -    /**
  -     * number of concurrent threads
  -     */
       private static int concurrentThreads = 10;
  -    /**
  -     * used for client generated ids
  -     */
  +    // used for client generated ids
       private static int id = 10001;
  -    /**
  -     * if set false, we use autoincrement key gerneration
  -     */
  +    // if set false, we use autoincrement key gerneration
       private static boolean clientKeyGeneration = false;
  -    /**
  -     * 1 PB-api test, 2 ODMG-api test, 3 both api tests
  -     */
       private static int whichTest = 3;
  -    /**
  -     * if false we use performance optimized delete/insert method
  -     */
  -    private static boolean useStressMode = false;
   
       /**
  -     * testTimes[0] startTime/test length
  -     * testTimes[1] inserting times
  -     * testTimes[2] fetching times
  -     * testTimes[3] deleting times
  +     * times[0] startTime/test length
  +     * times[1] inserting times
  +     * times[2] fetching times
  +     * times[3] deleting times
        */
  -    private long[] testTimes;
  +    private long[] times;
       private int threadCount;
  -    // private Logger log = LoggerFactory.getLogger(PerformanceTest2.class);
  +    private Logger log = LoggerFactory.getLogger(PerformanceTest2.class);
       public ThreadGroup threadGroup = new ThreadGroup("PerfTest");
       private String databaseName = TestHelper.DEF_DATABASE_NAME;
   
  @@ -99,6 +52,126 @@
           this.threadCount = concurrentThreads;
       }
   
  +    /**
  +     * generate client made ids
  +     */
  +    public synchronized static int getId()
  +    {
  +        return ++id;
  +    }
  +
  +    public int getArticleCount()
  +    {
  +        Criteria c = new Criteria();
  +        Query q = new QueryByCriteria(PerformanceArticle.class, c);
  +        int count = 0;
  +        try
  +        {
  +            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            count = broker.getCount(q);
  +            broker.close();
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +        }
  +        return count;
  +    }
  +
  +    public ThreadGroup getThreadGroup()
  +    {
  +        return threadGroup;
  +    }
  +
  +    public synchronized void checkOut()
  +    {
  +        --threadCount;
  +    }
  +
  +    public synchronized void addTime(int position, long time)
  +    {
  +        times[position] = times[position] + time;
  +    }
  +
  +    public synchronized int activeThreads(boolean notify)
  +    {
  +        try
  +        {
  +            //freeze main thread, we only want to trace client threads
  +            if (!notify)
  +                wait();
  +            else
  +                notifyAll();
  +        }
  +        catch (InterruptedException e)
  +        {
  +        }
  +        return this.threadCount;
  +    }
  +
  +    /**
  +     * Setting up the test fixture.
  +     */
  +    public void init() throws Exception
  +    {
  +//        log.info("Start init performance test");
  +        times = new long[4];
  +        threadCount = concurrentThreads;
  +
  +        if (whichTest == 1 || whichTest == 3)
  +        {
  +//        log.info("Init PB-API");
  +            PerformanceArticle art = createArticle(1000);
  +            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            broker.beginTransaction();
  +            broker.store(art);
  +            broker.commitTransaction();
  +
  +            broker.beginTransaction();
  +            broker.delete(art);
  +            broker.commitTransaction();
  +            broker.close();
  +        }
  +
  +        if (whichTest == 2 || whichTest == 3)
  +        {
  +//        log.info("Init ODMG-API");
  +            PerformanceArticle art2 = createArticle(1001);
  +            Implementation ojb = OJB.getInstance();
  +            Database db = ojb.newDatabase();
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
  +            Transaction tx = ojb.newTransaction();
  +            tx.begin();
  +            tx.lock(art2, Transaction.WRITE);
  +            tx.commit();
  +
  +            tx.begin();
  +            db.deletePersistent(art2);
  +            tx.commit();
  +            db.close();
  +//        log.info("End init performance test");
  +        }
  +    }
  +
  +    /**
  +     * factory method that createa an PerformanceArticle
  +     * @return the created PerformanceArticle object
  +     */
  +    private PerformanceArticle createArticle(int id)
  +    {
  +        PerformanceArticle a = new PerformanceArticle();
  +        if (clientKeyGeneration) a.setArticleId(getId());
  +        a.setArticleName("New Performance Article " + id);
  +        a.setMinimumStock(100);
  +        a.setOrderedUnits(17);
  +        a.setPrice(0.45);
  +        a.setProductGroupId(1);
  +        a.setStock(234);
  +        a.setSupplierId(4);
  +        a.setUnit("bottle");
  +        return a;
  +    }
  +
       public static void main(String[] args)
       {
           int loops = args.length > 4 ? Integer.parseInt(args[4]) : 1;
  @@ -115,31 +188,22 @@
   
       private static void performTest(String[] args)
       {
  -        // number of threads
           if (args.length > 0)
           {
               concurrentThreads = Integer.parseInt(args[0]);
           }
  -        // number of loops per thread
           if (args.length > 1)
           {
               iterationsPerThread = Integer.parseInt(args[1]);
           }
  -        // client side key generation
           if (args.length > 2)
           {
               clientKeyGeneration = Boolean.valueOf(args[2]).booleanValue();
           }
  -        // select the api
           if (args.length > 3)
           {
               whichTest = Integer.parseInt(args[3]);
           }
  -        // run in stress mode
  -        if (args.length > 5)
  -        {
  -            useStressMode = Boolean.valueOf(args[5]).booleanValue();
  -        }
           try
           {
               PerformanceTest2 test = new PerformanceTest2();
  @@ -154,19 +218,20 @@
                   test.testMultithreaded_PB_api();
                   while (test.threadGroup.activeCount() > activeThreadsStart)
                   {
  -                    System.out.println("# active threads: " + test.threadGroup.activeCount());
  +                    System.err.println("# active threads: " + test.threadGroup.activeCount());
                       try
                       {
  -                        Thread.sleep(500);
  +                        Thread.sleep(1500);
                       }
                       catch (InterruptedException e)
                       {
                       }
                   }
  +
  +                System.err.println("Test-Info:   Objects in DB before PB test: " + objectCount);
                   objectCountAfter = test.getArticleCount();
  -                System.out.println("Test-Info:   Objects in DB before PB test: " + objectCount);
  -                System.out.println("Test-Info:   Objects in DB after PB test: " + objectCountAfter);
  -                System.out.println("Test-Info:   Stress test was successful? - " + (objectCount == objectCountAfter) + " -");
  +                System.err.println("Test-Info:   Objects in DB after PB test: " + objectCountAfter);
  +                System.err.println("Test-Info:   Stress test was successful? - " + (objectCount == objectCountAfter) + " -");
               }
   
   
  @@ -178,19 +243,20 @@
                   test.testMultithreaded_ODMG_api();
                   while (test.threadGroup.activeCount() > activeThreadsStart)
                   {
  -                    System.out.println("# active threads: " + test.threadGroup.activeCount());
  +                    System.err.println("# active threads: " + test.threadGroup.activeCount());
                       try
                       {
  -                        Thread.sleep(500);
  +                        Thread.sleep(1500);
                       }
                       catch (InterruptedException e)
                       {
                       }
                   }
  +
  +                System.err.println("Test-Info:   Objects in DB before ODMG test: " + objectCount);
                   objectCountAfter = test.getArticleCount();
  -                System.out.println("Test-Info:   Objects in DB before ODMG test: " + objectCount);
  -                System.out.println("Test-Info:   Objects in DB after ODMG test: " + objectCountAfter);
  -                System.out.println("Test-Info:   Stress test was successful? - " + (objectCount == objectCountAfter) + " -");
  +                System.err.println("Test-Info:   Objects in DB after ODMG test: " + objectCountAfter);
  +                System.err.println("Test-Info:   Stress test was successful? - " + (objectCount == objectCountAfter) + " -");
               }
           }
           catch (Exception e)
  @@ -199,55 +265,12 @@
           }
       }
   
  -
  -    public ThreadGroup getThreadGroup()
  -    {
  -        return threadGroup;
  -    }
  -
  -    public synchronized void checkOut()
  -    {
  -        --threadCount;
  -    }
  -
  -    public synchronized void addTime(int position, long time)
  -    {
  -        testTimes[position] = testTimes[position] + time;
  -    }
  -
  -    public synchronized int activeThreads(boolean notify)
  -    {
  -        try
  -        {
  -            //freeze main thread, we only want to trace client threads
  -            if (!notify)
  -                wait();
  -            else
  -                notifyAll();
  -        }
  -        catch (InterruptedException e)
  -        {
  -        }
  -        return this.threadCount;
  -    }
  -
  -    /**
  -     * Setting up the test fixture.
  -     */
  -    public void init() throws Exception
  -    {
  -        System.out.println(PREFIX_LOG + "init test");
  -        testTimes = new long[4];
  -        threadCount = concurrentThreads;
  -    }
  -
  -
       public void testMultithreaded_PB_api()
       {
           String sep = System.getProperty("line.separator");
  -        testTimes[0] = System.currentTimeMillis();
  -        System.out.println(PREFIX_LOG + sep + sep + "++ Start thread generation for PB api test ++");
  -        System.out.println(PREFIX_LOG + "Begin with performance test, " + concurrentThreads +
  +        times[0] = System.currentTimeMillis();
  +        log.info(sep + sep + "++ Start thread generation for PB api test ++");
  +        log.info("Begin with performance test, " + concurrentThreads +
                   " concurrent threads, handle " + iterationsPerThread + " articles form each thread");
           for (int i = 0; i < concurrentThreads; i++)
           {
  @@ -262,17 +285,17 @@
               //this thread,
               //cause we do not want to trace this loop
           }
  -        testTimes[0] = (long) (System.currentTimeMillis() - testTimes[0]);
  -        System.out.println(PREFIX_LOG + buildTestSummary("PB API"));
  -        System.out.println(PREFIX_LOG + "++ End of performance test PB api ++" + sep + sep);
  +        times[0] = (long) (System.currentTimeMillis() - times[0]);
  +        log.info(buildTestSummary("PB API"));
  +        log.info("++ End of performance test PB api ++" + sep + sep);
       }
   
       public void testMultithreaded_ODMG_api()
       {
           String sep = System.getProperty("line.separator");
  -        testTimes[0] = System.currentTimeMillis();
  -        System.out.println(PREFIX_LOG + "++ Start thread generation for ODMG api test ++");
  -        System.out.println(PREFIX_LOG + "Begin with performance test, " + concurrentThreads +
  +        times[0] = System.currentTimeMillis();
  +        log.info("++ Start thread generation for ODMG api test ++");
  +        log.info("Begin with performance test, " + concurrentThreads +
                   " concurrent threads, handle " + iterationsPerThread + " articles form each thread");
           for (int i = 0; i < concurrentThreads; i++)
           {
  @@ -286,35 +309,9 @@
               //this thread,
               //cause we do not want to trace this loop
           }
  -        testTimes[0] = (long) (System.currentTimeMillis() - testTimes[0]);
  -        System.out.println(PREFIX_LOG + buildTestSummary("ODMG"));
  -        System.out.println(PREFIX_LOG + "++ End of performance test ODMG api ++" + sep);
  -    }
  -
  -    /**
  -     * generate client made ids
  -     */
  -    public synchronized static int getId()
  -    {
  -        return ++id;
  -    }
  -
  -    private int getArticleCount()
  -    {
  -        Criteria c = new Criteria();
  -        Query q = new QueryByCriteria(PerformanceArticle.class, c);
  -        int count = 0;
  -        try
  -        {
  -            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            count = broker.getCount(q);
  -            broker.close();
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -        }
  -        return count;
  +        times[0] = (long) (System.currentTimeMillis() - times[0]);
  +        log.info(buildTestSummary("ODMG"));
  +        log.info("++ End of performance test ODMG api ++" + sep);
       }
   
       private String buildTestSummary(String key)
  @@ -328,103 +325,87 @@
           buf.append(sep);
           buf.append(concurrentThreads + " concurrent threads, handle " + iterationsPerThread + " articles per thread");
           buf.append(sep);
  -        buf.append("Test period: " + (double) (((double) testTimes[0]) / 1000) + " [sec]");
  +        buf.append("Test period: " + (double) (((double) times[0]) / 1000) + " [sec]");
           buf.append(sep);
  -        buf.append("Inserting period: " + (testTimes[1] / (concurrentThreads)) + " [msec]");
  +        buf.append("Inserting period: " + (times[1] / (concurrentThreads)) + " [msec]");
           buf.append(sep);
  -        buf.append("Fetching period: " + (testTimes[2] / (concurrentThreads)) + " [msec]");
  +        buf.append("Fetching period: " + (times[2] / (concurrentThreads)) + " [msec]");
           buf.append(sep);
  -        buf.append("Deleting period: " + (testTimes[3] / (concurrentThreads)) + " [msec]");
  +        buf.append("Deleting period: " + (times[3] / (concurrentThreads)) + " [msec]");
           buf.append(sep);
           buf.append("----------------------------------------------------");
   
           return buf.toString();
       }
   
  -
  -
  -    // =====================================================================================
  -    // Inner class
  -    // =====================================================================================
  -
       /**
        * ODMG-api test class
        */
  -    class PerfomanceTestClientODMG extends PerfHandle
  +    class PerfomanceTestClientODMG implements Runnable
       {
  -        private String objectName;
  +        private static final String PRE_NAME = "A_";
  +        private PerformanceArticle[] arr;
           private Implementation odmg;
  +        private String threadName;
           private Database db;
  -        private boolean notInit = true;
   
           public PerfomanceTestClientODMG()
           {
           }
   
  -        void init()
  +        public void run()
           {
  +            odmg = OJB.getInstance();
  +            threadName = Thread.currentThread().toString();
  +            arr = new PerformanceArticle[iterationsPerThread];
  +            for (int i = 0; i < iterationsPerThread; i++)
  +            {
  +                PerformanceArticle a = createArticle(i, threadName);
  +                arr[i] = a;
  +            }
  +
  +            //log.info("Thread "+this+" run");
               try
               {
  -                odmg = OJB.getInstance();
  -                db = odmg.newDatabase();
  -                db.open(databaseName, Database.OPEN_READ_WRITE);
  +                insertNewArticles();
  +                readArticlesByCursor();
  +                deleteArticles();
               }
  -            catch (ODMGException e)
  +            catch (Throwable e)
               {
  -                e.printStackTrace();
  +                log.error("Error in client " + this, e);
               }
  -        }
  -
  -        void tearDown() throws Exception
  -        {
  -            db.close();
  -        }
  -
  -        String getTestObjectName()
  -        {
  -            if (objectName == null) objectName = "PB_" + Thread.currentThread().toString();
  -            return objectName;
  -        }
  -
  -        /**
  -         * A performance optimized insert-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  -         */
  -        protected void insertNewArticles() throws Exception
  -        {
  -            Transaction tx = odmg.newTransaction();
  -            tx.begin();
  -            for (int i = 0; i < arr.length; i++)
  +            finally
               {
  -                tx.lock(arr[i], Transaction.WRITE);
  +                checkOut();
  +                activeThreads(true);
               }
  -            tx.commit();
           }
   
           /**
  -         * A resource cumbering insert-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  +         * factory method that createa an PerformanceArticle
  +         * @return the created PerformanceArticle object
            */
  -        protected void insertNewArticlesStress() throws Exception
  +        private PerformanceArticle createArticle(int id, String name)
           {
  -            for (int i = 0; i < arr.length; i++)
  -            {
  -                Transaction tx = odmg.newTransaction();
  -                tx.begin();
  -                tx.lock(arr[i], Transaction.WRITE);
  -                tx.commit();
  -            }
  +            PerformanceArticle a = new PerformanceArticle();
  +            if (clientKeyGeneration) a.setArticleId(getId());
  +            a.setArticleName(PRE_NAME + name);
  +            a.setMinimumStock(100);
  +            a.setOrderedUnits(17);
  +            a.setPrice(0.45);
  +            a.setProductGroupId(1);
  +            a.setStock(234);
  +            a.setSupplierId(4);
  +            a.setUnit("bottle");
  +            return a;
           }
   
  -        /**
  -         * A performance optimized delete-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  -         */
           protected void deleteArticles() throws Exception
           {
  +            long start = System.currentTimeMillis();
  +            Database db = odmg.newDatabase();
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
               Transaction tx = odmg.newTransaction();
               tx.begin();
               for (int i = 0; i < arr.length; i++)
  @@ -432,34 +413,44 @@
                   db.deletePersistent(arr[i]);
               }
               tx.commit();
  +            db.close();
  +            long stop = System.currentTimeMillis();
  +            times[3] = times[3] + (stop - start);
           }
   
  -        /**
  -         * A resource cumbering insert-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  -         */
  -        protected void deleteArticlesStress() throws Exception
  +        protected void insertNewArticles() throws Exception
           {
  +            long start = System.currentTimeMillis();
  +            Database db = odmg.newDatabase();
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
  +            Transaction tx = odmg.newTransaction();
  +            tx.begin();
               for (int i = 0; i < arr.length; i++)
               {
  -                Transaction tx = odmg.newTransaction();
  -                tx.begin();
  -                db.deletePersistent(arr[i]);
  -                tx.commit();
  +                tx.lock(arr[i], Transaction.WRITE);
               }
  +            tx.commit();
  +            db.close();
  +            long stop = System.currentTimeMillis();
  +            times[1] = times[1] + (stop - start);
           }
   
           protected void readArticlesByCursor() throws Exception
           {
  -            Transaction tx = odmg.newTransaction();
  -            tx.begin();
  +            long start = System.currentTimeMillis();
  +            int artId = arr[0].articleId;
  +
  +            Database db = odmg.newDatabase();
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
  +// for better performance we could read without a tx
  +//            Transaction tx = ojb.newTransaction();
  +//            tx.begin();
               OQLQuery query = odmg.newOQLQuery();
               String sql = "select allArticles from " + PerformanceArticle.class.getName() +
  -                    " where articleName like \"" + objectName + "\"";
  +                    " where articleName = \"" + PRE_NAME + threadName + "\"";
               query.create(sql);
  -            List allProducts = (List) query.execute();
  -            tx.commit();
  +            DList allProducts = (DList) query.execute();
  +//            tx.commit();
               Iterator iter = allProducts.iterator();
               int fetchCount = 0;
               while (iter.hasNext())
  @@ -467,48 +458,74 @@
                   fetchCount++;
                   PerformanceArticle a = (PerformanceArticle) iter.next();
               }
  -            if (fetchCount != arr.length)
  -            {
  -                System.out.println("## Read objects: Could not found number of created objects, expected " +
  -                        (arr.length) + " found " + fetchCount + " ##");
  -            }
  +            db.close();
  +            long stop = System.currentTimeMillis();
  +            times[2] = times[2] + (stop - start);
           }
       }
   
   
  -
  -    // =====================================================================================
  -    // Inner class
  -    // =====================================================================================
  -
       /**
        * PB-api test class
        */
  -    class PerfomanceTestClientPB extends PerfHandle implements Runnable
  +    class PerfomanceTestClientPB implements Runnable
       {
  -        private String objectName;
  +        private PerformanceArticle[] arr;
   
           public PerfomanceTestClientPB()
           {
  +            arr = new PerformanceArticle[iterationsPerThread];
  +            for (int i = 0; i < iterationsPerThread; i++)
  +            {
  +                PerformanceArticle a = createArticle(i);
  +                arr[i] = a;
  +            }
  +            //log.info("Articles created");
           }
   
  -        String getTestObjectName()
  +        public void run()
           {
  -            if (objectName == null) objectName = "PB_" + Thread.currentThread().toString();
  -            return objectName;
  +            //log.info("Thread "+this+" run");
  +            try
  +            {
  +                insertNewArticles();
  +                readArticlesByCursor();
  +                deleteArticles();
  +            }
  +            catch (Throwable e)
  +            {
  +                log.error("Error in client " + this, e);
  +            }
  +            finally
  +            {
  +                checkOut();
  +                activeThreads(true);
  +            }
           }
   
  -        void init() throws Exception
  +        /**
  +         * factory method that createa an PerformanceArticle
  +         * @return the created PerformanceArticle object
  +         */
  +        private PerformanceArticle createArticle(int id)
           {
  +            PerformanceArticle a = new PerformanceArticle();
  +            if (clientKeyGeneration) a.setArticleId(getId());
  +            a.setArticleName("New Performance Article " + id);
  +            a.setMinimumStock(100);
  +            a.setOrderedUnits(17);
  +            a.setPrice(0.45);
  +            a.setProductGroupId(1);
  +            a.setStock(234);
  +            a.setSupplierId(4);
  +            a.setUnit("bottle");
  +            return a;
           }
   
  -        /**
  -         * A resource cumbering insert-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  -         */
  -        protected void insertNewArticlesStress() throws Exception
  +        protected void deleteArticles() throws Exception
           {
  +            long start = System.currentTimeMillis();
  +
               for (int i = 0; i < arr.length; i++)
               {
                   PersistenceBroker broker = null;
  @@ -516,80 +533,27 @@
                   {
                       broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                       broker.beginTransaction();
  -                    broker.store(arr[i]);
  +                    broker.delete(arr[i]);
                       broker.commitTransaction();
                   }
                   finally
                   {
                       if (broker != null) broker.close();
                   }
  -
               }
  +
  +            long stop = System.currentTimeMillis();
  +            times[3] = times[3] + (stop - start);
           }
   
  -        /**
  -         * A performance optimized insert-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  -         */
           protected void insertNewArticles() throws Exception
           {
  +
               ObjectModificationDefaultImpl needsInsert = new ObjectModificationDefaultImpl();
               needsInsert.setNeedsInsert(true);
  -            PersistenceBroker broker = null;
  -            try
  -            {
  -                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                broker.serviceConnectionManager().setBatchMode(true);
  -                broker.beginTransaction();
  -                for (int i = 0; i < arr.length; i++)
  -                {
  -                    broker.store(arr[i], needsInsert);
  -                }
  -                broker.commitTransaction();
  -            }
  -            finally
  -            {
  -                if (broker != null) broker.close();
  -            }
  -        }
  -
  -        protected void readArticlesByCursor() throws Exception
  -        {
  -            Criteria c = new Criteria();
  -            c.addLike("articleName", objectName);
  -            Query q = new QueryByCriteria(PerformanceArticle.class, c);
   
  -            PersistenceBroker broker = null;
  -            try
  -            {
  -                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                Iterator iter = broker.getIteratorByQuery(q);
  -                int fetchCount = 0;
  -                while (iter.hasNext())
  -                {
  -                    fetchCount++;
  -                    PerformanceArticle a = (PerformanceArticle) iter.next();
  -                }
  -                if (fetchCount != arr.length)
  -                {
  -                    System.out.println("## Read objects: Could not found number of created objects, expected " +
  -                            (arr.length) + " found " + fetchCount + " ##");
  -                }
  -            }
  -            finally
  -            {
  -                if (broker != null) broker.close();
  -            }
  -        }
  +            long start = System.currentTimeMillis();
   
  -        /**
  -         * A resource cumbering delete-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  -         */
  -        protected void deleteArticlesStress() throws Exception
  -        {
               for (int i = 0; i < arr.length; i++)
               {
                   PersistenceBroker broker = null;
  @@ -597,151 +561,49 @@
                   {
                       broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                       broker.beginTransaction();
  -                    broker.delete(arr[i]);
  +                    broker.store(arr[i], needsInsert);
                       broker.commitTransaction();
                   }
                   finally
                   {
                       if (broker != null) broker.close();
                   }
  -            }
  -        }
   
  -        /**
  -         * A performance optimized delete-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  -         */
  -        protected void deleteArticles() throws Exception
  -        {
  -            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            try
  -            {
  -                broker.serviceConnectionManager().setBatchMode(true);
  -                broker.beginTransaction();
  -                for (int i = 0; i < arr.length; i++)
  -                {
  -                    broker.delete(arr[i]);
  -                }
  -                broker.commitTransaction();
               }
  -            finally
  -            {
  -                if (broker != null) broker.close();
  -            }
  -        }
   
  -        void tearDown() throws Exception
  -        {
  +            long stop = System.currentTimeMillis();
  +            times[1] = times[1] + (stop - start);
           }
  -    }
  -
  -
  -
  -    // =====================================================================================
  -    // Inner class
  -    // =====================================================================================
  -
  -    abstract class PerfHandle implements Runnable
  -    {
  -        PerformanceArticle[] arr;
  -        String threadName;
  -
  -        abstract void init() throws Exception;
  -
  -        abstract void insertNewArticles() throws Exception;
  -
  -        abstract void insertNewArticlesStress() throws Exception;
  -
  -        abstract void readArticlesByCursor() throws Exception;
  -
  -        abstract void deleteArticles() throws Exception;
  -
  -        abstract void deleteArticlesStress() throws Exception;
  -
  -        abstract String getTestObjectName();
  -
  -        abstract void tearDown() throws Exception;
   
  -        public void run()
  +        protected void readArticlesByCursor() throws Exception
           {
  -            arr = new PerformanceArticle[iterationsPerThread];
  -            for (int i = 0; i < iterationsPerThread; i++)
  -            {
  -                PerformanceArticle a = createArticle(getTestObjectName());
  -                arr[i] = a;
  -            }
  +            long start = System.currentTimeMillis();
  +            int artId = arr[0].articleId;
   
  +            Criteria c = new Criteria();
  +            c.addBetween("articleId", new Integer(artId), new Integer(artId + iterationsPerThread));
  +            Query q = new QueryByCriteria(PerformanceArticle.class, c);
  +
  +            PersistenceBroker broker = null;
               try
               {
  -                long period = 0;
  -                init();
  -                if (!useStressMode)
  -                {
  -                    period = System.currentTimeMillis();
  -                    insertNewArticles();
  -                    period = System.currentTimeMillis() - period;
  -                    addTime(1, period);
  -                }
  -                else
  -                {
  -                    period = System.currentTimeMillis();
  -                    insertNewArticlesStress();
  -                    period = System.currentTimeMillis() - period;
  -                    addTime(1, period);
  -                }
  -
  -                if (!useStressMode)
  -                {
  -                    period = System.currentTimeMillis();
  -                    readArticlesByCursor();
  -                    period = System.currentTimeMillis() - period;
  -                    addTime(2, period);
  -                }
  -                else
  +                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                Iterator iter = broker.getIteratorByQuery(q);
  +                int fetchCount = 0;
  +                while (iter.hasNext())
                   {
  -                    period = System.currentTimeMillis();
  -                    readArticlesByCursor();
  -                    period = System.currentTimeMillis() - period;
  -                    addTime(2, period);
  +                    fetchCount++;
  +                    PerformanceArticle a = (PerformanceArticle) iter.next();
                   }
  -
  -                period = System.currentTimeMillis();
  -                deleteArticles();
  -                period = System.currentTimeMillis() - period;
  -                addTime(3, period);
  -
  -                tearDown();
  -            }
  -            catch (Exception e)
  -            {
  -                System.out.println(PREFIX_LOG + "## Error in client ##");
  -                e.printStackTrace();
               }
               finally
               {
  -                checkOut();
  -                activeThreads(true);
  +                if (broker != null) broker.close();
               }
  -        }
   
  -        /**
  -         * factory method that createa an PerformanceArticle
  -         * @return the created PerformanceArticle object
  -         */
  -        private PerformanceArticle createArticle(String name)
  -        {
  -            PerformanceArticle a = new PerformanceArticle();
  -            if (clientKeyGeneration) a.setArticleId(getId());
  -            a.setArticleName(name);
  -            a.setMinimumStock(100);
  -            a.setOrderedUnits(17);
  -            a.setPrice(0.45);
  -            a.setProductGroupId(1);
  -            a.setStock(234);
  -            a.setSupplierId(4);
  -            a.setUnit("bottle");
  -            return a;
  +
  +            long stop = System.currentTimeMillis();
  +            times[2] = times[2] + (stop - start);
           }
       }
   }
  
  
  
  1.2       +12 -55    db-ojb/src/test/org/apache/ojb/broker/OJBPerfTest.java
  
  Index: OJBPerfTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/OJBPerfTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OJBPerfTest.java	6 Feb 2003 01:32:15 -0000	1.1
  +++ OJBPerfTest.java	7 Feb 2003 10:58:40 -0000	1.2
  @@ -20,8 +20,9 @@
   import java.util.List;
   
   /**
  - * The performance test implementation classes for testing
  - * the PB-api and ODMG-api of OJB.
  + * Performance test implementation classes for testing
  + * the PB-api and ODMG-api of OJB using the performance-package
  + * test classes.
    *
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
  @@ -82,27 +83,8 @@
           }
   
           /**
  -         * factory method that creates an {@link org.apache.ojb.performance.PerfArticle}
  -         * @param articleName set the 'articleName'
  -         * @return the created PerfArticle object
  -         */
  -        public PerfArticle newPerfArticle(String articleName)
  -        {
  -            PerfArticle a = new PerfArticleImpl();
  -            a.setArticleName(articleName);
  -            a.setMinimumStock(100);
  -            a.setPrice(new BigDecimal(0.45));
  -            a.setProductGroupId(1);
  -            a.setStock(234);
  -            a.setSupplierId(4);
  -            a.setUnit("bottle");
  -            return a;
  -        }
  -
  -        /**
            * A resource cumbering insert-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  +         * this was used to test implementation.
            */
           public void insertNewArticlesStress(PerfArticle[] arr) throws Exception
           {
  @@ -126,8 +108,7 @@
   
           /**
            * A performance optimized insert-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  +         * used to test performance.
            */
           public void insertNewArticles(PerfArticle[] arr) throws Exception
           {
  @@ -173,8 +154,7 @@
   
           /**
            * A resource cumbering delete-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  +         * used to test implementation
            */
           public void deleteArticlesStress(PerfArticle[] arr) throws Exception
           {
  @@ -197,8 +177,7 @@
   
           /**
            * A performance optimized delete-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  +         * used to test performance
            */
           public void deleteArticles(PerfArticle[] arr) throws Exception
           {
  @@ -299,8 +278,7 @@
   
           /**
            * A performance optimized insert-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  +         * used to test performance
            */
           public void insertNewArticles(PerfArticle[] arr) throws Exception
           {
  @@ -314,8 +292,7 @@
   
           /**
            * A resource cumbering insert-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  +         * used to test implementation
            */
           public void insertNewArticlesStress(PerfArticle[] arr) throws Exception
           {
  @@ -342,8 +319,7 @@
   
           /**
            * A performance optimized delete-method implementation,
  -         * use this to test performance - set
  -         * {@link useStressMode} to <code>false</code>
  +         * use to test performance
            */
           public void deleteArticles(PerfArticle[] arr) throws Exception
           {
  @@ -357,8 +333,7 @@
   
           /**
            * A resource cumbering insert-method implementation,
  -         * use this to test implementation - set
  -         * {@link useStressMode} to <code>true</code>
  +         * use to test implementation
            */
           public void deleteArticlesStress(PerfArticle[] arr) throws Exception
           {
  @@ -369,24 +344,6 @@
                   db.deletePersistent(arr[i]);
                   tx.commit();
               }
  -        }
  -
  -        /**
  -         * factory method that creates an PerfArticle
  -         * @param articleName set the 'articleName'
  -         * @return the created PerfArticle object
  -         */
  -        public PerfArticle newPerfArticle(String articleName)
  -        {
  -            PerfArticle a = new PerfArticleImpl();
  -            a.setArticleName(articleName);
  -            a.setMinimumStock(100);
  -            a.setPrice(new BigDecimal(0.45));
  -            a.setProductGroupId(1);
  -            a.setStock(234);
  -            a.setSupplierId(4);
  -            a.setUnit("bottle");
  -            return a;
           }
       }
   }
  
  
  

Mime
View raw message