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 + "}";
    }
}

Reply via email to