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 ObjectCacheTest.java
Date Sun, 04 Jan 2004 23:51:40 GMT
arminw      2004/01/04 15:51:40

  Modified:    src/test/org/apache/ojb/broker ObjectCacheTest.java
  Log:
  fix test cases
  
  Revision  Changes    Path
  1.13      +62 -53    db-ojb/src/test/org/apache/ojb/broker/ObjectCacheTest.java
  
  Index: ObjectCacheTest.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/broker/ObjectCacheTest.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- ObjectCacheTest.java	31 Dec 2003 12:01:56 -0000	1.12
  +++ ObjectCacheTest.java	4 Jan 2004 23:51:40 -0000	1.13
  @@ -1,5 +1,8 @@
   package org.apache.ojb.broker;
   
  +import java.io.Serializable;
  +import java.util.Properties;
  +
   import junit.framework.TestCase;
   import org.apache.ojb.broker.cache.CacheFilterClassImpl;
   import org.apache.ojb.broker.cache.CacheFilterPackageImpl;
  @@ -8,20 +11,19 @@
   import org.apache.ojb.broker.cache.ObjectCacheFactory;
   import org.apache.ojb.broker.cache.ObjectCacheJCSImpl;
   import org.apache.ojb.broker.cache.ObjectCacheJCSPerClassImpl;
  +import org.apache.ojb.broker.cache.ObjectCacheLocalDefaultImpl;
   import org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl;
   import org.apache.ojb.broker.cache.ObjectCachePerClassImpl;
  -import org.apache.ojb.broker.cache.ObjectCacheLocalDefaultImpl;
   import org.apache.ojb.broker.metadata.ConnectionRepository;
   import org.apache.ojb.broker.metadata.MetadataManager;
   import org.apache.ojb.broker.metadata.MetadataTest;
   import org.apache.ojb.broker.query.QueryByIdentity;
   import org.apache.ojb.broker.sequence.Repository;
  +import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.GUID;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
   import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
   
  -import java.io.Serializable;
  -
   /**
    * Do some basic tests using ObjectCache implementations.
    *
  @@ -97,8 +99,7 @@
           PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
           try
           {
  -            ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheJCSPerClassImpl.class);
  -            ObjectCache cache = ObjectCacheFactory.getInstance().createObjectCache(broker);
  +            ObjectCache cache = new ObjectCacheJCSPerClassImpl(broker, null);
   
               CacheObject obj_1 = new CacheObject(null, "testJCSPerClassObjectCacheImplementation_1");
               Identity oid_1 = new Identity(obj_1, broker);
  @@ -205,18 +206,20 @@
        */
       public void testCacheFilterFunctions() throws Exception
       {
  -        getConfig().setCacheFilters(cacheFilter);
  -        MetadataManager.getInstance().getRepository().
  -                addAttribute(CacheFilterPackageImpl.EXCLUDE_PACKAGES, EXCLUDE_PACKAGE);
  -        MetadataManager.getInstance().connectionRepository().getDescriptor(TestHelper.DEF_KEY).
  -                addAttribute(CacheFilterPackageImpl.EXCLUDE_PACKAGES, EXCLUDE_PACKAGE_NOT_EXIST);
  -        for (int i = 0; i < objectCacheImpls.length; i++)
  +        PersistenceBrokerFactory.releaseAllInstances();
  +
  +        try
           {
  -            ObjectCacheFactory.getInstance().setClassToServe(objectCacheImpls[i]);
  +            getConfig().setCacheFilters(cacheFilter);
  +            MetadataManager.getInstance().getRepository().
  +                    addAttribute(CacheFilterPackageImpl.EXCLUDE_PACKAGES, EXCLUDE_PACKAGE);
  +            MetadataManager.getInstance().connectionRepository().getDescriptor(TestHelper.DEF_KEY).
  +                    addAttribute(CacheFilterPackageImpl.EXCLUDE_PACKAGES, EXCLUDE_PACKAGE_NOT_EXIST);
  +
               PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
               try
               {
  -                ObjectCache cache = ObjectCacheFactory.getInstance().createObjectCache(broker);
  +                ObjectCache cache = broker.serviceObjectCache();
                   CacheObject obj = new CacheObject(null, "CacheObject persistent obj");
                   Identity oid = new Identity(obj, broker);
   
  @@ -255,6 +258,10 @@
                   if (broker != null) broker.close();
               }
           }
  +        finally
  +        {
  +            PersistenceBrokerFactory.releaseAllInstances();
  +        }
       }
   
       /**
  @@ -266,8 +273,19 @@
       {
           for (int i = 0; i < objectCacheImpls.length; i++)
           {
  -            ObjectCacheFactory.getInstance().setClassToServe(objectCacheImpls[i]);
  -            checkBaseFunctions();
  +            PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +            try
  +            {
  +                ObjectCache cache = (ObjectCache) ClassHelper.newInstance(
  +                            objectCacheImpls[i],
  +                            new Class[] {PersistenceBroker.class,Properties.class},
  +                            new Object[] {broker, null});
  +                checkBaseFunctions(broker, cache);
  +            }
  +            finally
  +            {
  +                if (broker != null) broker.close();
  +            }
           }
       }
   
  @@ -277,44 +295,35 @@
        *
        * @throws Exception
        */
  -    private void checkBaseFunctions() throws Exception
  +    private void checkBaseFunctions(PersistenceBroker broker, ObjectCache cache) throws
