Hello Al, Thanks for your kind pointer.
I found that the IndexedDiskCacheNoMemoryUnitTest which is as same as my test purpose. When I read the test configure, I should check the unit test first. And during further test, I understand the test result behavior and my application system behavior. if I set MaxPurgatorySize=2001, then the test always PASS But if I set the value below than that, than the test FAIL from time to time. Becauseof the asynch behavior when writing to the disk. If I have enough memory, than I can set enough MaxPurgatorySize. But my current situation is limited. So I think I need some regulator when input to the cache if there is some Purgatory space than insert or wait until have some space even a performance degradation happen. I saw the Purgatory Size number from test results report. But I cound not find the method how to get the current available Purgatory Size. How can I get the current available Purgatory size ? and If I make some patch about this, where should I look ? Thanks, Youngho ----- Original Message ----- From: "Al Forbes" <[EMAIL PROTECTED]> To: "JCS Users List" <jcs-users@jakarta.apache.org> Sent: Friday, November 07, 2008 8:34 PM Subject: Re: IndexedDiskCache insert, remove and reinsert question > Hi Youngho, > > I do not have time to look at this in detail, but there are many test cases > in the unit tests. If you have not look there, then tt's probably a good > idea to look at those first. > > http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/ > > Regards > Al > > 2008/11/6 Youngho Cho <[EMAIL PROTECTED]> > >> Hello, >> >> I tested some objects put into IndexedDiskCache and remove and reinsert >> test like following. >> But I can not pass the test. >> >> Is there something wrong in cache.ccf file ? >> How can I pass the test ? >> >> >> >> Thanks, >> >> Youngho >> >> >> >> 1. test cache.ccf >> >> # DEFAULT CACHE REGION >> jcs.default=DC >> jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes >> jcs.default.cacheattributes.MaxObjects=0 >> >> jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache >> jcs.default.cacheattributes.DiskUsagePatternName=UPDATE >> jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes >> jcs.default.elementattributes.IsEternal=false >> >> >> # SYSTEM GROUP ID CACHE >> jcs.system.groupIdCache=DC >> >> jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes >> jcs.system.groupIdCache.cacheattributes.MaxObjects=0 >> >> jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache >> >> >> # AVAILABLE AUXILIARY CACHES >> >> jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory >> >> jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes >> jcs.auxiliary.DC.attributes.DiskPath=d:/tmp >> jcs.auxiliary.DC.attributes.maxKeySize=1000000 >> jcs.auxiliary.DC.attributes.MaxPurgatorySize=100 >> jcs.auxiliary.DC.attributes.OptimizeOnShutdown=false >> >> # PRE-DEFINED CACHE REGIONS >> jcs.region.testCache1=DC >> >> jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes >> jcs.region.testCache1.cacheattributes.MaxObjects=0 >> >> jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache >> >> >> jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes >> jcs.region.testCache1.elementattributes.IsEternal=false >> jcs.region.testCache1.elementattributes.MaxLifeSeconds=0 >> jcs.region.testCache1.elementattributes.IsSpool=true >> jcs.region.testCache1.elementattributes.IsLateral=true >> jcs.region.testCache1.elementattributes.IsRemote=true >> >> >> >> 2. test class >> >> // >> // JCSTest .java >> // >> >> import java.io.File; >> >> import junit.framework.TestCase; >> >> import org.apache.jcs.JCS; >> import org.apache.jcs.access.exception.CacheException; >> import org.apache.jcs.engine.CompositeCacheAttributes; >> import org.apache.jcs.engine.behavior.ICompositeCacheAttributes; >> import org.apache.jcs.utils.struct.LRUMap; >> >> public class JCSTest extends TestCase >> { >> >> protected static int MAX_NUM = 100000; >> >> protected JCS jcs = null; >> >> protected void setUp() throws Exception >> { >> File file = new File("d:/tmp"); >> if(file.exists()) >> { >> File[] files = file.listFiles(); >> for(int i=0; i < files.length; i++) >> { >> files[i].delete(); >> } >> } >> JCS.setConfigFilename( "/TestJCS.ccf" ); >> jcs = JCS.getInstance("testCache1"); >> } >> >> >> protected void tearDown() >> throws Exception >> { >> jcs.dispose(); >> } >> >> protected void insert(int key) throws CacheException >> { >> Object obj = getCachedObject(key); >> jcs.put(new Integer(key), obj); >> } >> >> protected void insertMany(int maxNum) throws CacheException >> { >> for (int i = 0; i < maxNum; i++) >> { >> insert(i); >> if ((i % 20000) == 0) >> { >> try >> { >> Thread.sleep(20000); >> } >> catch(Exception e) >> { >> // >> } >> } >> } >> } >> >> protected Object get(int key) >> { >> return jcs.get(new Integer(key)); >> } >> >> protected void getMany(int maxNum) >> { >> for (int i = 0; i < maxNum; i++) >> { >> assertNotNull(getCachedObject(i).toString(), get(i)); >> } >> } >> >> protected void testMany(int maxNum) throws Exception >> { >> for (int i = 0; i < maxNum; i++) >> { >> final MockCache obj = (MockCache)get(i); >> assertNotNull(getCachedObject(i).toString(), obj); >> assertEquals(getCachedObject(i).getValue(), obj.getValue()); >> // remove >> jcs.remove(new Integer(i)); >> assertNull("[" + i +"] should be removed" , get(i)); >> >> // reinsert again >> insert(i); >> >> final MockCache obj1 = (MockCache)get(i); >> // retest >> assertEquals(getCachedObject(i).getValue(), obj.getValue(), >> obj1.getValue()); >> } >> } >> >> protected void printStats() >> { >> System.out.println(jcs.getStats()); >> } >> >> public void testJCS() throws Exception >> { >> long start = System.currentTimeMillis(); >> insertMany(MAX_NUM); >> System.out.println(" "); >> System.out.println("[DONE] : insert takes " + >> (System.currentTimeMillis() - start ) + "msec "); >> >> start = System.currentTimeMillis(); >> getMany(MAX_NUM); >> System.out.println(" "); >> System.out.println("[DONE] : get takes " + >> (System.currentTimeMillis() - start ) + "msec "); >> >> start = System.currentTimeMillis(); >> testMany(MAX_NUM); >> System.out.println(" "); >> System.out.println("[DONE] : test takes " + >> (System.currentTimeMillis() - start) + "msec "); >> >> printStats(); >> } >> >> protected static MockCache getCachedObject(int i) >> { >> return new MockCache(Integer.toString(i), >> "some string [" + Integer.toString(i) + "]"); >> } >> } >> >> // >> // MockCache.java >> // >> import java.io.Serializable; >> >> public class MockCache implements Serializable >> { >> >> private String key = null; >> private String value = null; >> >> /** >> * >> */ >> public MockCache() >> { >> } >> >> /** >> * >> */ >> public MockCache(String key, String value) >> { >> this.key = key; >> this.value = value; >> } >> >> public String getValue() >> { >> return this.value; >> } >> >> public String toString() >> { >> return "{[" + this.key + "] " + this.value + "}"; >> } >> } >