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 Sat, 20 Sep 2003 14:20:06 GMT
arminw      2003/09/20 07:20:06

  Modified:    src/test/org/apache/ojb cache.ccf
               src/test/org/apache/ojb/broker ObjectCacheTest.java
  Log:
  - add test for JCS ObjectCache implementation
  
  Revision  Changes    Path
  1.2       +7 -1      db-ojb/src/test/org/apache/ojb/cache.ccf
  
  Index: cache.ccf
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/test/org/apache/ojb/cache.ccf,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- cache.ccf	6 Mar 2003 00:32:09 -0000	1.1
  +++ cache.ccf	20 Sep 2003 14:20:06 -0000	1.2
  @@ -10,9 +10,15 @@
   jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
   jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
   
  -# region used by the ObjectCacheJCSImpl
  +# default region used by the JCS ObjectCache implementations
   jcs.region.ojbDefault=
   jcs.region.ojbDefault.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
   jcs.region.ojbDefault.cacheattributes.MaxObjects=1000
   jcs.region.ojbDefault.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
   
  +# region used by test case
  +jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject=
  +jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.MaxObjects=3
  +jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.MaxMemoryIdleTimeSeconds=2
  +jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.UseMemoryShrinker=true
  +jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.ShrinkerIntervalSeconds=1
  
  
  
  1.9       +97 -41    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- ObjectCacheTest.java	17 Sep 2003 22:31:51 -0000	1.8
  +++ ObjectCacheTest.java	20 Sep 2003 14:20:06 -0000	1.9
  @@ -84,16 +84,56 @@
       }
   
       /**
  -     * Check base caching functions of some cache implementations.
  -     *
  -     * @throws Exception
  +     * Test the JCS cache implementation. In JCS config file the following
  +     * properties are set:
  +     * <br/>
  +     * jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.MaxObjects=3
  +     * jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.MaxMemoryIdleTimeSeconds=2
  +     * jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.UseMemoryShrinker=true
  +     * jcs.region.org.apache.ojb.broker.ObjectCacheTest$CacheObject.cacheattributes.ShrinkerIntervalSeconds=1
        */
  -    public void testSimpleObjectCacheFunctions() throws Exception
  +    public void testJCSPerClassObjectCacheImplementation() throws Exception
       {
  -        for (int i = 0; i < objectCacheImpls.length; i++)
  +        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        try
           {
  -            ObjectCacheFactory.getInstance().setClassToServe(objectCacheImpls[i]);
  -            checkBaseFunctions();
  +            ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheJCSPerClassImpl.class);
  +            ObjectCache cache = ObjectCacheFactory.getInstance().createObjectCache(broker);
  +
  +            CacheObject obj_1 = new CacheObject(null, "testJCSPerClassObjectCacheImplementation_1");
  +            Identity oid_1 = new Identity(obj_1, broker);
  +            CacheObject obj_2 = new CacheObject(null, "testJCSPerClassObjectCacheImplementation_2");
  +            Identity oid_2 = new Identity(obj_2, broker);
  +            CacheObject obj_3 = new CacheObject(null, "testJCSPerClassObjectCacheImplementation_2");
  +            Identity oid_3 = new Identity(obj_3, broker);
  +
  +            cache.cache(oid_1, obj_1);
  +            cache.cache(oid_2, obj_2);
  +
  +            // two objects should be found
  +            assertNotNull(cache.lookup(oid_1));
  +            assertNotNull(cache.lookup(oid_2));
  +            cache.cache(oid_3, obj_3);
  +            // we only allow two objects in cache region
  +            boolean bool = cache.lookup(oid_1) != null;
  +            bool = bool && cache.lookup(oid_2) != null;
  +            bool = bool && cache.lookup(oid_3) != null;
  +            assertFalse("We should not found all cached objects", bool);
  +            // idle time is 2 sec
  +            Thread.sleep(2500);
  +            assertNull(cache.lookup(oid_1));
  +            assertNull(cache.lookup(oid_2));
  +            assertNull(cache.lookup(oid_3));
  +
  +        }
  +        catch (Exception e)
  +        {
  +            e.printStackTrace();
  +            throw e;
  +        }
  +        finally
  +        {
  +            if(broker != null) broker.close();
           }
       }
   
  @@ -157,42 +197,20 @@
       }
   
       /**
  -     * This test checks if the caches of two different brokers are properly isolated.
  -     * changes made to an object in tx1 should not be visible in tx2 !
  -     * TODO: once we work without global cache only (e.g. intern temporary cache), this
test should pass!
  +     * Check base caching functions of some cache implementations.
  +     *
  +     * @throws Exception
        */
  -    public void YYYtestCacheIsolation() throws Exception
  +    public void testSimpleObjectCacheFunctions() throws Exception
       {
  -        Object[] pk = new Object[]{new Long(42)};
  -        Identity oid = new Identity(Article.class, InterfaceArticle.class, pk);
  -
  -        GUID guid = new GUID();
  -
  -        PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        broker1.beginTransaction();
  -
  -        Article a1 = (Article) broker1.getObjectByQuery(new QueryByIdentity(oid));
  -        String originalName = a1.getArticleName();
  -        a1.setArticleName(guid.toString());
  -
  -// start a second transaction
  -        PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
  -        broker2.beginTransaction();
  -
  -        Article a2 = (Article) broker2.getObjectByQuery(new QueryByIdentity(oid));
  -
  -        assertEquals(guid.toString(), a1.getArticleName());
  -        assertEquals(originalName, a2.getArticleName());
  -        assertNotSame(a1, a2);
  -
  -
  -        broker1.commitTransaction();
  -        broker1.close();
  -
  -        broker2.commitTransaction();
  -        broker2.close();
  +        for (int i = 0; i < objectCacheImpls.length; i++)
  +        {
  +            ObjectCacheFactory.getInstance().setClassToServe(objectCacheImpls[i]);
  +            checkBaseFunctions();
  +        }
       }
   
  +
       /**
        * Checks the base functions of the current ObjectCache implementation.
        *
  @@ -218,7 +236,7 @@
               assertNotNull(result);
               assertEquals(obj, result);
               assertNotSame(obj2, result);
  -System.out.println("## "+cache);
  +
               cache.remove(oid);
               result = cache.lookup(oid);
               Object result2 = cache.lookup(oid2);
  @@ -305,6 +323,44 @@
               MetadataManager.getInstance().connectionRepository().removeDescriptor(cr.getAllDescriptor().get(0));
           }
       }
  +
  +    /**
  +     * This test checks if the caches of two different brokers are properly isolated.
  +     * changes made to an object in tx1 should not be visible in tx2 !
  +     * TODO: once we work without global cache only (e.g. intern temporary cache), this
test should pass!
  +     */
  +    public void YYYtestCacheIsolation() throws Exception
  +    {
  +        Object[] pk = new Object[]{new Long(42)};
  +        Identity oid = new Identity(Article.class, InterfaceArticle.class, pk);
  +
  +        GUID guid = new GUID();
  +
  +        PersistenceBroker broker1 = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        broker1.beginTransaction();
  +
  +        Article a1 = (Article) broker1.getObjectByQuery(new QueryByIdentity(oid));
  +        String originalName = a1.getArticleName();
  +        a1.setArticleName(guid.toString());
  +
  +// start a second transaction
  +        PersistenceBroker broker2 = PersistenceBrokerFactory.defaultPersistenceBroker();
  +        broker2.beginTransaction();
  +
  +        Article a2 = (Article) broker2.getObjectByQuery(new QueryByIdentity(oid));
  +
  +        assertEquals(guid.toString(), a1.getArticleName());
  +        assertEquals(originalName, a2.getArticleName());
  +        assertNotSame(a1, a2);
  +
  +
  +        broker1.commitTransaction();
  +        broker1.close();
  +
  +        broker2.commitTransaction();
  +        broker2.close();
  +    }
  +
   
   
       // **********************************************************************
  
  
  

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