Exception
       {
  -        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        try
  -        {
  -            ObjectCache cache = ObjectCacheFactory.getInstance().createObjectCache(broker);
  -            CacheObject obj = new CacheObject(null, "ObjectCache test");
  -            Identity oid = new Identity(obj, broker);
  -            CacheObject obj2 = new CacheObject(null, "ObjectCache test 2");
  -            Identity oid2 = new Identity(obj2, broker);
  -            cache.clear();
  -            Object result = cache.lookup(oid);
  -            assertNull(result);
  -
  -            cache.cache(oid, obj);
  -            cache.cache(oid2, obj2);
  -            result = cache.lookup(oid);
  -            assertNotNull(result);
  -            assertEquals(obj, result);
  -            assertNotSame(obj2, result);
  -
  -            cache.remove(oid);
  -            result = cache.lookup(oid);
  -            Object result2 = cache.lookup(oid2);
  -            assertNull(result);
  -            assertNotNull(result2);
  -
  -            cache.clear();
  -            result = cache.lookup(oid);
  -            assertNull(result);
  -            result = cache.lookup(oid2);
  -            assertNull(result);
  -            // cache.clear();
  -        }
  -        finally
  -        {
  -            if (broker != null) broker.close();
  -        }
  +        CacheObject obj = new CacheObject(null, "ObjectCache test");
  +        Identity oid = new Identity(obj, broker);
  +        CacheObject obj2 = new CacheObject(null, "ObjectCache test 2");
  +        Identity oid2 = new Identity(obj2, broker);
  +        cache.clear();
  +        Object result = cache.lookup(oid);
  +        assertNull(result);
  +
  +        cache.cache(oid, obj);
  +        cache.cache(oid2, obj2);
  +        result = cache.lookup(oid);
  +        assertNotNull(result);
  +        assertEquals(obj, result);
  +        assertNotSame(obj2, result);
  +
  +        cache.remove(oid);
  +        result = cache.lookup(oid);
  +        Object result2 = cache.lookup(oid2);
  +        assertNull(result);
  +        assertNotNull(result2);
  +
  +        cache.clear();
  +        result = cache.lookup(oid);
  +        assertNull(result);
  +        result = cache.lookup(oid2);
  +        assertNull(result);
  +        // cache.clear();
       }
   
       /**
  
  
  

---------------------------------------------------------------------
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