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/sequence SequenceManagerTest.java
Date Sun, 24 Jul 2005 23:57:42 GMT
arminw      2005/07/24 16:57:42

  Modified:    src/test/org/apache/ojb/broker/cache Tag: OJB_1_0_RELEASE
                        ObjectCacheTest.java
               src/test/org/apache/ojb/broker/sequence Tag: OJB_1_0_RELEASE
                        SequenceManagerTest.java
  Log:
  test improvements
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.1.2.2   +2 -2      db-ojb/src/test/org/apache/ojb/broker/cache/ObjectCacheTest.java
  
  Index: ObjectCacheTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/cache/ObjectCacheTest.java,v
  retrieving revision 1.1.2.1
  retrieving revision 1.1.2.2
  diff -u -r1.1.2.1 -r1.1.2.2
  --- ObjectCacheTest.java	23 Jan 2005 03:03:19 -0000	1.1.2.1
  +++ ObjectCacheTest.java	24 Jul 2005 23:57:42 -0000	1.1.2.2
  @@ -101,7 +101,7 @@
               bool = bool && cache.lookup(oid_3) != null;
               assertFalse("We should not found all cached objects", bool);
               // idle time is 2 sec
  -            Thread.sleep(3500);
  +            Thread.sleep(4000);
               assertNull(cache.lookup(oid_1));
               assertNull(cache.lookup(oid_2));
               assertNull(cache.lookup(oid_3));
  
  
  
  No                   revision
  No                   revision
  1.26.4.1  +64 -47    db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java
  
  Index: SequenceManagerTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/sequence/SequenceManagerTest.java,v
  retrieving revision 1.26
  retrieving revision 1.26.4.1
  diff -u -r1.26 -r1.26.4.1
  --- SequenceManagerTest.java	6 Nov 2003 01:38:16 -0000	1.26
  +++ SequenceManagerTest.java	24 Jul 2005 23:57:42 -0000	1.26.4.1
  @@ -1,8 +1,6 @@
   package org.apache.ojb.broker.sequence;
   
  -import junit.framework.TestCase;
   import org.apache.commons.lang.SerializationUtils;
  -import org.apache.ojb.broker.*;
   import org.apache.ojb.broker.metadata.ClassDescriptor;
   import org.apache.ojb.broker.metadata.DescriptorRepository;
   import org.apache.ojb.broker.metadata.FieldDescriptor;
  @@ -20,6 +18,16 @@
   import org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl;
   import org.apache.ojb.broker.util.sequence.SequenceManagerSeqHiLoImpl;
   import org.apache.ojb.broker.util.sequence.SequenceManagerStoredProcedureImpl;
  +import org.apache.ojb.broker.PersistenceBroker;
  +import org.apache.ojb.broker.PersistenceBrokerFactory;
  +import org.apache.ojb.broker.PBKey;
  +import org.apache.ojb.broker.TestHelper;
  +import org.apache.ojb.broker.PersistenceBrokerException;
  +import org.apache.ojb.broker.ObjectRepository;
  +import org.apache.ojb.broker.BookArticle;
  +import org.apache.ojb.broker.Article;
  +import org.apache.ojb.broker.CdArticle;
  +import org.apache.ojb.junit.OJBTestCase;
   
   import java.io.Serializable;
   import java.util.ArrayList;
  @@ -37,7 +45,7 @@
    * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
    * @version $Id$
    */
  -public class SequenceManagerTest extends TestCase
  +public class SequenceManagerTest extends OJBTestCase
   {
       private static final String TEST_SEQUENCE_NAME = "TEST_SEQUENCE";
       /**
  @@ -86,53 +94,12 @@
   
       protected void setUp() throws Exception
       {
  -        // we generate the keys only once
  -        if (generatedKeys == null) generatedKeys = new ArrayList();
  -        if (generatedKeys.size() > 1)
  -            return;
  -        else
  -        {
  -
  -            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            SequenceManager sm = broker.serviceSequenceManager();
  -            int seqGrabSize = 0;
  -            // we need the SM grab size
  -            if (sm instanceof SequenceManagerSeqHiLoImpl || sm instanceof SequenceManagerHighLowImpl)
  -            {
  -                SequenceDescriptor sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
  -                String strSize = sd.getAttribute(SequenceManagerHighLowImpl.PROPERTY_GRAB_SIZE);
  -                if (strSize != null)
  -                {
  -                    seqGrabSize = new Integer(strSize).intValue();
  -                }
  -            }
  -            broker.close();
  -
  -            // the grab size have to be a factor of the loops number
  -            // to pass the 'testForLostKeys' test because we
  -            if (loops < seqGrabSize) loops = seqGrabSize;
  -            if (seqGrabSize != 0) loops = (loops / seqGrabSize) * seqGrabSize;
  -
  -            brokers = new PersistenceBroker[instances];
  -            for (int i = 0; i < instances; i++)
  -            {
  -                brokers[i] = PersistenceBrokerFactory.defaultPersistenceBroker();
  -            }
  -            threadGroup = new ThreadGroup("sequenceManagerTG");
  -        }
  +        super.setUp();
       }
   
       protected void tearDown() throws Exception
       {
  -        if (brokers != null)
  -        {
  -            for (int i = 0; i < instances; i++)
  -            {
  -                brokers[i].close();
  -            }
  -        }
  -        threadGroup = null;
  -        brokers = null;
  +        super.tearDown();
       }
   
       /**
  @@ -667,6 +634,9 @@
       {
           // we generate the keys only once
           if (generatedKeys != null && generatedKeys.size() > 1) return;
  +
  +        prepareKeyGeneration();
  +        
           System.out.println(
                   this.getClass().getName() + ":\n" + instances + " threads generating "
+
                   loops + " keys per thread,\nusing target class " + targetClass);
  @@ -688,9 +658,56 @@
               {
               }
           }
  +
  +        cleanupKeyGeneration();
  +
           System.out.println("Generated keys: " + (generatedKeys != null ? "" + generatedKeys.size()
: "no keys generated"));
       }
   
  +    private void cleanupKeyGeneration()
  +    {
  +        if (brokers != null)
  +        {
  +            for (int i = 0; i < instances; i++)
  +            {
  +                brokers[i].close();
  +            }
  +        }
  +        threadGroup = null;
  +        brokers = null;
  +    }
  +
  +    private void prepareKeyGeneration()
  +    {
  +        if (generatedKeys == null) generatedKeys = new ArrayList();
  +        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        SequenceManager sm = broker.serviceSequenceManager();
  +        int seqGrabSize = 0;
  +        // we need the SM grab size
  +        if (sm instanceof SequenceManagerSeqHiLoImpl || sm instanceof SequenceManagerHighLowImpl)
  +        {
  +            SequenceDescriptor sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
  +            String strSize = sd.getAttribute(SequenceManagerHighLowImpl.PROPERTY_GRAB_SIZE);
  +            if (strSize != null)
  +            {
  +                seqGrabSize = new Integer(strSize).intValue();
  +            }
  +        }
  +        broker.close();
  +
  +        // the grab size have to be a factor of the loops number
  +        // to pass the 'testForLostKeys' test because we
  +        if (loops < seqGrabSize) loops = seqGrabSize;
  +        if (seqGrabSize != 0) loops = (loops / seqGrabSize) * seqGrabSize;
  +
  +        brokers = new PersistenceBroker[instances];
  +        for (int i = 0; i < instances; i++)
  +        {
  +            brokers[i] = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        }
  +        threadGroup = new ThreadGroup("sequenceManagerTG");
  +    }
  +
       private void analyseUniqueness(ArrayList results)
       {
           System.out.println(this.getClass().getName() + ": Analyse generated keys");
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message