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 cache.ccf
Date Thu, 08 Sep 2005 17:52:59 GMT
arminw      2005/09/08 10:52:59

  Modified:    src/java/org/apache/ojb/broker/cache ObjectCacheJCSImpl.java
               src/test/org/apache/ojb/broker/cache ObjectCacheTest.java
               src/test/org/apache/ojb cache.ccf
  Log:
  fix problem with cache configuration
  
  Revision  Changes    Path
  1.14      +21 -5     db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheJCSImpl.java
  
  Index: ObjectCacheJCSImpl.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/cache/ObjectCacheJCSImpl.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ObjectCacheJCSImpl.java	27 Aug 2005 12:06:45 -0000	1.13
  +++ ObjectCacheJCSImpl.java	8 Sep 2005 17:52:58 -0000	1.14
  @@ -54,13 +54,13 @@
    * <td><strong>Property Values</strong></td>
    * </tr>
    * <tr>
  - * <td>jcs.maxObjects</td>
  + * <td>jcs.MaxObjects</td>
    * <td>
    * Set the maximal number of cached objects.
    * </td>
    * </tr>
    * <tr>
  - * <td>jcs.maxLifeSeconds</td>
  + * <td>jcs.MaxLifeSeconds</td>
    * <td>
    * Same as attribute <em>lifetime</em> in element <em>ObjectCache</em>.<br/>
    * You can define the maximum life of an item by setting this parameter.
  @@ -75,12 +75,27 @@
   public class ObjectCacheJCSImpl extends AbstractObjectCache
   {
       private Logger log = LoggerFactory.getLogger(ObjectCacheJCSImpl.class);
  +    /*
  +    TODO: which properties shall we support?
  +    MaxObjects=2
  +    MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  +    UseMemoryShrinker=false
  +    MaxMemoryIdleTimeSeconds=2
  +    ShrinkerIntervalSeconds=1
  +    MaxSpoolPerRun=500
  +    IsEternal=false
  +    MaxLifeSeconds=2
  +    IsSpool=false
  +    IsRemote=false
  +    IsLateral=false
  +    */
  +    
       /**
        * The used default region name.
        */
       public static final String DEFAULT_REGION = "ojbDefaultJCSRegion";
  -    public static final String PROP_MAX_OBJECTS = "jcs.maxObjects";
  -    public static final String PROP_MAX_LIFE_SECONDS = "jcs.maxLifeSeconds";
  +    public static final String PROP_MAX_OBJECTS = "jcs.MaxObjects";
  +    public static final String PROP_MAX_LIFE_SECONDS = "jcs.MaxLifeSeconds";
       private JCS jcsCache;
       private ObjectCacheDescriptor ocd;
   
  @@ -102,6 +117,7 @@
           try
           {
               jcsCache = JCS.getInstance(region);
  +            jcsCache.getElementAttributes().setIsEternal(false);
               
               if(ocd.getTimeout() != null)
               {
  
  
  
  1.8       +35 -39    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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ObjectCacheTest.java	27 Aug 2005 12:41:20 -0000	1.7
  +++ ObjectCacheTest.java	8 Sep 2005 17:52:59 -0000	1.8
  @@ -73,32 +73,32 @@
           broker = persistenceConf.createPersistenceBroker();
       }
   
  -    public void XXXtestBaseObjectCacheDefaultImpl() throws Exception
  +    public void testBaseObjectCacheDefaultImpl() throws Exception
       {
           cacheBaseFunctions(CachingStrategyDefaultImpl.class, ObjectCacheDefaultImpl.class);
       }
   
  -    public void XXXtestBaseObjectCacheJCSImpl() throws Exception
  +    public void testBaseObjectCacheJCSImpl() throws Exception
       {
           cacheBaseFunctions(CachingStrategyDefaultImpl.class, ObjectCacheJCSImpl.class);
       }
   
  -    public void XXXtestBaseObjectCacheOSCacheImpl() throws Exception
  +    public void testBaseObjectCacheOSCacheImpl() throws Exception
       {
           cacheBaseFunctions(CachingStrategyDefaultImpl.class, ObjectCacheOSCacheImpl.class);
       }
   
  -    public void XXXtestBaseObjectCacheDefaultImpl_2() throws Exception
  +    public void testBaseObjectCacheDefaultImpl_2() throws Exception
       {
           cacheBaseFunctions(CachingStrategyTwoLevelImpl.class, ObjectCacheDefaultImpl.class);
       }
   
  -    public void XXXtestBaseObjectCacheJCSImpl_2() throws Exception
  +    public void testBaseObjectCacheJCSImpl_2() throws Exception
       {
           cacheBaseFunctions(CachingStrategyTwoLevelImpl.class, ObjectCacheJCSImpl.class);
       }
   
  -    public void XXXtestBaseObjectCacheOSCacheImpl_2() throws Exception
  +    public void testBaseObjectCacheOSCacheImpl_2() throws Exception
       {
           cacheBaseFunctions(CachingStrategyTwoLevelImpl.class, ObjectCacheOSCacheImpl.class);
       }
  @@ -157,7 +157,7 @@
       /**
        * Test the two-level cache mode.
        */
  -    public void XXXtestCompareObjectIdentityTwoLevelDefaultImpl() throws Exception
  +    public void testCompareObjectIdentityTwoLevelDefaultImpl() throws Exception
       {
           cacheCompareObjectIdentityTwoLevel(ObjectCacheDefaultImpl.class);
       }
  @@ -165,7 +165,7 @@
       /**
        * Test the two-level cache mode.
        */
  -    public void XXXtestCompareObjectIdentityTwoLevelJCSImpl() throws Exception
  +    public void testCompareObjectIdentityTwoLevelJCSImpl() throws Exception
       {
           cacheCompareObjectIdentityTwoLevel(ObjectCacheJCSImpl.class);
       }
  @@ -173,7 +173,7 @@
       /**
        * Test the two-level cache mode.
        */
  -    public void XXXtestCompareObjectIdentityTwoLevelOSCacheImpl() throws Exception
  +    public void testCompareObjectIdentityTwoLevelOSCacheImpl() throws Exception
       {
           cacheCompareObjectIdentityTwoLevel(ObjectCacheOSCacheImpl.class);
       }
  @@ -243,7 +243,7 @@
        * using LRU-strategy and 'timeout' objects setting
        * @throws Exception
        */
  -    public void XXXtestObjectCacheDefaultImplTimeoutAndMaxEntry() throws Exception
  +    public void testObjectCacheDefaultImplTimeoutAndMaxEntry() throws Exception
       {
           ObjectCacheDescriptor ocd = new ObjectCacheDescriptor(broker.getConfiguration().getJdbcConnectionDescriptor());
           ocd.setCachingStrategy(CachingStrategyDefaultImpl.class);
  @@ -264,16 +264,13 @@
        */
       public void testObjectCacheJCSImplTimeoutAndMaxObjects() throws Exception
       {
  -        if(ojbSkipKnownIssueProblem("Know problem caused by JCS, seems 'maxObjects'" +
  -                " and 'maxLifeSeconds' setting don't work properly")) return;
  -
           ObjectCacheDescriptor ocd = new ObjectCacheDescriptor(broker.getConfiguration().getJdbcConnectionDescriptor());
           ocd.setCachingStrategy(CachingStrategyDefaultImpl.class);
           ocd.setObjectCache(ObjectCacheJCSImpl.class);
           // most important setting
           ocd.setTimeout(new Integer(1));
  -        ocd.addAttribute(ObjectCacheJCSImpl.PROP_MAX_OBJECTS, "2");
  -        ocd.addAttribute(ObjectCacheJCSImpl.PROP_MAX_LIFE_SECONDS, "2");
  +        ocd.addAttribute(ObjectCacheJCSImpl.PROP_MAX_OBJECTS, "3");
  +        ocd.addAttribute(ObjectCacheJCSImpl.PROP_MAX_LIFE_SECONDS, "1");
   
           timeoutMaxObjectTestFor(ocd);
       }
  @@ -282,7 +279,7 @@
        * Test timeout and max objects setting for OSCache
        * @throws Exception
        */
  -    public void XXXtestObjectCacheOSCacheImplTimeoutAndMaxObjects() throws Exception
  +    public void testObjectCacheOSCacheImplTimeoutAndMaxObjects() throws Exception
       {
           ObjectCacheDescriptor ocd = new ObjectCacheDescriptor(broker.getConfiguration().getJdbcConnectionDescriptor());
           ocd.setCachingStrategy(CachingStrategyDefaultImpl.class);
  @@ -297,7 +294,7 @@
       protected void timeoutMaxObjectTestFor(ObjectCacheDescriptor ocd) throws Exception
       {
           prepareNewCache(ocd);
  -System.out.println("Cache: " + broker.serviceSessionCache().getCachingStrategy(CacheObject.class));
  +// System.out.println("Cache: " + broker.serviceSessionCache().getCachingStrategy(CacheObject.class));
           try
           {
               CacheObject obj_1 = new CacheObject();
  @@ -355,16 +352,13 @@
        * Test the JCS cache implementation. In JCS config file the following
        * properties are set:
        * <br/>
  -     * jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxObjects=3
  +     * jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxObjects=2
        * jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxMemoryIdleTimeSeconds=2
        * jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.UseMemoryShrinker=true
        * jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.ShrinkerIntervalSeconds=1
        */
  -    public void XXXtestJCSObjectCacheConfigFile() throws Exception
  +    public void testJCSObjectCacheConfigFile() throws Exception
       {
  -        if(ojbSkipKnownIssueProblem("Know problem caused by JCS, seems 'maxObjects'" +
  -                " and 'maxLifeSeconds' setting don't work properly")) return;
  -
           ObjectCacheDescriptor ocd = new ObjectCacheDescriptor(broker.getConfiguration().getJdbcConnectionDescriptor());
           ocd.setCachingStrategy(CachingStrategyDefaultImpl.class);
           ocd.setObjectCache(ObjectCacheJCSImpl.class);
  @@ -382,20 +376,22 @@
           cache.cache(oid_1, obj_1);
           cache.cache(oid_2, obj_2);
           cache.cache(oid_2, obj_3);
  -
  -        // two objects should be found
  -        assertNotNull(cache.lookup(oid_1));
  -        assertNotNull(cache.lookup(oid_2));
  -        assertNotNull(cache.lookup(oid_3));
           cache.cache(oid_4, obj_4);
  -        // 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;
  -        bool = bool && cache.lookup(oid_4) != null;
  -        assertFalse("We should not found all cached objects", bool);
  +
  +        // we only allow three objects in cache region
  +        CacheObject new_1 = (CacheObject) cache.lookup(oid_1);
  +        CacheObject new_2 = (CacheObject) cache.lookup(oid_2);
  +        CacheObject new_3 = (CacheObject) cache.lookup(oid_3);
  +        CacheObject new_4 = (CacheObject) cache.lookup(oid_4);
  +        int count = 0;
  +        if(new_1 != null) ++count;
  +        if(new_2 != null) ++count;
  +        if(new_3 != null) ++count;
  +        if(new_4 != null) ++count;
  +        assertEquals(2, count);
  +
           // idle time is 2 sec
  -        Thread.sleep(3500);
  +        Thread.sleep(2000);
           assertNull(cache.lookup(oid_1));
           assertNull(cache.lookup(oid_2));
           assertNull(cache.lookup(oid_3));
  @@ -409,7 +405,7 @@
        * Thus we should found 'CacheObject' instance in cache, but NOT found
        * 'EmptyCacheObject' instance.
        */
  -    public void XXXtestPerClassCache() throws Exception
  +    public void testPerClassCache() throws Exception
       {
           String name = "testPerClassCache_" + System.currentTimeMillis();
   
  @@ -437,7 +433,7 @@
        * This should be ObjectCacheEmptyImpl, because this is declared at jdbc-connection-descriptor
        * level.
        */
  -    public void XXXtestPerDatabaseCache()
  +    public void testPerDatabaseCache()
       {
           String name = "testPerDatabaseCache_" + System.currentTimeMillis();
           ConnectionRepository cr = ojb.getMetadataManager()
  @@ -466,7 +462,7 @@
        * caching.
        * @throws Exception
        */
  -    public void XXXtestCacheFilterFunctions() throws Exception
  +    public void testCacheFilterFunctions() throws Exception
       {
           String name = "testCacheFilterFunctions_" + System.currentTimeMillis();
           ObjectCacheDescriptor ocd = new ObjectCacheDescriptor(broker.getConfiguration().getJdbcConnectionDescriptor());
  @@ -513,7 +509,7 @@
        * 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 XXXtestCacheIsolation() throws Exception
  +    public void testCacheIsolation() throws Exception
       {
           String name = "testCacheIsolation_" + System.currentTimeMillis();
   
  
  
  
  1.5       +11 -2     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.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- cache.ccf	27 Aug 2005 12:46:14 -0000	1.4
  +++ cache.ccf	8 Sep 2005 17:52:59 -0000	1.5
  @@ -4,22 +4,31 @@
   jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
   jcs.default.cacheattributes.MaxObjects=1000
   jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  +jcs.default.elementattributes.IsSpool=false
  +jcs.default.elementattributes.IsRemote=false
  +jcs.default.elementattributes.IsLateral=false
   
   # 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
  +jcs.default.elementattributes.IsSpool=false
  +jcs.default.elementattributes.IsRemote=false
  +jcs.default.elementattributes.IsLateral=false
   
   # region used by test case
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject=
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  -jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxObjects=3
  +jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxObjects=2
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  -jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.UseMemoryShrinker=true
  +jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.UseMemoryShrinker=false
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxMemoryIdleTimeSeconds=2
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.ShrinkerIntervalSeconds=1
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.cacheattributes.MaxSpoolPerRun=500
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.elementattributes=org.apache.jcs.engine.ElementAttributes
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.elementattributes.IsEternal=false
   jcs.region.org.apache.ojb.broker.cache.ObjectCacheTest$CacheObject.elementattributes.MaxLifeSeconds=2
  +jcs.default.elementattributes.IsSpool=false
  +jcs.default.elementattributes.IsRemote=false
  +jcs.default.elementattributes.IsLateral=false
  
  
  

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