jakarta-jcs-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ard Schrijvers" <a.schrijv...@hippo.nl>
Subject RE: Possible bug in JCS with IdleTime element attribute
Date Thu, 18 Jan 2007 10:49:47 GMT

> 
> I think I may have found a bug in JCS with regards to the
> IdleTime element attribute.  Either that
> or I don't understand how this setting works.

I thin you have a bug in your test...

> 
> import junit.framework.TestCase;
> 
> public class TestMissCountExpiredBug extends TestCase
> {
>   public void testSomething()
>     throws Exception
>   {
>     // setup JCS
>     CompositeCacheManager mgr = 
> CompositeCacheManager.getUnconfiguredInstance();
>     mgr.configure( setupProperties() );
>     
>     // get access to bug test cache region
>     JCS jcs = JCS.getInstance( "BugTest" );
>     CompositeCache cache = mgr.getCache( "BugTest" );

now, cache is the cache you get from your configured CompositeCacheManager. I think, your
jcs has just default configuration, because I do not see where it is configured..?

If you replace jcs below, with cache, you probably will see, everything works just fine,

Regards Ard

>        
>     // put five items in cache
>     for ( int i = 0; i < 5; i++ )
>     {
>       String key = "key" + i;
>       String value = "value" + i;
>       jcs.put( key, value );
>     }
>     
>     // sleep for twice the length of the max idle time of 
> items in the cache
>     // region
>     IElementAttributes attrs = cache.getElementAttributes();
>     long idleTimeSeconds = attrs.getIdleTime();
>     assertEquals( 5L, idleTimeSeconds );
>     System.out.println( "idle time seconds=" + idleTimeSeconds );
>     long sleepTime = 1000 * 2 * idleTimeSeconds;
>     System.out.println( "sleeping for " + sleepTime
>       + " millis to allow cache elements to be flagged as 
> idle for too long" );
>     Thread.sleep( sleepTime );
>     
>     // try to access the five items - they should have 
> expired so this should
>     // fail
>     for ( int i = 0; i < 5; i++ )
>     {
>       String key = "key" + i;
>       Object value = jcs.get( key );
>       if ( value != null )
>       {
>         System.out.println( "found a value for key " + key + 
> ": " + value );
>       }
>     }
>     
>     // check miss count expired - should be five
>     int missCountExpired = cache.getMissCountExpired();
>     System.out.println( "miss count expired: " + missCountExpired );
>     assertEquals( 5, missCountExpired );
>   }
>   
>   private Properties setupProperties()
>   {
>     Properties answer = new Properties();
>     
>     // defaults
>     answer.setProperty( "jcs.default", "" );
>     answer.setProperty( "jcs.default.cacheattributes", 
> "org.apache.jcs.engine.CompositeCacheAttributes" );
>     answer.setProperty( 
> "jcs.default.cacheattributes.MemoryCacheName", 
> "org.apache.jcs.engine.memory.lru.LRUMemoryCache" );
>     answer.setProperty( 
> "jcs.default.cacheattributes.MaxObjects", "100000" );
> 
>     // bug test region - elements won't go to disk, but 
> should be marked as expired after five seconds of non-use
>     answer.setProperty( "jcs.region.BugTest", "" );
>     answer.setProperty( "jcs.region.BugTest.cacheattributes", 
> "org.apache.jcs.engine.CompositeCacheAttributes" );
>     answer.setProperty( 
> "jcs.region.BugTest.cacheattributes.MemoryCacheName", 
> "org.apache.jcs.engine.memory.lru.LRUMemoryCache" );
>     answer.setProperty( 
> "jcs.region.BugTest.cacheattributes.MaxObjects", "1000" );
>     answer.setProperty( 
> "jcs.region.BugTest.cacheattributes.UseMemoryShrinker", "false" );
>     answer.setProperty( 
> "jcs.region.BugTest.elementattributes", 
> "org.apache.jcs.engine.ElementAttributes" );
>     answer.setProperty( 
> "jcs.region.BugTest.elementattributes.IsEternal", "false" );
>     answer.setProperty( 
> "jcs.region.BugTest.elementattributes.IdleTime", "5" );
>     
>     return answer;
>   }
> }
> 
> 
> 
> 
> 
> 
>  
> ______________________________________________________________
> ______________________
> Now that's room service!  Choose from over 150,000 hotels
> in 45,000 destinations on Yahoo! Travel to find your fit.
> http://farechase.yahoo.com/promo-generic-14795097
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jcs-users-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-users-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-users-help@jakarta.apache.org


Mime
View raw message