db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: jakarta-ojb/src/test/org/apache/ojb/broker/metadata RuntimeConfigurationTest.java RepositoryPersistorTest.java MetadataTest.java
Date Fri, 31 Jan 2003 17:50:12 GMT
arminw      2003/01/31 09:50:11

  Modified:    src/test/org/apache/ojb/odmg LockingTest.java
               src/test/org/apache/ojb/broker PerformanceTest3.java
                        PerformanceTest2.java BlobTest.java AllTests.java
               src/test/org/apache/ojb/broker/metadata
                        RepositoryPersistorTest.java MetadataTest.java
  Added:       src/test/org/apache/ojb/broker
                        FieldConversionForeigenKeyTest.java
               src/test/org/apache/ojb/broker/metadata
                        RuntimeConfigurationTest.java
  Log:
  add new test cases, update test cases
  
  Revision  Changes    Path
  1.6       +109 -45   jakarta-ojb/src/test/org/apache/ojb/odmg/LockingTest.java
  
  Index: LockingTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/odmg/LockingTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LockingTest.java	16 Jan 2003 17:11:59 -0000	1.5
  +++ LockingTest.java	31 Jan 2003 17:50:02 -0000	1.6
  @@ -2,16 +2,19 @@
   
   
   import junit.framework.TestCase;
  +import org.apache.ojb.broker.PersistenceBroker;
   import org.apache.ojb.broker.PersistenceBrokerFactory;
   import org.apache.ojb.broker.TestHelper;
  -import org.apache.ojb.broker.singlevm.PersistenceBrokerConfiguration;
  -import org.apache.ojb.broker.util.configuration.ConfigurationException;
  -import org.apache.ojb.odmg.OJB;
  -import org.apache.ojb.odmg.TransactionImpl;
  +import org.apache.ojb.broker.query.Criteria;
  +import org.apache.ojb.broker.query.QueryFactory;
   import org.apache.ojb.odmg.locking.LockManager;
   import org.apache.ojb.odmg.locking.LockManagerFactory;
   import org.odmg.Database;
   import org.odmg.Implementation;
  +import org.odmg.OQLQuery;
  +import org.odmg.Transaction;
  +
  +import java.util.List;
   
   /** Demo Application that shows basic concepts for Applications using the OJB ODMG
    * implementation as an transactional object server.
  @@ -24,7 +27,13 @@
           junit.textui.TestRunner.main(arr);
       }
   
  -    private String databaseName;
  +    private static String PRE = "LockingTest_" + System.currentTimeMillis() + "_";
  +
  +    private Implementation odmg1 = OJB.getInstance();
  +    private Database db1 = odmg1.newDatabase();
  +
  +    private Implementation odmg2 = OJB.getInstance();
  +    private Database db2 = odmg2.newDatabase();
   
       /**
        * Insert the method's description here.
  @@ -40,67 +49,122 @@
        * Insert the method's description here.
        * Creation date: (06.12.2000 21:58:53)
        */
  -    public void setUp()
  +    public void setUp() throws Exception
       {
  -        databaseName = TestHelper.DEF_DATABASE_NAME;
  +        String databaseName = TestHelper.DEF_DATABASE_NAME;
  +
  +        odmg1 = OJB.getInstance();
  +        db1 = odmg1.newDatabase();
  +        db1.open(databaseName, Database.OPEN_READ_WRITE);
  +
  +        odmg2 = OJB.getInstance();
  +        db2 = odmg2.newDatabase();
  +        db2.open(databaseName, Database.OPEN_READ_WRITE);
  +
       }
   
       /**
        * Insert the method's description here.
        * Creation date: (06.12.2000 21:59:14)
        */
  -    public void tearDown()
  +    public void tearDown() throws Exception
       {
  -        try
  -        {
  -//            OJB.getInstance().currentTransaction().abort();
  -            OJB.getInstance().getDatabase(null).close();
  -            databaseName = null;
  +        if (odmg1.currentTransaction() != null) odmg1.currentTransaction().abort();
  +        db1.close();
   
  -
  -        }
  -        catch (Throwable t)
  -        {
  -        }
  +        if (odmg2.currentTransaction() != null) odmg2.currentTransaction().abort();
  +        db2.close();
       }
   
  -    public void testLockBasics()
  +    public void testLockBasics() throws Exception
       {
  +        TransactionImpl tx1 = (TransactionImpl) odmg1.newTransaction();
  +        TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
  +
  +        Article a = new Article();
  +        a.setArticleId(333);
  +
  +        tx1.begin();
  +        tx2.begin();
  +        LockManager lm = LockManagerFactory.getLockManager();
  +        boolean success1 = lm.writeLock(tx1, a);
  +        boolean success2 = lm.writeLock(tx2, a);
  +
  +        boolean success3 = lm.releaseLock(tx1, a);
  +
  +        assertTrue("1st lock should succeed", success1);
  +        assertTrue("2nd lock should not succeed", !success2);
  +        assertTrue("release should succeed", success3);
  +
           try
           {
  -            // get facade instance
  -            Implementation odmg = OJB.getInstance();
  -            Database db = odmg.newDatabase();
  -            //open database
  -            db.open(databaseName, Database.OPEN_READ_WRITE);
  -            TransactionImpl tx1 = (TransactionImpl) odmg.newTransaction();
  -            TransactionImpl tx2 = (TransactionImpl) odmg.newTransaction();
  -
  -            Article a = new Article();
  -            a.setArticleId(333);
  -
  -            tx1.begin();
  -            tx2.begin();
  -            LockManager lm = LockManagerFactory.getLockManager();
  -            boolean success1 = lm.writeLock(tx1, a);
  -            boolean success2 = lm.writeLock(tx2, a);
  -
  -            boolean success3 = lm.releaseLock(tx1, a);
  -
  -            assertTrue("1st lock should succeed", success1);
  -            assertTrue("2nd lock should not succeed", !success2);
  -            assertTrue("release should succeed", success3);
  -
               tx1.abort();
               tx2.abort();
  -
           }
  -        catch (Throwable ex)
  +        catch (Exception e)
           {
  -            fail(ex.getMessage());
           }
  +    }
  +
  +    /**
  +     * factory method that createa an PerformanceArticle
  +     * @return the created PerformanceArticle object
  +     */
  +    private Article createArticle(String name)
  +    {
  +        Article a = new Article();
   
  +        a.setArticleName(PRE + 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;
       }
   
  +    public void testLockLoop() throws Exception
  +    {
  +        int loops = 10;
  +        Article[] arr = new Article[loops];
  +        for (int i = 0; i < loops; i++)
  +        {
  +            Article a = createArticle("testLockLoop");
  +            arr[i] = a;
  +        }
  +
  +        TransactionImpl tx = (TransactionImpl) odmg1.newTransaction();
  +        tx.begin();
  +        for (int i = 0; i < arr.length; i++)
  +        {
  +            tx.lock(arr[i], Transaction.WRITE);
  +        }
  +        LockManager lm = LockManagerFactory.getLockManager();
  +        boolean success = lm.writeLock(tx, arr[(loops - 2)]);
  +        assertTrue("lock should succeed", success);
  +        tx.commit();
  +
  +        TransactionImpl tx2 = (TransactionImpl) odmg2.newTransaction();
  +        tx2.begin();
  +        success = lm.writeLock(tx2, arr[(loops - 2)]);
  +        assertTrue("lock should succeed", success);
  +
  +        OQLQuery query = odmg2.newOQLQuery();
  +        String sql = "select allArticles from " + Article.class.getName() +
  +                " where articleName = \"" + PRE + "testLockLoop" + "\"";
  +        query.create(sql);
  +        int result = ((List) query.execute()).size();
  +        tx2.commit();
  +        assertEquals("Wrong number of objects wrote to DB", loops, result);
  +
  +        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        broker.clearCache();
  +        Criteria crit = new Criteria();
  +        crit.addLike("articleName", PRE + "testLockLoop");
  +        result = broker.getCount(QueryFactory.newQuery(Article.class, crit));
  +        assertEquals("Wrong number of objects wrote to DB", loops, result);
  +    }
   
   }
  
  
  
  1.6       +67 -64    jakarta-ojb/src/test/org/apache/ojb/broker/PerformanceTest3.java
  
  Index: PerformanceTest3.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/PerformanceTest3.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PerformanceTest3.java	21 Dec 2002 16:34:30 -0000	1.5
  +++ PerformanceTest3.java	31 Jan 2003 17:50:03 -0000	1.6
  @@ -10,9 +10,12 @@
   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.broker.singlevm.PersistenceBrokerConfiguration;
   import org.apache.ojb.odmg.OJB;
  -import org.odmg.*;
  +import org.odmg.DList;
  +import org.odmg.Database;
  +import org.odmg.Implementation;
  +import org.odmg.OQLQuery;
  +import org.odmg.Transaction;
   
   import java.util.Iterator;
   
  @@ -23,8 +26,12 @@
    */
   public class PerformanceTest3
   {
  -    private static String repositoryFarAway = "repositoryFarAway.xml";
  -    private static PBKey pbKey_FarAway = new PBKey(repositoryFarAway);
  +    private static String databaseNameFarAway = TestHelper.FAR_AWAY_DATABASE_NAME;
  +    private static PBKey pbKey_FarAway = TestHelper.FAR_AWAY_KEY;
  +
  +    private static String databaseName = TestHelper.DEF_DATABASE_NAME;
  +    private static PBKey pbKey = TestHelper.DEF_KEY;
  +
       private static int iterationsPerThread = 1000;
       private static int concurrentThreads = 10;
       //used for client generated ids
  @@ -42,27 +49,22 @@
       private int threadCount;
       private Logger log = LoggerFactory.getLogger(PerformanceTest3.class);
       public ThreadGroup threadGroup = new ThreadGroup("PerfTest");
  -    private String repository;
  +//    private String repository;
   
       public PerformanceTest3()
       {
           this.threadCount = concurrentThreads;
  -        repository =
  -                    ((PersistenceBrokerConfiguration) PersistenceBrokerFactory
  -                    .getConfigurator()
  -                    .getConfigurationFor(null))
  -                    .getRepositoryFilename();
       }
   
       public static void main(String[] args)
       {
  -       int loops = args.length > 5 ? Integer.parseInt(args[5]) : 1;
  -        System.out.println("#######################################"+
  -                                "\n###  Start stress test - do "+loops+" loop  ###"+
  -                                "\n#######################################");
  -        for (int i = 0; i<loops; i++)
  +        int loops = args.length > 5 ? Integer.parseInt(args[5]) : 1;
  +        System.out.println("#######################################" +
  +                "\n###  Start stress test - do " + loops + " loop  ###" +
  +                "\n#######################################");
  +        for (int i = 0; i < loops; i++)
           {
  -            System.out.println("\n##  perform loop "+(i+1)+"   ##");
  +            System.out.println("\n##  perform loop " + (i + 1) + "   ##");
               performTest(args);
           }
           System.exit(0);
  @@ -88,7 +90,7 @@
           }
           if (args.length > 4)
           {
  -            repositoryFarAway = args[4];
  +            databaseNameFarAway = args[4];
           }
           try
           {
  @@ -98,17 +100,18 @@
               int objectCountFarAway = 0;
               int objectCountFarAwayAfter = 0;
   
  -            if (whichTest==1 || whichTest ==3)
  +            if (whichTest == 1 || whichTest == 3)
               {
   
  -                int activeThreadsStart = test.threadGroup.activeCount();test.init();
  +                int activeThreadsStart = test.threadGroup.activeCount();
  +                test.init();
                   objectCountDefault = test.getArticleCount();
                   objectCountFarAway = test.getFarAwayCount();
                   test.testMultithreaded_PB_api();
                   int count;
  -                while(test.threadGroup.activeCount()>activeThreadsStart)
  +                while (test.threadGroup.activeCount() > activeThreadsStart)
                   {
  -                    System.err.println("# active threads: "+ test.threadGroup.activeCount());
  +                    System.err.println("# active threads: " + test.threadGroup.activeCount());
                       try
                       {
                           Thread.sleep(1500);
  @@ -118,20 +121,20 @@
                       }
                   }
   
  -                System.err.println("Test-Info:   Objects in default DB before PB test: "+ objectCountDefault);
  +                System.err.println("Test-Info:   Objects in default DB before PB test: " + objectCountDefault);
                   objectCountDefaultAfter = test.getArticleCount();
  -                System.err.println("Test-Info:   Objects in default DB after PB test: "+objectCountDefaultAfter);
  +                System.err.println("Test-Info:   Objects in default DB after PB test: " + objectCountDefaultAfter);
   
  -                System.err.println("Test-Info:   Objects in farAway_DB before PB test: "+ objectCountFarAway);
  +                System.err.println("Test-Info:   Objects in farAway_DB before PB test: " + objectCountFarAway);
                   objectCountFarAwayAfter = test.getFarAwayCount();
  -                System.err.println("Test-Info:   Objects in farAway_DB after PB test: "+objectCountFarAwayAfter);
  +                System.err.println("Test-Info:   Objects in farAway_DB after PB test: " + objectCountFarAwayAfter);
   
  -                System.err.println("Test-Info:   Stress test was successful? - "+
  -                    (objectCountDefault==objectCountDefaultAfter && (objectCountFarAway==objectCountFarAwayAfter))+" -");
  +                System.err.println("Test-Info:   Stress test was successful? - " +
  +                        (objectCountDefault == objectCountDefaultAfter && (objectCountFarAway == objectCountFarAwayAfter)) + " -");
               }
   
   
  -            if (whichTest==2 || whichTest ==3)
  +            if (whichTest == 2 || whichTest == 3)
               {
                   int activeThreadsStart = test.threadGroup.activeCount();
                   test.init();
  @@ -139,9 +142,9 @@
                   objectCountFarAway = test.getFarAwayCount();
                   test.testMultithreaded_ODMG_api();
                   int count;
  -                while(test.threadGroup.activeCount()>activeThreadsStart)
  +                while (test.threadGroup.activeCount() > activeThreadsStart)
                   {
  -                    System.err.println("# active threads: "+ test.threadGroup.activeCount());
  +                    System.err.println("# active threads: " + test.threadGroup.activeCount());
                       try
                       {
                           Thread.sleep(1500);
  @@ -150,16 +153,16 @@
                       {
                       }
                   }
  -                System.err.println("Test-Info:   Objects in default DB before ODMG test: "+ objectCountDefault);
  +                System.err.println("Test-Info:   Objects in default DB before ODMG test: " + objectCountDefault);
                   objectCountDefaultAfter = test.getArticleCount();
  -                System.err.println("Test-Info:   Objects in default DB after ODMG test: "+objectCountDefaultAfter);
  +                System.err.println("Test-Info:   Objects in default DB after ODMG test: " + objectCountDefaultAfter);
   
  -                System.err.println("Test-Info:   Objects in farAway_DB before ODMG test: "+ objectCountFarAway);
  +                System.err.println("Test-Info:   Objects in farAway_DB before ODMG test: " + objectCountFarAway);
                   objectCountFarAwayAfter = test.getFarAwayCount();
  -                System.err.println("Test-Info:   Objects in farAway_DB after ODMG test: "+objectCountFarAwayAfter);
  +                System.err.println("Test-Info:   Objects in farAway_DB after ODMG test: " + objectCountFarAwayAfter);
   
  -                System.err.println("Test-Info:   Stress test was successful? - "+
  -                    (objectCountDefault==objectCountDefaultAfter && (objectCountFarAway==objectCountFarAwayAfter))+" -");
  +                System.err.println("Test-Info:   Stress test was successful? - " +
  +                        (objectCountDefault == objectCountDefaultAfter && (objectCountFarAway == objectCountFarAwayAfter)) + " -");
               }
           }
           catch (Exception e)
  @@ -198,7 +201,7 @@
       {
           String sep = System.getProperty("line.separator");
           times[0] = System.currentTimeMillis();
  -        log.info(sep+sep+"++ Start thread generation for PB api test ++");
  +        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++)
  @@ -215,7 +218,7 @@
           }
           times[0] = (long) (System.currentTimeMillis() - times[0]);
           log.info(buildTestSummary("PB API"));
  -        log.info("++ End of performance test PB api ++"+sep+sep);
  +        log.info("++ End of performance test PB api ++" + sep + sep);
       }
   
       public void testMultithreaded_ODMG_api()
  @@ -239,7 +242,7 @@
           }
           times[0] = (long) (System.currentTimeMillis() - times[0]);
           log.info(buildTestSummary("ODMG"));
  -        log.info("++ End of performance test ODMG api ++"+sep);
  +        log.info("++ End of performance test ODMG api ++" + sep);
       }
   
       private String buildTestSummary(String key)
  @@ -251,7 +254,7 @@
           buf.append(sep);
           buf.append("TEST SUMMARY - " + key);
           buf.append(sep);
  -        buf.append(concurrentThreads+" concurrent threads, handle " + iterationsPerThread + " articles per thread");
  +        buf.append(concurrentThreads + " concurrent threads, handle " + iterationsPerThread + " articles per thread");
           buf.append(sep);
           buf.append("Test period: " + (double) (((double) times[0]) / 1000) + " [sec]");
           buf.append(sep);
  @@ -333,7 +336,7 @@
           private PerformanceArticle createArticle(int id, String name)
           {
               PerformanceArticle a = new PerformanceArticle();
  -            if(clientKeyGeneration) a.setArticleId(getId());
  +            if (clientKeyGeneration) a.setArticleId(getId());
               a.setArticleName(PRE_NAME + name);
               a.setMinimumStock(100);
               a.setOrderedUnits(17);
  @@ -348,7 +351,7 @@
           private FarAwayClass createFarAwayObject(int i, String name)
           {
               FarAwayClass fa = new FarAwayClass();
  -            if(clientKeyGeneration) fa.setId(getId());
  +            if (clientKeyGeneration) fa.setId(getId());
               fa.setName(PRE_NAME + name);
               fa.setDescription("so far away from " + i);
               return fa;
  @@ -358,7 +361,7 @@
           {
               long start = System.currentTimeMillis();
               Database db = ojb.newDatabase();
  -            db.open(repository, Database.OPEN_READ_WRITE);
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
               for (int i = 0; i < arr.length; i++)
               {
                   Transaction tx = ojb.newTransaction();
  @@ -375,7 +378,7 @@
           {
               long start = System.currentTimeMillis();
               Database db = ojb.newDatabase();
  -            db.open(repositoryFarAway, Database.OPEN_READ_WRITE);
  +            db.open(databaseNameFarAway, Database.OPEN_READ_WRITE);
               for (int i = 0; i < arr.length; i++)
               {
                   Transaction tx = ojb.newTransaction();
  @@ -392,7 +395,7 @@
           {
               long start = System.currentTimeMillis();
               Database db = ojb.newDatabase();
  -            db.open(repository, Database.OPEN_READ_WRITE);
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
               for (int i = 0; i < arr.length; i++)
               {
                   Transaction tx = ojb.newTransaction();
  @@ -409,7 +412,7 @@
           {
               long start = System.currentTimeMillis();
               Database db = ojb.newDatabase();
  -            db.open(repositoryFarAway, Database.OPEN_READ_WRITE);
  +            db.open(databaseNameFarAway, Database.OPEN_READ_WRITE);
               for (int i = 0; i < arr.length; i++)
               {
                   Transaction tx = ojb.newTransaction();
  @@ -428,16 +431,17 @@
               int artId = arr[0].articleId;
   
               Database db = ojb.newDatabase();
  -            db.open(repository, Database.OPEN_READ_WRITE);
  -// for better performance we could read without a tx
  -//            Transaction tx = ojb.newTransaction();
  -//            tx.begin();
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
  +
  +            Transaction tx = ojb.newTransaction();
  +            tx.begin();
               OQLQuery query = ojb.newOQLQuery();
               String sql = "select allArticles from " + PerformanceArticle.class.getName() +
  -                    " where articleName = \"" + PRE_NAME + threadName+"\"";
  +                    " where articleName = \"" + PRE_NAME + threadName + "\"";
               query.create(sql);
               DList allProducts = (DList) query.execute();
  -//            tx.commit();
  +            tx.commit();
  +
               Iterator iter = allProducts.iterator();
               int fetchCount = 0;
               while (iter.hasNext())
  @@ -456,16 +460,15 @@
               int farAway_id = arrFarAway[0].getId();
   
               Database db = ojb.newDatabase();
  -            db.open(repositoryFarAway, Database.OPEN_READ_WRITE);
  -// for better performance we could read without a tx
  -//            Transaction tx = ojb.newTransaction();
  -//            tx.begin();
  +            db.open(databaseNameFarAway, Database.OPEN_READ_WRITE);
  +            Transaction tx = ojb.newTransaction();
  +            tx.begin();
               OQLQuery query = ojb.newOQLQuery();
               String sql = "select allFarAways from " + FarAwayClass.class.getName() +
  -                    " where name = \""+PRE_NAME+threadName+"\"";
  +                    " where name = \"" + PRE_NAME + threadName + "\"";
               query.create(sql);
               DList allFarAways = (DList) query.execute();
  -//            tx.commit();
  +            tx.commit();
               Iterator iter = allFarAways.iterator();
               int fetchCount = 0;
               while (iter.hasNext())
  @@ -541,7 +544,7 @@
           private PerformanceArticle createArticle(int id)
           {
               PerformanceArticle a = new PerformanceArticle();
  -            if(clientKeyGeneration) a.setArticleId(getId());
  +            if (clientKeyGeneration) a.setArticleId(getId());
               a.setArticleName("New Performance Article " + id);
               a.setMinimumStock(100);
               a.setOrderedUnits(17);
  @@ -556,7 +559,7 @@
           private FarAwayClass createFarAwayObject(int i)
           {
               FarAwayClass fa = new FarAwayClass();
  -            if(clientKeyGeneration) fa.setId(getId());
  +            if (clientKeyGeneration) fa.setId(getId());
               fa.setName("away from " + i);
               fa.setDescription("so far away from " + i);
               return fa;
  @@ -791,7 +794,7 @@
           times = new long[4];
           threadCount = concurrentThreads;
   
  -        if (whichTest==1 || whichTest ==3)
  +        if (whichTest == 1 || whichTest == 3)
           {
   //        log.info("Init PB-API");
               PerformanceArticle art = createArticle(1000);
  @@ -806,13 +809,13 @@
               broker.close();
           }
   
  -        if (whichTest==2 || whichTest ==3)
  +        if (whichTest == 2 || whichTest == 3)
           {
   //        log.info("Init ODMG-API");
               PerformanceArticle art2 = createArticle(1001);
               Implementation ojb = OJB.getInstance();
               Database db = ojb.newDatabase();
  -            db.open(repository, Database.OPEN_READ_WRITE);
  +            db.open(databaseName, Database.OPEN_READ_WRITE);
               Transaction tx = ojb.newTransaction();
               tx.begin();
               tx.lock(art2, Transaction.WRITE);
  @@ -833,7 +836,7 @@
       private PerformanceArticle createArticle(int id)
       {
           PerformanceArticle a = new PerformanceArticle();
  -        if(clientKeyGeneration) a.setArticleId(getId());
  +        if (clientKeyGeneration) a.setArticleId(getId());
           a.setArticleName("New Performance Article " + id);
           a.setMinimumStock(100);
           a.setOrderedUnits(17);
  
  
  
  1.14      +373 -278  jakarta-ojb/src/test/org/apache/ojb/broker/PerformanceTest2.java
  
  Index: PerformanceTest2.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/PerformanceTest2.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- PerformanceTest2.java	30 Jan 2003 18:15:24 -0000	1.13
  +++ PerformanceTest2.java	31 Jan 2003 17:50:04 -0000	1.14
  @@ -8,11 +8,10 @@
   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.Database;
   import org.odmg.Implementation;
  +import org.odmg.ODMGException;
   import org.odmg.OQLQuery;
   import org.odmg.Transaction;
   
  @@ -20,19 +19,68 @@
   import java.util.List;
   
   /**
  - * stress test against one database using several threads
  + * 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>
  + *
    *
    * @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
  @@ -42,7 +90,7 @@
        */
       private long[] testTimes;
       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;
   
  @@ -65,98 +113,33 @@
           System.exit(0);
       }
   
  -    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
  -    {
  -        log.info("init test");
  -        testTimes = new long[4];
  -        threadCount = concurrentThreads;
  -
  -        if (whichTest == 1 || whichTest == 3)
  -        {
  -            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)
  -        {
  -            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("init test end");
  -        }
  -    }
  -
       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();
  @@ -171,10 +154,10 @@
                   test.testMultithreaded_PB_api();
                   while (test.threadGroup.activeCount() > activeThreadsStart)
                   {
  -                    System.err.println("# active threads: " + test.threadGroup.activeCount());
  +                    System.out.println("# active threads: " + test.threadGroup.activeCount());
                       try
                       {
  -                        Thread.sleep(1500);
  +                        Thread.sleep(500);
                       }
                       catch (InterruptedException e)
                       {
  @@ -195,10 +178,10 @@
                   test.testMultithreaded_ODMG_api();
                   while (test.threadGroup.activeCount() > activeThreadsStart)
                   {
  -                    System.err.println("# active threads: " + test.threadGroup.activeCount());
  +                    System.out.println("# active threads: " + test.threadGroup.activeCount());
                       try
                       {
  -                        Thread.sleep(1500);
  +                        Thread.sleep(500);
                       }
                       catch (InterruptedException e)
                       {
  @@ -216,12 +199,55 @@
           }
       }
   
  +
  +    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();
  -        log.info(sep + sep + "++ Start thread generation for PB api test ++");
  -        log.info("Begin with performance test, " + concurrentThreads +
  +        System.out.println(PREFIX_LOG + sep + sep + "++ Start thread generation for PB api test ++");
  +        System.out.println(PREFIX_LOG + "Begin with performance test, " + concurrentThreads +
                   " concurrent threads, handle " + iterationsPerThread + " articles form each thread");
           for (int i = 0; i < concurrentThreads; i++)
           {
  @@ -237,16 +263,16 @@
               //cause we do not want to trace this loop
           }
           testTimes[0] = (long) (System.currentTimeMillis() - testTimes[0]);
  -        log.info(buildTestSummary("PB API"));
  -        log.info("++ End of performance test PB api ++" + sep + sep);
  +        System.out.println(PREFIX_LOG + buildTestSummary("PB API"));
  +        System.out.println(PREFIX_LOG + "++ End of performance test PB api ++" + sep + sep);
       }
   
       public void testMultithreaded_ODMG_api()
       {
           String sep = System.getProperty("line.separator");
           testTimes[0] = System.currentTimeMillis();
  -        log.info("++ Start thread generation for ODMG api test ++");
  -        log.info("Begin with performance test, " + concurrentThreads +
  +        System.out.println(PREFIX_LOG + "++ Start thread generation for ODMG api test ++");
  +        System.out.println(PREFIX_LOG + "Begin with performance test, " + concurrentThreads +
                   " concurrent threads, handle " + iterationsPerThread + " articles form each thread");
           for (int i = 0; i < concurrentThreads; i++)
           {
  @@ -261,27 +287,8 @@
               //cause we do not want to trace this loop
           }
           testTimes[0] = (long) (System.currentTimeMillis() - testTimes[0]);
  -        log.info(buildTestSummary("ODMG"));
  -        log.info("++ End of performance test ODMG api ++" + sep);
  -    }
  -
  -    /**
  -     * 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;
  +        System.out.println(PREFIX_LOG + buildTestSummary("ODMG"));
  +        System.out.println(PREFIX_LOG + "++ End of performance test ODMG api ++" + sep);
       }
   
       /**
  @@ -343,71 +350,81 @@
       /**
        * ODMG-api test class
        */
  -    class PerfomanceTestClientODMG implements Runnable
  +    class PerfomanceTestClientODMG extends PerfHandle
       {
  -        private static final String PRE_NAME = "ODMG_";
  -        private PerformanceArticle[] arr;
  +        private String objectName;
           private Implementation odmg;
  -        private String threadName;
           private Database db;
  +        private boolean notInit = true;
   
           public PerfomanceTestClientODMG()
           {
           }
   
  -        public void run()
  +        void init()
           {
  -            odmg = OJB.getInstance();
  -            threadName = Thread.currentThread().toString();
  -            arr = new PerformanceArticle[iterationsPerThread];
  -            for (int i = 0; i < iterationsPerThread; i++)
  -            {
  -                PerformanceArticle a = createArticle(threadName);
  -                arr[i] = a;
  -            }
  -
  -            //log.info("Thread "+this+" run");
               try
               {
  -                insertNewArticles();
  -                readArticlesByCursor();
  -                deleteArticles();
  +                odmg = OJB.getInstance();
  +                db = odmg.newDatabase();
  +                db.open(databaseName, Database.OPEN_READ_WRITE);
               }
  -            catch (Throwable e)
  +            catch (ODMGException e)
               {
  -                log.error("Error in client " + this, e);
  +                e.printStackTrace();
               }
  -            finally
  +        }
  +
  +        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++)
               {
  -                checkOut();
  -                activeThreads(true);
  +                tx.lock(arr[i], Transaction.WRITE);
               }
  +            tx.commit();
           }
   
           /**
  -         * factory method that createa an PerformanceArticle
  -         * @return the created PerformanceArticle object
  +         * A resource cumbering insert-method implementation,
  +         * use this to test implementation - set
  +         * {@link useStressMode} to <code>true</code>
            */
  -        private PerformanceArticle createArticle(String name)
  +        protected void insertNewArticlesStress() throws Exception
           {
  -            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;
  +            for (int i = 0; i < arr.length; i++)
  +            {
  +                Transaction tx = odmg.newTransaction();
  +                tx.begin();
  +                tx.lock(arr[i], Transaction.WRITE);
  +                tx.commit();
  +            }
           }
   
  +        /**
  +         * 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++)
  @@ -415,41 +432,31 @@
                   db.deletePersistent(arr[i]);
               }
               tx.commit();
  -            db.close();
  -            long stop = System.currentTimeMillis();
  -            addTime(3, stop - start);
           }
   
  -        protected void insertNewArticles() throws Exception
  +        /**
  +         * A resource cumbering insert-method implementation,
  +         * use this to test implementation - set
  +         * {@link useStressMode} to <code>true</code>
  +         */
  +        protected void deleteArticlesStress() 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++)
               {
  -                tx.lock(arr[i], Transaction.WRITE);
  +                Transaction tx = odmg.newTransaction();
  +                tx.begin();
  +                db.deletePersistent(arr[i]);
  +                tx.commit();
               }
  -            tx.commit();
  -            db.close();
  -            long stop = System.currentTimeMillis();
  -            addTime(1, stop - start);
           }
   
           protected void readArticlesByCursor() throws Exception
           {
  -            long start = System.currentTimeMillis();
  -            int artId = arr[0].articleId;
  -
  -            Database db = odmg.newDatabase();
  -            db.open(databaseName, Database.OPEN_READ_WRITE);
  -
               Transaction tx = odmg.newTransaction();
               tx.begin();
               OQLQuery query = odmg.newOQLQuery();
               String sql = "select allArticles from " + PerformanceArticle.class.getName() +
  -                    " where articleName = \"" + PRE_NAME + threadName + "\"";
  +                    " where articleName like \"" + objectName + "\"";
               query.create(sql);
               List allProducts = (List) query.execute();
               tx.commit();
  @@ -462,12 +469,9 @@
               }
               if (fetchCount != arr.length)
               {
  -                System.out.println("## Could not found all inserted objects, expected " +
  +                System.out.println("## Read objects: Could not found number of created objects, expected " +
                           (arr.length) + " found " + fetchCount + " ##");
               }
  -            db.close();
  -            long stop = System.currentTimeMillis();
  -            addTime(2, stop - start);
           }
       }
   
  @@ -480,69 +484,31 @@
       /**
        * PB-api test class
        */
  -    class PerfomanceTestClientPB implements Runnable
  +    class PerfomanceTestClientPB extends PerfHandle implements Runnable
       {
  -        private PerformanceArticle[] arr;
  -        private static final String PRE_NAME = "PB_";
  -        private String threadName;
  +        private String objectName;
   
           public PerfomanceTestClientPB()
           {
  -
           }
   
  -        public void run()
  +        String getTestObjectName()
           {
  -            threadName = Thread.currentThread().toString();
  -            arr = new PerformanceArticle[iterationsPerThread];
  -            for (int i = 0; i < iterationsPerThread; i++)
  -            {
  -                PerformanceArticle a = createArticle(threadName);
  -                arr[i] = a;
  -            }
  -
  -
  -            //log.info("Thread "+this+" run");
  -            try
  -            {
  -                insertNewArticles();
  -                readArticlesByCursor();
  -                deleteArticles();
  -            }
  -            catch (Throwable e)
  -            {
  -                log.error("Error in client " + this, e);
  -            }
  -            finally
  -            {
  -                checkOut();
  -                activeThreads(true);
  -            }
  +            if (objectName == null) objectName = "PB_" + Thread.currentThread().toString();
  +            return objectName;
           }
   
  -        /**
  -         * factory method that createa an PerformanceArticle
  -         * @return the created PerformanceArticle object
  -         */
  -        private PerformanceArticle createArticle(String name)
  +        void init() throws Exception
           {
  -            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;
           }
   
  -        protected void deleteArticles() throws Exception
  +        /**
  +         * A resource cumbering insert-method implementation,
  +         * use this to test implementation - set
  +         * {@link useStressMode} to <code>true</code>
  +         */
  +        protected void insertNewArticlesStress() throws Exception
           {
  -            long start = System.currentTimeMillis();
  -
               for (int i = 0; i < arr.length; i++)
               {
                   PersistenceBroker broker = null;
  @@ -550,78 +516,48 @@
                   {
                       broker = PersistenceBrokerFactory.defaultPersistenceBroker();
                       broker.beginTransaction();
  -                    broker.delete(arr[i]);
  +                    broker.store(arr[i]);
                       broker.commitTransaction();
                   }
                   finally
                   {
                       if (broker != null) broker.close();
                   }
  -            }
   
  -            long stop = System.currentTimeMillis();
  -            addTime(3, stop - start);
  +            }
           }
   
  -//        protected void deleteArticles() throws Exception
  -//        {
  -//            long start = System.currentTimeMillis();
  -//
  -//            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -//            try
  -//            {
  -//                broker.beginTransaction();
  -//                for (int i = 0; i < arr.length; 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);
  -
  -            long start = System.currentTimeMillis();
  -
  -            for (int i = 0; i < arr.length; i++)
  +            PersistenceBroker broker = null;
  +            try
               {
  -                PersistenceBroker broker = null;
  -                try
  +                broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                broker.serviceConnectionManager().setBatchMode(true);
  +                broker.beginTransaction();
  +                for (int i = 0; i < arr.length; i++)
                   {
  -                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -                    broker.beginTransaction();
                       broker.store(arr[i], needsInsert);
  -                    broker.commitTransaction();
                   }
  -                finally
  -                {
  -                    if (broker != null) broker.close();
  -                }
  -
  +                broker.commitTransaction();
  +            }
  +            finally
  +            {
  +                if (broker != null) broker.close();
               }
  -
  -            long stop = System.currentTimeMillis();
  -            addTime(1, stop - start);
           }
   
           protected void readArticlesByCursor() throws Exception
           {
  -            long start = System.currentTimeMillis();
  -            int artId = arr[0].articleId;
  -
               Criteria c = new Criteria();
  -            c.addLike("articleName", PRE_NAME+threadName);
  +            c.addLike("articleName", objectName);
               Query q = new QueryByCriteria(PerformanceArticle.class, c);
   
               PersistenceBroker broker = null;
  @@ -637,7 +573,7 @@
                   }
                   if (fetchCount != arr.length)
                   {
  -                    System.out.println("## Could not found all inserted objects, expected " +
  +                    System.out.println("## Read objects: Could not found number of created objects, expected " +
                               (arr.length) + " found " + fetchCount + " ##");
                   }
               }
  @@ -645,8 +581,167 @@
               {
                   if (broker != null) broker.close();
               }
  -            long stop = System.currentTimeMillis();
  -            addTime(2, stop - start);
  +        }
  +
  +        /**
  +         * 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;
  +                try
  +                {
  +                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                    broker.beginTransaction();
  +                    broker.delete(arr[i]);
  +                    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
  +        {
  +        }
  +    }
  +
  +
  +
  +    // =====================================================================================
  +    // 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()
  +        {
  +            arr = new PerformanceArticle[iterationsPerThread];
  +            for (int i = 0; i < iterationsPerThread; i++)
  +            {
  +                PerformanceArticle a = createArticle(getTestObjectName());
  +                arr[i] = a;
  +            }
  +
  +            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
  +                {
  +                    period = System.currentTimeMillis();
  +                    readArticlesByCursor();
  +                    period = System.currentTimeMillis() - period;
  +                    addTime(2, period);
  +                }
  +
  +                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);
  +            }
  +        }
  +
  +        /**
  +         * 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;
           }
       }
   }
  
  
  
  1.6       +93 -111   jakarta-ojb/src/test/org/apache/ojb/broker/BlobTest.java
  
  Index: BlobTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/BlobTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BlobTest.java	12 Dec 2002 20:16:04 -0000	1.5
  +++ BlobTest.java	31 Jan 2003 17:50:05 -0000	1.6
  @@ -1,121 +1,103 @@
   package org.apache.ojb.broker;
   
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.util.logging.LoggerFactory;
   
  -/** 
  +/**
    * This TestClass tests storimg and retrieving Objects with BLOB/CLOB Attributes.
    * Does currently not work with HSQLDB, as it doen't support Blobs/Clobs.
    */
   public class BlobTest extends TestCase
   {
  -	public static void main(String[] args)
  -	{
  -		String[] arr = { CLASS.getName()};
  -		junit.textui.TestRunner.main(arr);
  -	}
  -
  -	PersistenceBroker broker;
  -	private static Class CLASS = BlobTest.class;
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (24.12.2000 00:33:40)
  -	 */
  -	public BlobTest(String name)
  -	{
  -		super(name);
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:58:53)
  -	 */
  -	public void setUp() throws PBFactoryException
  -	{
  -		broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:59:14)
  -	 */
  -	public void tearDown()
  -	{
  -		try
  -		{
  -			broker.clearCache();
  -			broker.close();
  -		}
  -		catch (PersistenceBrokerException e)
  -		{
  -		}
  -	}
  -
  -	
  -
  -	/** Test optimistic Lock by timestamp.*/
  -	public void testBlobInsertion()
  -	{
  -	    int size = 5000;
  -		try
  -		{
  -			ObjectWithBlob obj = new ObjectWithBlob();
  -			
  -			byte[] barr = new byte[size];
  -			char[] carr = new char[size];
  -			for (int i = 0; i<size; i++)
  -			{
  -				barr[i] = (byte) 'x'; 
  -				carr[i] = 'y';  
  -			}
  -			
  -			obj.setId(1);
  -			obj.setBlob(barr);
  -			obj.setClob(carr);
  -			
  -			broker.store(obj);
  -			
  -			broker.clearCache();
  -			
  -			Identity oid = new Identity(obj);
  -			ObjectWithBlob obj1 = (ObjectWithBlob) broker.getObjectByIdentity(oid);
  -			
  -			assertEquals(obj.getBlob().length, obj1.getBlob().length);
  -			assertEquals(obj.getClob().length, obj1.getClob().length);
  -		}
  -		catch (Throwable t)
  -		{
  -		    LoggerFactory.getDefaultLogger().error(t);
  -			fail(t.getMessage());
  -		}
  -	}
  -	public void testReadNullBlob()
  -	{
  -		try
  -		{
  -			ObjectWithBlob obj = new ObjectWithBlob();
  -			
  -			obj.setId(1);
  -			obj.setBlob(null);
  -			obj.setClob(null);
  -			
  -			broker.store(obj);
  -			
  -			broker.clearCache();
  -			
  -			Identity oid = new Identity(obj);
  -                        ObjectWithBlob obj1 = (ObjectWithBlob) broker.getObjectByIdentity(oid);
  -			
  -			assertEquals(null, obj.getBlob());
  -			assertEquals(null, obj.getClob());
  -		}
  -		catch (Throwable t)
  -		{
  -		    LoggerFactory.getDefaultLogger().error(t);
  -			fail(t.getMessage());
  -		}
  -	}
  -
  -
  +    public static void main(String[] args)
  +    {
  +        String[] arr = {BlobTest.class.getName()};
  +        junit.textui.TestRunner.main(arr);
  +    }
  +
  +    private PersistenceBroker broker;
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (24.12.2000 00:33:40)
  +     */
  +    public BlobTest(String name)
  +    {
  +        super(name);
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (06.12.2000 21:58:53)
  +     */
  +    public void setUp() throws Exception
  +    {
  +        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (06.12.2000 21:59:14)
  +     */
  +    public void tearDown()
  +    {
  +        try
  +        {
  +            broker.clearCache();
  +            broker.close();
  +        }
  +        catch (PersistenceBrokerException e)
  +        {
  +        }
  +    }
  +
  +
  +    /** Test optimistic Lock by timestamp.*/
  +    public void testBlobInsertion() throws Exception
  +    {
  +        int size = 5000;
  +
  +        ObjectWithBlob obj = new ObjectWithBlob();
  +
  +        byte[] barr = new byte[size];
  +        char[] carr = new char[size];
  +        for (int i = 0; i < size; i++)
  +        {
  +            barr[i] = (byte) 'x';
  +            carr[i] = 'y';
  +        }
  +
  +        obj.setId(1);
  +        obj.setBlob(barr);
  +        obj.setClob(carr);
  +
  +        broker.store(obj);
  +
  +        broker.clearCache();
  +
  +        Identity oid = new Identity(obj, broker);
  +        ObjectWithBlob obj1 = (ObjectWithBlob) broker.getObjectByIdentity(oid);
  +
  +        assertEquals(obj.getBlob().length, obj1.getBlob().length);
  +        assertEquals(obj.getClob().length, obj1.getClob().length);
  +
  +    }
  +
  +    public void testReadNullBlob()
  +    {
  +        ObjectWithBlob obj = new ObjectWithBlob();
  +
  +        obj.setId(1);
  +        obj.setBlob(null);
  +        obj.setClob(null);
  +
  +        broker.store(obj);
  +
  +        broker.clearCache();
  +
  +        Identity oid = new Identity(obj, broker);
  +        ObjectWithBlob obj1 = (ObjectWithBlob) broker.getObjectByIdentity(oid);
  +
  +        assertEquals(null, obj.getBlob());
  +        assertEquals(null, obj.getClob());
  +    }
   }
  
  
  
  1.17      +60 -2     jakarta-ojb/src/test/org/apache/ojb/broker/AllTests.java
  
  Index: AllTests.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/AllTests.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AllTests.java	9 Jan 2003 17:20:14 -0000	1.16
  +++ AllTests.java	31 Jan 2003 17:50:05 -0000	1.17
  @@ -1,4 +1,62 @@
  -package org.apache.ojb.broker;
import org.apache.ojb.broker.metadata.*;
  +package org.apache.ojb.broker;
  +
  +import junit.framework.Test;
  +import junit.framework.TestSuite;
  +import org.apache.ojb.broker.metadata.CustomAttributesTest;
  +import org.apache.ojb.broker.metadata.MetadataTest;
  +import org.apache.ojb.broker.metadata.RepositoryPersistorTest;
   import org.apache.ojb.broker.sequence.SequenceManagerTest;
   
  -import junit.framework.Test;
import junit.framework.TestSuite;

/**
 * the facade to all TestCases in this package.
 *
 * @author: Thomas Mahler
 */
public class AllTests extends junit.framework.TestSuite
{
    /** static reference to .class.
     * Java does not provide any way to obtain the Class object from
     * static method without naming it.
     */
     private static Class CLASS = AllTests.class;

    /**
     * runs the suite in a junit.textui.TestRunner.
     */
     public static void main(String[] args)
    {
        String[] arr = { CLASS.getName()};
        junit.textui.TestRunner.main(arr);
    }

    /** build a TestSuite from all the TestCases in this package*/
    public static Test suite()
    {
        TestSuite suite = new TestSuite();
        suite.addTest(new TestSuite(PersistenceBrokerTest.class));
        suite.addTest(new TestSuite(BrokerExamples.class));
        suite.addTest(new TestSuite(ProxyExamples.class));
        suite.addTest(new TestSuite(PolymorphicExtents.class));
        suite.addTest(new TestSuite(TreeTest.class));
        suite.addTest(new TestSuite(TypedCollectionsTest.class));
        suite.addTest(new TestSuite(MtoNMapping.class));
        suite.addTest(new TestSuite(AutomaticForeignKeys.class));
        suite.addTest(new TestSuite(OptimisticLockingTest.class));
        suite.addTest(new TestSuite(QueryTest.class));
        suite.addTest(new TestSuite(GraphTest.class));
    	suite.addTest(new TestSuite(PBAwareTest.class));
        suite.addTest(new TestSuite(ContractVersionEffectivenessTest.class));
        suite.addTest(new TestSuite(ComplexMultiMappedTableTest.class));
        suite.addTest(new TestSuite(ComplexMultiMappedTableWithCollectionByQueryTest.class));
        suite.addTest(new TestSuite(BidirectionalAssociationTest.class));
        suite.addTest(new TestSuite(AutoIncrementWithRelatedObjectTest.class));
        suite.addTest(new TestSuite(OneToManyTest.class));
        suite.addTest(new TestSuite(PBRollbackTest.class));
        suite.addTest(new TestSuite(TransactionDemarcationTest.class));
        suite.addTest(new TestSuite(MultipleDBTest.class));
        suite.addTest(new TestSuite(RepositoryPersistorTest.class));
        suite.addTest(new TestSuite(CustomAttributesTest.class));
        suite.addTest(new TestSuite(SequenceManagerTest.class));
        suite.addTest(new TestSuite(ConvertedKeyReferenceTest.class));
		suite.addTest(new TestSuite(KeyConstraintViolationTest.class));
		suite.addTest(new TestSuite(RsIteratorTest.class));
		//suite.addTest(new TestSuite(BlobTest.class)); /* doesn't work for hsqldb */
		suite.addTest(new TestSuite(LogServiceTest.class));
		suite.addTest(new TestSuite(ManyToManyTest.class));
		suite.addTest(new TestSuite(OneToOneTest.class));
		suite.addTest(new TestSuite(MetaDataSerializationTest.class));
		suite.addTest(new TestSuite(MetadataTest.class));
        return suite;
    }

}
  \ No newline at end of file
  +/**
 * the facade to all TestCases in this package.
 *
 * @author: Thomas Mahler
 */
  +public class AllTests extends junit.framework.TestSuite
  +{
  +    /** static reference to .class.
     * Java does not provide any way to obtain the Class object from
     * static method without naming it.
     */
  +    private static Class CLASS = AllTests.class;
  +
  +    /**
     * runs the suite in a junit.textui.TestRunner.
     */
  +    public static void main(String[] args)
  +    {
  +        String[] arr = {CLASS.getName()};
  +        junit.textui.TestRunner.main(arr);
  +    }
  +
  +    /** build a TestSuite from all the TestCases in this package*/
  +    public static Test suite()
  +    {
  +        TestSuite suite = new TestSuite();
  +        suite.addTest(new TestSuite(PersistenceBrokerTest.class));
  +        suite.addTest(new TestSuite(BrokerExamples.class));
  +        suite.addTest(new TestSuite(ProxyExamples.class));
  +        suite.addTest(new TestSuite(PolymorphicExtents.class));
  +        suite.addTest(new TestSuite(TreeTest.class));
  +        suite.addTest(new TestSuite(TypedCollectionsTest.class));
  +        suite.addTest(new TestSuite(MtoNMapping.class));
  +        suite.addTest(new TestSuite(AutomaticForeignKeys.class));
  +        suite.addTest(new TestSuite(OptimisticLockingTest.class));
  +        suite.addTest(new TestSuite(QueryTest.class));
  +        suite.addTest(new TestSuite(GraphTest.class));
  +        suite.addTest(new TestSuite(PBAwareTest.class));
  +        suite.addTest(new TestSuite(ContractVersionEffectivenessTest.class));
  +        suite.addTest(new TestSuite(ComplexMultiMappedTableTest.class));
  +        suite.addTest(new TestSuite(ComplexMultiMappedTableWithCollectionByQueryTest.class));
  +        suite.addTest(new TestSuite(BidirectionalAssociationTest.class));
  +        suite.addTest(new TestSuite(AutoIncrementWithRelatedObjectTest.class));
  +        suite.addTest(new TestSuite(OneToManyTest.class));
  +        suite.addTest(new TestSuite(PBRollbackTest.class));
  +        suite.addTest(new TestSuite(TransactionDemarcationTest.class));
  +        suite.addTest(new TestSuite(MultipleDBTest.class));
  +        suite.addTest(new TestSuite(RepositoryPersistorTest.class));
  +        suite.addTest(new TestSuite(CustomAttributesTest.class));
  +        suite.addTest(new TestSuite(SequenceManagerTest.class));
  +        suite.addTest(new TestSuite(ConvertedKeyReferenceTest.class));
  +        suite.addTest(new TestSuite(KeyConstraintViolationTest.class));
  +        suite.addTest(new TestSuite(RsIteratorTest.class));
        //suite.addTest(new TestSuite(BlobTest.class)); /* doesn't work for hsqldb */
        suite.addTest(new TestSuite(LogServiceTest.class));
  +        suite.addTest(new TestSuite(ManyToManyTest.class));
  +        suite.addTest(new TestSuite(OneToOneTest.class));
  +        suite.addTest(new TestSuite(MetaDataSerializationTest.class));
  +        suite.addTest(new TestSuite(MetadataTest.class));
  +        suite.addTest(new TestSuite(FieldConversionForeigenKeyTest.class));
  +        return suite;
  +    }
  +
  +}
  \ No newline at end of file
  
  
  
  1.1                  jakarta-ojb/src/test/org/apache/ojb/broker/FieldConversionForeigenKeyTest.java
  
  Index: FieldConversionForeigenKeyTest.java
  ===================================================================
  /**
   * (C) 2003 ppi Media
   * User: om
   */
  
  package org.apache.ojb.broker;
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.query.Criteria;
  import org.apache.ojb.broker.query.QueryFactory;
  import org.apache.ojb.odmg.FieldConversion_Node;
  
  /**
   * Test using field conversion from <code>long</code>
   * to <code>BigDecimal</code>.
   *
   * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
   * @version $Id: FieldConversionForeigenKeyTest.java,v 1.1 2003/01/31 17:50:05 arminw Exp $
   */
  public class FieldConversionForeigenKeyTest extends TestCase
  {
      public static void main(String[] args)
      {
          String[] arr = {FieldConversionForeigenKeyTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      private PersistenceBroker broker;
  
      /**
       * Insert the method's description here.
       * Creation date: (06.12.2000 21:58:53)
       */
      public void setUp() throws PBFactoryException
      {
  
          broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  
      }
  
      /**
       * Insert the method's description here.
       * Creation date: (06.12.2000 21:59:14)
       */
      public void tearDown()
      {
  
          try
          {
              broker.clearCache();
              broker.close();
          }
          catch (PersistenceBrokerException e)
          {
          }
  
      }
  
      public void testStoreNode() throws Exception
      {
          String strQuery = "select allNodes from " + FieldConversion_Node.class.getName();
          long id = System.currentTimeMillis();
          FieldConversion_Node node = new FieldConversion_Node(id, null);
          FieldConversion_Node child = new FieldConversion_Node(id + 1, node);
  
          int before;
  
          broker.beginTransaction();
          before = broker.getCount(QueryFactory.newQuery(FieldConversion_Node.class, (Criteria) null));
  
          broker.store(child);
  
          broker.commitTransaction();
  
          broker.beginTransaction();
          int after = broker.getCount(QueryFactory.newQuery(FieldConversion_Node.class, (Criteria) null));
          broker.commitTransaction();
  
          assertFalse(after == 0);
          assertEquals(before + 2, after);
  
      }
  }
  
  
  
  1.8       +3 -1      jakarta-ojb/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java
  
  Index: RepositoryPersistorTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/metadata/RepositoryPersistorTest.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- RepositoryPersistorTest.java	9 Jan 2003 17:20:15 -0000	1.7
  +++ RepositoryPersistorTest.java	31 Jan 2003 17:50:07 -0000	1.8
  @@ -1,6 +1,7 @@
   package org.apache.ojb.broker.metadata;
   
   import java.util.Iterator;
  +import java.io.FileOutputStream;
   
   import junit.framework.TestCase;
   import org.apache.ojb.broker.TestHelper;
  @@ -58,7 +59,8 @@
           }
   
           RepositoryPersistor persistor = new RepositoryPersistor();
  -        persistor.writeToFile(repository, conRepository, filename);
  +        FileOutputStream fos = new FileOutputStream(filename);
  +        persistor.writeToFile(repository, conRepository, fos);
   
           DescriptorRepository second = persistor.readDescriptorRepository(filename);
           iter = second.iterator();
  
  
  
  1.3       +218 -37   jakarta-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java
  
  Index: MetadataTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/metadata/MetadataTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MetadataTest.java	9 Jan 2003 23:58:34 -0000	1.2
  +++ MetadataTest.java	31 Jan 2003 17:50:07 -0000	1.3
  @@ -1,54 +1,235 @@
   package org.apache.ojb.broker.metadata;
   
  -import java.util.Iterator;
  -
   import junit.framework.TestCase;
  -import org.apache.ojb.broker.TestHelper;
   import org.apache.ojb.broker.PBKey;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.PBFactoryException;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.sequence.SMMaxA;
   import org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImpl;
   
  +import java.util.Iterator;
  +
   /**
    * This TestClass tests the RepositoryPersitors facilities for
    * reading and writing a valid repository.
    */
   public class MetadataTest extends TestCase
   {
  -	public static void main(String[] args)
  -	{
  -		String[] arr = { MetadataTest.class.getName()};
  -		junit.textui.TestRunner.main(arr);
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (24.12.2000 00:33:40)
  -	 */
  -	public MetadataTest(String name)
  -	{
  -		super(name);
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:58:53)
  -	 */
  -	public void setUp()
  -	{
  -	}
  -
  -	/**
  -	 * Insert the method's description here.
  -	 * Creation date: (06.12.2000 21:59:14)
  -	 */
  -	public void tearDown()
  -	{
  +    public static void main(String[] args)
  +    {
  +        String[] arr = {MetadataTest.class.getName()};
  +        junit.textui.TestRunner.main(arr);
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (24.12.2000 00:33:40)
  +     */
  +    public MetadataTest(String name)
  +    {
  +        super(name);
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (06.12.2000 21:58:53)
  +     */
  +    public void setUp()
  +    {
  +    }
  +
  +    /**
  +     * Insert the method's description here.
  +     * Creation date: (06.12.2000 21:59:14)
  +     */
  +    public void tearDown()
  +    {
  +
  +    }
  +
  +    public void testRuntimeMetadataChanges() throws Exception
  +    {
  +        int loops = 10;
  +        // enable the per thread changes of metadata
  +        MetadataManager.getInstance().setEnablePerThreadChanges(true);
  +        long period = System.currentTimeMillis();
  +        GlobalUsingBroker gub = new GlobalUsingBroker(loops);
  +        ThreadedUsingBroker tub = new ThreadedUsingBroker(loops);
  +        ThreadGroup metadata = new ThreadGroup("metadata");
  +        new Thread(metadata, gub).start();
  +        new Thread(metadata, tub).start();
  +        while(metadata.activeCount() > 0)
  +        {
  +            Thread.sleep(50);
  +        }
  +        period = System.currentTimeMillis() - period;
  +        System.out.println("RuntimeMetadataChanges test take: "+period+" ms");
  +        MetadataManager.getInstance().setEnablePerThreadChanges(false);
  +
  +        PersistenceBroker broker = null;
  +        try
  +        {
  +            broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            ClassDescriptor cld = broker.getClassDescriptor(SMMaxA.class);
  +            String name = cld.getClassNameOfObject();
  +            assertEquals(SMMaxA.class.getName(), name);
  +            assertFalse(MetadataManager.getInstance().isEnablePerThreadChanges());
  +        }
  +        finally
  +        {
  +            if(broker != null) broker.close();
  +        }
  +    }
   
  -	}
  +    class GlobalUsingBroker implements Runnable
  +    {
  +        int loops;
  +
  +        public GlobalUsingBroker(int loops)
  +        {
  +            this.loops = loops;
  +        }
  +
  +        public void run()
  +        {
  +            PersistenceBroker broker = null;
  +            int k =0;
  +            try
  +            {
  +                while (k<loops)
  +                {
  +                    try
  +                    {
  +                        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                        ClassDescriptor cld = broker.getClassDescriptor(SMMaxA.class);
  +                        String name = cld.getClassNameOfObject();
  +                        assertEquals(SMMaxA.class.getName(), name);
  +                        assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
  +                    }
  +                    finally
  +                    {
  +                        if(broker != null) broker.close();
  +                    }
  +                    try
  +                    {
  +                        broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                        ClassDescriptor cld = broker.getClassDescriptor(SMMaxA.class);
  +                        String name = cld.getClassNameOfObject();
  +                        assertEquals(SMMaxA.class.getName(), name);
  +                        // System.out.println("Default: found "+name);
  +                    }
  +                    finally
  +                    {
  +                        if(broker != null) broker.close();
  +                    }
  +
  +                    k++;
  +                    try
  +                    {
  +                        Thread.sleep(50);
  +                    }
  +                    catch (InterruptedException e)
  +                    {
  +                    }
  +                }
  +            }
  +            catch (PBFactoryException e)
  +            {
  +                e.printStackTrace();
  +            }
  +            catch (PersistenceBrokerException e)
  +            {
  +            }
  +        }
  +    }
  +
  +    class ThreadedUsingBroker implements Runnable
  +    {
  +        int loops;
  +
  +        public ThreadedUsingBroker(int loops)
  +        {
  +            this.loops = loops;
  +        }
  +
  +        public void run()
  +        {
  +            DescriptorRepository dr = MetadataManager.getInstance().copyOfGlobalRepository();
  +            ClassDescriptor cld = dr.getDescriptorFor(SMMaxA.class);
  +            // we change the class descriptor
  +            cld.setClassOfObject(null);
  +            // set the changed repository for this thread
  +            MetadataManager.getInstance().setPerThreadDescriptor(dr);
  +
  +            int k = 0;
  +            while (k<loops)
  +            {
  +                PersistenceBroker broker = null;
  +                try
  +                {
  +                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                    cld = broker.getClassDescriptor(SMMaxA.class);
  +                    String name = cld.getClassNameOfObject();
  +                    assertNull(name);
  +                    assertTrue(MetadataManager.getInstance().isEnablePerThreadChanges());
  +                }
  +                finally
  +                {
  +                    if(broker != null) broker.close();
  +                }
  +
  +                try
  +                {
  +                    broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +                    cld = broker.getClassDescriptor(SMMaxA.class);
  +                    String name = cld.getClassNameOfObject();
  +                    assertNull(name);
  +                    // System.out.println("Changed: found "+name);
  +                }
  +                finally
  +                {
  +                    if(broker != null) broker.close();
  +                }
  +
  +                k++;
  +                try
  +                {
  +                    Thread.sleep(50);
  +                }
  +                catch (InterruptedException e)
  +                {
  +                }
  +            }
  +
  +        }
  +    }
  +
  +    public void testTimeToCopyRepository()
  +    {
  +        DescriptorRepository dr = null;
  +        int loop = 5;
  +        long period = System.currentTimeMillis();
  +        for (int i = 0; i < loop; i++)
  +        {
  +            dr = MetadataManager.getInstance().copyOfGlobalRepository();
  +        }
  +        period = System.currentTimeMillis() - period;
  +        int descriptors = 0;
  +        Iterator it = dr.iterator();
  +        while (it.hasNext())
  +        {
  +            it.next();
  +            ++descriptors;
  +        }
  +        System.out.println("# Time to create a copy of "+ descriptors +" class-descriptors: " + period/loop + " ms #");
  +    }
   
  -	public void testReadConnectionDescriptor()
  +    public void testReadConnectionDescriptor()
       {
           JdbcConnectionDescriptor jcd = MetadataManager.getInstance().connectionRepository().
  -                                        getDescriptor(new PBKey("testConnection", "a user", "a password"));
  +                getDescriptor(new PBKey("testConnection", "a user", "a password"));
           /* descriptor snip
   
           <jdbc-connection-descriptor
  @@ -90,8 +271,8 @@
           </sequence-manager>
       </jdbc-connection-descriptor>
           */
  -	// don't set it to true!!! This may break everything (2 default connections)
  -        assertEquals(false, jcd.isDefaultConnection()); 
  +        // don't set it to true!!! This may break everything (2 default connections)
  +        assertEquals(false, jcd.isDefaultConnection());
   
           assertNotNull(jcd.getDbms());
           assertEquals("Oracle", jcd.getDbms());
  
  
  
  1.1                  jakarta-ojb/src/test/org/apache/ojb/broker/metadata/RuntimeConfigurationTest.java
  
  Index: RuntimeConfigurationTest.java
  ===================================================================
  package org.apache.ojb.broker.metadata;
  
  import junit.framework.TestCase;
  import org.apache.ojb.broker.A;
  import org.apache.ojb.broker.PersistenceBrokerFactory;
  import org.apache.ojb.broker.PersistenceBroker;
  import org.apache.ojb.broker.query.QueryFactory;
  import org.apache.ojb.broker.query.Query;
  import org.apache.ojb.broker.query.Criteria;
  
  /**
   * Test used to check if it is possible to start OJB
   * without defined descriptors.
   * Before running this test delete/comment out all
   * jdbc-connection-descriptors, class-descriptors in the
   * repository file.
   *
   * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
   * @version $Id: RuntimeConfigurationTest.java,v 1.1 2003/01/31 17:50:07 arminw Exp $
   */
  public class RuntimeConfigurationTest extends TestCase
  {
      public RuntimeConfigurationTest()
      {
      }
  
      public RuntimeConfigurationTest(String s)
      {
          super(s);
      }
  
      public static void main(String[] args)
      {
          String[] arr = {RuntimeConfigurationTest.class.getName()};
          junit.textui.TestRunner.main(arr);
      }
  
      public void testStartWithout() throws Exception
      {
          ConnectionRepository cr = MetadataManager.getInstance().connectionRepository();
          System.out.println("ConnectionRepository before add: "+cr.toXML());
          JdbcConnectionDescriptor jcd = new JdbcConnectionDescriptor();
          jcd.setDbAlias("test");
          jcd.setDbms("test2");
          jcd.setDefaultConnection(true);
          cr.addDescriptor(jcd);
          System.out.println("ConnectionRepository after add: "+cr.toXML());
  
          DescriptorRepository dr = MetadataManager.getInstance().getRepository();
          System.out.println("DescriptorRepository before add: "+dr.toXML());
          ClassDescriptor cld = new ClassDescriptor(dr);
          cld.setClassOfObject(A.class);
          FieldDescriptor fd = new FieldDescriptor(cld, 1);
          fd.setPersistentField(A.class, "someAField");
          cld.addFieldDescriptor(fd);
  
          dr.setClassDescriptor(cld);
          System.out.println("DescriptorRepository after add: "+dr.toXML());
          PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
          broker.close();
  //        Query query = QueryFactory.newQuery(A.class, (Criteria)null);
  //        broker.getCollectionByQuery(query);
      }
  }
  
  
  

Mime
View raw message