You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2006/02/16 00:07:32 UTC

svn commit: r378115 - in /jakarta/jcs/trunk/src: conf/ java/org/apache/jcs/access/ java/org/apache/jcs/admin/ java/org/apache/jcs/auxiliary/disk/indexed/ java/org/apache/jcs/engine/ java/org/apache/jcs/engine/control/ java/org/apache/jcs/utils/config/ ...

Author: asmuts
Date: Wed Feb 15 15:07:30 2006
New Revision: 378115

URL: http://svn.apache.org/viewcvs?rev=378115&view=rev
Log:
added tests for indexed disk cache
fixed lrumpa entry set bug

Added:
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMapEntry.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java
      - copied, changed from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java
      - copied, changed from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java
      - copied, changed from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheNoMemoryUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java
      - copied, changed from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
      - copied, changed from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
Removed:
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheNoMemoryUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
Modified:
    jakarta/jcs/trunk/src/conf/cache2.ccf
    jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheElementInfo.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheRegionInfo.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/admin/JCSAdminBean.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheElement.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/ElementAttributes.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/servlet/BasicHttpAuthenticator.java
    jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java
    jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapUnitTest.java

Modified: jakarta/jcs/trunk/src/conf/cache2.ccf
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/conf/cache2.ccf?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/conf/cache2.ccf (original)
+++ jakarta/jcs/trunk/src/conf/cache2.ccf Wed Feb 15 15:07:30 2006
@@ -15,10 +15,17 @@
 
 ##############################################################
 ################## CACHE REGIONS AVAILABLE ###################
-jcs.region.testCache1=RC
+jcs.region.testCache1=DC,RC
 jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
-jcs.region.testCache1.cacheattributes.MaxObjects=200000
+jcs.region.testCache1.cacheattributes.MaxObjects=10
 jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.testCache1.cacheattributes.UseMemoryShrinker=true
+jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=30
+jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=300
+jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=100
+jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
+jcs.region.testCache1.elementattributes.IsEternal=false
+jcs.region.testCache1.elementattributes.MaxLifeSeconds=60000
 jcs.region.testCache1.elementattributes.IsLateral=true
 jcs.region.testCache1.elementattributes.IsRemote=true
 
@@ -42,13 +49,13 @@
 # standard disk cache
 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=@project_home@/raf
+jcs.auxiliary.DC.attributes.DiskPath=target/test-sandbox
 
 # need to make put or invalidate an option
 # just a remove lock to add
 jcs.auxiliary.RC=org.apache.jcs.auxiliary.remote.RemoteCacheFactory
 jcs.auxiliary.RC.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
-jcs.auxiliary.RC.attributes.FailoverServers=localhost:1102,localhost:1101
+jcs.auxiliary.RC.attributes.FailoverServers=localhost:1101
 jcs.auxiliary.RC.attributes.LocalPort=1202
 jcs.auxiliary.RC.attributes.RemoveUponRemotePut=false
 jcs.auxiliary.RC.attributes.GetTimeoutMillis=5000

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/access/CacheAccess.java Wed Feb 15 15:07:30 2006
@@ -26,7 +26,6 @@
 import org.apache.jcs.access.exception.InvalidHandleException;
 import org.apache.jcs.access.exception.ObjectExistsException;
 import org.apache.jcs.engine.CacheElement;
-import org.apache.jcs.engine.CompositeCacheAttributes;
 import org.apache.jcs.engine.behavior.ICacheElement;
 import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
 import org.apache.jcs.engine.behavior.IElementAttributes;
@@ -109,7 +108,7 @@
      * @return CacheAccess instance for the new region
      * @exception CacheException
      */
-    public static CacheAccess defineRegion( String name, CompositeCacheAttributes cattr )
+    public static CacheAccess defineRegion( String name, ICompositeCacheAttributes cattr )
         throws CacheException
     {
         ensureCacheManager();
@@ -130,7 +129,7 @@
      * @return CacheAccess instance for the new region
      * @exception CacheException
      */
-    public static CacheAccess defineRegion( String name, CompositeCacheAttributes cattr, IElementAttributes attr )
+    public static CacheAccess defineRegion( String name, ICompositeCacheAttributes cattr, IElementAttributes attr )
         throws CacheException
     {
         ensureCacheManager();
@@ -242,7 +241,8 @@
     {
         if ( this.cacheControl.get( (Serializable) key ) != null )
         {
-            throw new ObjectExistsException( "putSafe failed.  Object exists in the cache for key [" + key +"].  Remove first or use a non-safe put to override the value." );
+            throw new ObjectExistsException( "putSafe failed.  Object exists in the cache for key [" + key
+                + "].  Remove first or use a non-safe put to override the value." );
         }
         put( key, value );
     }
@@ -382,15 +382,22 @@
         this.cacheControl.remove( (Serializable) name );
     }
 
-
     /**
      * ResetAttributes allows for some of the attributes of a region to be reset
      * in particular expiration time attriubtes, time to live, default time to
      * live and idle time, and event handlers. Changing default settings on
      * groups and regions will not affect existing objects. Only object loaded
      * after the reset will use the new defaults. If no name argument is
-     * provided, the reset is applied to the region. NOTE: this method is
-     * currently not implemented.
+     * provided, the reset is applied to the region.
+     * 
+     * NOTE: this method is does not reset the attributes for items already in
+     * the cache. It could potentially do this for items in memory, and maybe on
+     * disk (which would be slow) but not remote items. Rather than have
+     * unpredicatble behavior, this method just sets the default attributes.
+     * TODO is should be renamed "setDefaultElementAttributes"
+     * 
+     * @deprecated As of release 1.3
+     * @see setDefaultElementAttributes
      * 
      * @param attr
      *            New attributes for this region.
@@ -404,6 +411,26 @@
     }
 
     /**
+     * This method is does not reset the attributes for items already in the
+     * cache. It could potentially do this for items in memory, and maybe on
+     * disk (which would be slow) but not remote items. Rather than have
+     * unpredicatble behavior, this method just sets the default attributes.
+     * Items subsequently put into the cache will use these defaults if they do
+     * not specify specific attributes.
+     * 
+     * 
+     * @param attr
+     *            the default attributes.
+     * @throws CacheException
+     *             if something goes wrong.
+     */
+    public void setDefaultElementAttributes( IElementAttributes attr )
+        throws CacheException
+    {
+        this.cacheControl.setElementAttributes( attr );
+    }
+
+    /**
      * Reset attributes for a particular element in the cache. NOTE: this method
      * is currently not implemented.
      * 
@@ -413,6 +440,7 @@
      *            New attributes for the object
      * @exception CacheException
      * @exception InvalidHandleException
+     *                if the item does not exist.
      */
     public void resetElementAttributes( Object name, IElementAttributes attr )
         throws CacheException, InvalidHandleException
@@ -423,8 +451,10 @@
             throw new InvalidHandleException( "Object for name [" + name + "] is not in the cache" );
         }
 
-        // don't assume pass by reference here, i.e. don't do this:
-        //element.setElementAttributes( attr );
+        // Although it will work currently, don't assume pass by reference here,
+        // i.e. don't do this:
+        // element.setElementAttributes( attr );
+        // Another reason to call put is to force the changes to be distributed.
         put( element.getKey(), element.getVal(), attr );
 
     }
@@ -432,11 +462,31 @@
     /**
      * GetElementAttributes will return an attribute object describing the
      * current attributes associated with the object name.
+     * <p>
+     * This was confusing, so I created a new method with a clear name.
+     * 
+     * @deprecated As of release 1.3
+     * @see getDefaultElementAttributes
      * 
      * @return Attributes for this region
      * @exception CacheException
      */
     public IElementAttributes getElementAttributes()
+        throws CacheException
+    {
+        return this.cacheControl.getElementAttributes();
+    }
+
+    /**
+     * Retrieves the default element attributes used by this region.
+     * <p>
+     * Each time an element is added to the cache without element attributes,
+     * the default element attributes are cloned.
+     * 
+     * @return the deafualt element attributes used by this region.
+     * @throws CacheException
+     */
+    public IElementAttributes getDefaultElementAttributes()
         throws CacheException
     {
         return this.cacheControl.getElementAttributes();

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheElementInfo.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheElementInfo.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheElementInfo.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheElementInfo.java Wed Feb 15 15:07:30 2006
@@ -72,4 +72,22 @@
     {
         return this.expiresInSeconds;
     }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "\nCacheElementInfo " );
+        buf.append( "\n Key [" + getKey() + "]" );
+        buf.append( "\n Eternal [" + isEternal() + "]" );
+        buf.append( "\n CreateTime [" + getCreateTime() + "]" );
+        buf.append( "\n MaxLifeSeconds [" + getMaxLifeSeconds() + "]" );
+        buf.append( "\n ExpiresInSeconds [" + getExpiresInSeconds() + "]" );
+
+        return buf.toString();
+    }
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheRegionInfo.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheRegionInfo.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheRegionInfo.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/admin/CacheRegionInfo.java Wed Feb 15 15:07:30 2006
@@ -68,4 +68,23 @@
         return this.cache.getStats();
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {
+        StringBuffer buf = new StringBuffer();
+        buf.append( "\nCacheRegionInfo " );
+        if ( getCache() != null )
+        {
+            buf.append( "\n CacheName [" + getCache().getCacheName() + "]" );
+            buf.append( "\n Status [" + getStatus() + "]" );
+        }
+        buf.append( "\n ByteCount [" + getByteCount() + "]" );
+
+        return buf.toString();
+    }
+
 }

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/admin/JCSAdminBean.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/admin/JCSAdminBean.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/admin/JCSAdminBean.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/admin/JCSAdminBean.java Wed Feb 15 15:07:30 2006
@@ -38,7 +38,7 @@
  * provides the ability to remove items (any number of key arguments can be
  * provided with action 'remove'). Should be initialized with a properties file
  * that provides at least a classpath resource loader.
- *  
+ * 
  */
 public class JCSAdminBean
 {
@@ -49,7 +49,7 @@
      * Builds up info about each element in a region.
      * 
      * @param cacheName
-     * @return
+     * @return List of CacheElementInfo objects
      * @throws Exception
      */
     public LinkedList buildElementInfo( String cacheName )
@@ -160,18 +160,19 @@
         ObjectOutputStream out = new ObjectOutputStream( counter );
 
         // non serializable objects will cause problems here
+        // stop at the first non serializable exception. 
         try
         {
             while ( iter.hasNext() )
             {
                 ICacheElement ce = (ICacheElement) ( (Map.Entry) iter.next() ).getValue();
-
+                    
                 out.writeObject( ce.getVal() );
             }
         }
         catch ( Exception e )
         {
-            //log later
+            // log later
         }
 
         // 4 bytes lost for the serialization header

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Wed Feb 15 15:07:30 2006
@@ -87,7 +87,7 @@
     // RECYLCE BIN -- array of empty spots
     private SortedPreferentialArray recycle;
 
-    IndexedDiskCacheAttributes cattr;
+    private IndexedDiskCacheAttributes cattr;
 
     // used for counting the number of requests
     private int optCnt = 0;
@@ -183,14 +183,14 @@
      * 
      * @throws InterruptedException
      */
-    private void loadKeys()
+    protected void loadKeys()
         throws InterruptedException
     {
         storageLock.writeLock().acquire();
 
         if ( log.isInfoEnabled() )
         {
-            log.info( "loading keys for " + keyFile.toString() );
+            log.info( "Loading keys for " + keyFile.toString() );
         }
 
         try
@@ -203,6 +203,11 @@
 
             if ( keys != null )
             {
+                if ( log.isInfoEnabled() )
+                {
+                    log.info( "Found " + keys.size() + " in keys file." );
+                }
+
                 keyHash.putAll( keys );
 
                 if ( log.isInfoEnabled() )
@@ -228,7 +233,7 @@
         }
         catch ( Exception e )
         {
-            log.error( fileName, e );
+            log.error( "Problem loading keys for file " + fileName, e );
         }
         finally
         {
@@ -289,7 +294,7 @@
      * Saves key file to disk. This converts the LRUMap to a HashMap for
      * deserialzation.
      */
-    private void saveKeys()
+    protected void saveKeys()
     {
         try
         {
@@ -317,7 +322,7 @@
         }
         catch ( Exception e )
         {
-            log.error( e );
+            log.error( "Problem storing keys.", e );
         }
     }
 
@@ -350,7 +355,7 @@
 
         // old element with same key
         IndexedDiskElementDescriptor old = null;
-        
+
         try
         {
             ded = new IndexedDiskElementDescriptor();
@@ -429,7 +434,8 @@
         }
         catch ( Exception e )
         {
-            log.error( "Failure updating element, cacheName: " + cacheName + ", key: " + ce.getKey() + " old: " + old, e );
+            log.error( "Failure updating element, cacheName: " + cacheName + ", key: " + ce.getKey() + " old: " + old,
+                       e );
         }
         return;
     }
@@ -912,18 +918,24 @@
     private int timesOptimized = 0;
 
     /**
-     * Realtime optimization is handled by this method. It works in this way:
+     * Realtime optimization is handled by this method.
      * 
-     * 1. lock the active file, create a new file 2. copy the keys for iteration
-     * 3. for each key in the copy, make sure it is still in the active keyhasH
-     * to prevent putting items on disk that have been removed. It also checks
-     * the new keyHash to make sure that a newer version hasn't already been
-     * put. 4. Write the element for the key copy to disk in the normal
-     * proceedure. 5. All gets will be serviced by the new file. 6. All puts are
-     * made on the new file.
+     * It works in this way:
+     * <ul>
+     * <li>1. Lock the active file, create a new file.</li>
+     * <li>2. Copy the keys for iteration.</li>
+     * <li>3. For each key in the copy, make sure it is still in the active
+     * keyhash to prevent putting items on disk that have been removed. It also
+     * checks the new keyHash to make sure that a newer version hasn't already
+     * been put.</li>
+     * <li>4. Write the element for the key copy to disk in the normal
+     * proceedure.</li>
+     * <li>5. All gets will be serviced by the new file. </li>
+     * <li>6. All puts are made on the new file.</li>
+     * </ul>
      * 
      */
-    private void optimizeRealTime()
+    protected void optimizeRealTime()
     {
 
         long start = System.currentTimeMillis();
@@ -1030,10 +1042,10 @@
     }
 
     /**
-     * Note: synchronization currently managed by the only caller method -
+     * Note: synchronization currently must be managed by the caller method--
      * dispose.
      */
-    private void optimizeFile()
+    protected void optimizeFile()
     {
         try
         {
@@ -1212,6 +1224,41 @@
     public int getSize()
     {
         return keyHash.size();
+    }
+
+    /**
+     * This is for debugging and testing.
+     * 
+     * @return the length of the data file.
+     * @throws IOException 
+     */
+    protected long getDataFileSize() throws IOException
+    {
+        long size = 0;
+
+        try
+        {
+            storageLock.readLock().acquire();
+            
+            try
+            {
+                if ( dataFile != null )
+                {
+                    size = dataFile.length();
+                }
+            }
+            finally
+            {
+                storageLock.readLock().release();
+            }            
+        }
+        catch ( InterruptedException e )
+        {
+            // nothing
+        }
+
+
+        return size;
     }
 
     /**

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheElement.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheElement.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheElement.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CacheElement.java Wed Feb 15 15:07:30 2006
@@ -44,7 +44,7 @@
      * These attributes hold information about the element and what it is
      * allowed to do.
      */
-    public ElementAttributes attr;
+    public IElementAttributes attr;
 
     /**
      * Constructor for the CacheElement object
@@ -58,6 +58,22 @@
         this.cacheName = cacheName;
         this.key = key;
         this.val = val;
+    }
+
+    /**
+     * Constructor for the CacheElement object
+     * 
+     * @param cacheName
+     * @param key
+     * @param val
+     * @param attrArg
+     */
+    public CacheElement( String cacheName, Serializable key, Serializable val, IElementAttributes attrArg )
+    {
+        this.cacheName = cacheName;
+        this.key = key;
+        this.val = val;
+        this.attr = attrArg;
     }
 
     /**

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/ElementAttributes.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/ElementAttributes.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/ElementAttributes.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/ElementAttributes.java Wed Feb 15 15:07:30 2006
@@ -21,16 +21,24 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.io.Serializable;
-
 import java.util.ArrayList;
 import java.util.Iterator;
 
-import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
-
 import org.apache.jcs.engine.behavior.IElementAttributes;
+import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
 
 /**
- * Element attribute descriptor class.
+ * This it the element attribute descriptor class. Each element in the cache has
+ * an ElementAttribute object associated with it. An ElementAttributes object
+ * can be associated with an element in 3 ways:
+ * <ul>
+ * <li>1. When the item is put into the cache, you can associate an element
+ * attributes object.</li>
+ * <li>2. If not attributes object is include when the element is put into the
+ * cache, then the default attributes for the region will be used.</li>
+ * <li>3. The element attributes can be reset. This effectively results in a
+ * retrieval followed by a put. Hence, this is the same as 1.</li>
+ * </ul>
  * 
  * @version $Id: ILateralCacheTCPListener.java,v 1.2 2002/01/18 22:08:26
  */
@@ -41,7 +49,7 @@
     private static final long serialVersionUID = 7814990748035017441L;
 
     /**
-     * can this item be flushed to disk
+     * Can this item be flushed to disk
      */
     public boolean IS_SPOOL = true;
 
@@ -56,24 +64,25 @@
     public boolean IS_REMOTE = true;
 
     /**
-     * can turn off expiration
+     * You can turn off expiration by setting this to true.  This causes the cache
+     * to bypass both max life and idle time expiration.
      */
     public boolean IS_ETERNAL = true;
 
     /**
-     * Description of the Field
+     * The object version. This is currently not used.
      */
     public long version = 0;
 
     /**
      * Max life seconds
      */
-    public long mls = -1;
+    public long maxLifeSeconds = -1;
 
     /**
-     * Description of the Field
+     * The maximum time an entry can be idle.  Setting this to -1 causes the idle time check to be ignored.
      */
-    public long idle = -1;
+    public long maxIdleTimeSeconds = -1;
 
     /**
      * The byte size of teh field. Must be manually set.
@@ -81,17 +90,23 @@
     public int size = 0;
 
     /**
-     * The creation time
+     * The creation time. This is used to enforce the max life.
      */
     public long createTime = 0;
 
     /**
-     * The last access time
+     * The last access time. This is used to enforce the max idel time.
      */
     public long lastAccessTime = 0;
 
     /**
-     * The list of Event handlers to use.
+     * The list of Event handlers to use. This is transient, since the event
+     * handlers cannot usually be serialized. This means that you cannot attach
+     * a post serialization event to an item.
+     * 
+     * TODO we need to check that when an item is passed to a non-local cache
+     * that if the local cache had a copy with event handlers, that those
+     * handlers are used.
      */
     public transient ArrayList eventHandlers;
 
@@ -111,7 +126,6 @@
      */
     protected ElementAttributes( ElementAttributes attr )
     {
-
         IS_ETERNAL = attr.IS_ETERNAL;
 
         // waterfal onto disk, for pure disk set memory to 0
@@ -123,11 +137,10 @@
         // central rmi store
         IS_REMOTE = attr.IS_REMOTE;
 
-        mls = attr.mls;
+        maxLifeSeconds = attr.maxLifeSeconds;
         // timetolive
-        idle = attr.idle;
+        maxIdleTimeSeconds = attr.maxIdleTimeSeconds;
         size = attr.size;
-
     }
 
     /**
@@ -207,7 +220,7 @@
      */
     public void setMaxLifeSeconds( long mls )
     {
-        this.mls = mls;
+        this.maxLifeSeconds = mls;
     }
 
     /*
@@ -217,7 +230,7 @@
      */
     public long getMaxLifeSeconds()
     {
-        return this.mls;
+        return this.maxLifeSeconds;
     }
 
     /*
@@ -227,7 +240,7 @@
      */
     public void setIdleTime( long idle )
     {
-        this.idle = idle;
+        this.maxIdleTimeSeconds = idle;
     }
 
     /*
@@ -285,7 +298,7 @@
      */
     public long getIdleTime()
     {
-        return this.idle;
+        return this.maxIdleTimeSeconds;
     }
 
     /*
@@ -362,7 +375,7 @@
     /**
      * Can this item be sent to the remote cache
      * 
-     * @return The {3} value
+     * @return true if the item can be sent to a remote auxiliary
      */
     public boolean getIsRemote()
     {
@@ -381,9 +394,10 @@
     }
 
     /**
-     * can turn off expiration
+     * You can turn off expiration by setting this to true. The max life value
+     * will be ignored.
      * 
-     * @return The {3} value
+     * @return true if the item cannot expire.
      */
     public boolean getIsEternal()
     {
@@ -391,7 +405,10 @@
     }
 
     /**
-     * Sets the isEternal attribute of the ElementAttributes object
+     * Sets the isEternal attribute of the ElementAttributes object. True means
+     * that the item should never expire. If can still be removed if it is the
+     * least recently used, and you are using the LRUMemory cache. it just will
+     * not be filtered for expiration by the cache hub.
      * 
      * @param val
      *            The new isEternal value
@@ -423,7 +440,10 @@
     }
 
     /**
-     * Sets the eventHandlers of the IElementAttributes object
+     * Sets the eventHandlers of the IElementAttributes object.
+     * <p>
+     * This add the references to the local list. Subsequent changes in the
+     * caller's list will not be reflected.
      * 
      * @param eventHandlers
      *            value

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java Wed Feb 15 15:07:30 2006
@@ -617,7 +617,8 @@
                 long lastAccessTime = attributes.getLastAccessTime();
 
                 // Remove if maxIdleTime exceeded
-                // FIXME: Does this really belong here?
+                // If you have a 0 size memory cache, then the last access will not get updated.
+                // you will need to set the idle time to -1.
 
                 if ( ( idleTime != -1 ) && ( now - lastAccessTime ) > ( idleTime * 1000 ) )
                 {
@@ -1331,4 +1332,13 @@
     {
         return removeCount;
     }
+    
+    /*
+     *  (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
+    public String toString()
+    {      
+        return getStats();        
+    }    
 }

Added: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java?rev=378115&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/config/IUtilConstants.java Wed Feb 15 15:07:30 2006
@@ -0,0 +1,87 @@
+package org.apache.jcs.utils.config;
+
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Description of the Interface
+ *  
+ */
+public interface IUtilConstants
+{
+    /** Description of the Field */
+    public final static String ADMIN_USERID = Config.ADMIN_USERID;
+
+    /** Description of the Field */
+    public final static String ADMIN_PASSWORD = Config.ADMIN_PASSWORD;
+
+    /**
+     * Description of the Class
+     *  
+     */
+    final static class Config
+    {
+        private final static Log log = LogFactory.getLog( Config.class );
+
+        private final static String ADMIN_USERID;
+
+        private final static String ADMIN_PASSWORD;
+
+        static
+        {
+            Properties props = new Properties();
+            InputStream is = null;
+            try
+            {
+                props.load( is = IUtilConstants.class.getResourceAsStream( "/jcsutils.properties" ) );
+            }
+            catch ( IOException ex )
+            {
+                log.warn( ex.getMessage() );
+            }
+            finally
+            {
+                if ( is != null )
+                {
+                    try
+                    {
+                        is.close();
+                    }
+                    catch ( IOException ignore )
+                    {
+                        // swallow
+                    }
+                }
+            }
+            ADMIN_USERID = props.getProperty( "admin.userid", "admin" );
+            ADMIN_PASSWORD = props.getProperty( "admin.password", "system" );
+        }
+
+        /** No instances please. */
+        private Config()
+        {
+            super();
+        }
+    }
+}

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/servlet/BasicHttpAuthenticator.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/servlet/BasicHttpAuthenticator.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/servlet/BasicHttpAuthenticator.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/servlet/BasicHttpAuthenticator.java Wed Feb 15 15:07:30 2006
@@ -21,10 +21,10 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.jcs.utils.config.IUtilConstants;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.utils.config.IUtilConstants;
 
 import sun.misc.BASE64Decoder;
 

Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java Wed Feb 15 15:07:30 2006
@@ -3,6 +3,7 @@
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.Map;
@@ -67,11 +68,11 @@
     public LRUMap()
     {
         list = new DoubleLinkedList();
-        
+
         // normal hshtable is faster for
         // sequential keys.
         map = new Hashtable();
-        //map = new ConcurrentHashMap();
+        // map = new ConcurrentHashMap();
     }
 
     /**
@@ -151,10 +152,18 @@
      * 
      * @see java.util.Map#putAll(java.util.Map)
      */
-    public void putAll( Map t )
+    public void putAll( Map source )
     {
-        // TODO Auto-generated method stub
-
+        if ( source != null )
+        {
+            Set entries = source.entrySet();
+            Iterator it = entries.iterator();
+            while ( it.hasNext() )
+            {
+                Entry entry = (Entry) it.next();
+                this.put( entry.getKey(), entry.getValue() );
+            }
+        }
     }
 
     /*
@@ -166,7 +175,21 @@
     {
         // todo, we should return a defensive copy
         // this is not thread safe.
-        return map.entrySet();
+        Set entries = map.entrySet();
+
+        Set unWrapped = new HashSet();
+
+        Iterator it = entries.iterator();
+        while ( it.hasNext() )
+        {
+            Entry pre = (Entry) it.next();
+
+            Entry post = new LRUMapEntry( pre.getKey(), ( (LRUElementDescriptor) pre.getValue() ).getPayload() );
+
+            unWrapped.add( post );
+        }
+
+        return unWrapped;
     }
 
     /*

Added: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMapEntry.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMapEntry.java?rev=378115&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMapEntry.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMapEntry.java Wed Feb 15 15:07:30 2006
@@ -0,0 +1,64 @@
+package org.apache.jcs.utils.struct;
+
+import java.io.Serializable;
+import java.util.Map.Entry;
+
+/**
+ * Entry for the LRUMap.
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class LRUMapEntry
+    implements Entry, Serializable
+{
+    private static final long serialVersionUID = -8176116317739129331L;
+
+    private Object key;
+
+    private Object value;
+
+    /**
+     * S
+     * @param key
+     * @param value
+     */
+    public LRUMapEntry( Object key, Object value )
+    {
+        this.key = key;
+        this.value = value;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.Map$Entry#getKey()
+     */
+    public Object getKey()
+    {
+        return this.key;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.Map$Entry#getValue()
+     */
+    public Object getValue()
+    {
+        return this.value;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see java.util.Map$Entry#setValue(java.lang.Object)
+     */
+    public Object setValue( Object valueArg )
+    {
+        Object old = this.value;
+        this.value = valueArg;
+        return old;
+    }
+
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java Wed Feb 15 15:07:30 2006
@@ -1,43 +1,48 @@
 package org.apache.jcs.access;
 
+import junit.framework.TestCase;
+
 import org.apache.jcs.access.exception.CacheException;
 import org.apache.jcs.access.exception.ObjectExistsException;
-
-import junit.framework.TestCase;
+import org.apache.jcs.engine.CompositeCacheAttributes;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
+import org.apache.jcs.engine.behavior.IElementAttributes;
 
 /**
  * Tests the methods of the cache access class from which the class JCS extends.
- *
+ * 
  * @author Aaron Smuts
- *
+ * 
  */
 public class CacheAccessUnitTest
     extends TestCase
 {
 
     /**
-     * Verify that we get an object exists exception if the item is in
-     * the cache.
-     *
+     * Verify that we get an object exists exception if the item is in the
+     * cache.
+     * 
      */
     public void testPutSafe()
     {
-        
+
         CacheAccess access = null;
         try
         {
             access = CacheAccess.getAccess( "test" );
-            
+
             assertNotNull( "We should have an access class", access );
         }
         catch ( CacheException e )
         {
             fail( "Shouldn't have received an error." + e.getMessage() );
         }
-        
+
         String key = "mykey";
         String value = "myvalue";
-        
+
         try
         {
             access.put( key, value );
@@ -46,9 +51,9 @@
         {
             fail( "Should have been able to put " + e.getMessage() );
         }
-        String returnedValue1 = (String)access.get( key );
+        String returnedValue1 = (String) access.get( key );
         assertEquals( "Wrong value returned.", value, returnedValue1 );
-        
+
         try
         {
             access.putSafe( key, "someothervalue" );
@@ -56,15 +61,178 @@
         }
         catch ( CacheException e )
         {
-            //e.printStackTrace();
+            // e.printStackTrace();
             // expected
             assertTrue( "Wrong type of exception.", e instanceof ObjectExistsException );
             assertTrue( "Should have the key in the error message.", e.getMessage().indexOf( "[" + key + "]" ) != -1 );
         }
 
-        String returnedValue2 = (String)access.get( key );
+        String returnedValue2 = (String) access.get( key );
         assertEquals( "Wrong value returned.  Shoudl still be the original.", value, returnedValue2 );
     }
+
+    /**
+     * Try to put a null key and verify that we get an exception.
+     * 
+     */
+    public void testPutNullKey()
+    {
+
+        CacheAccess access = null;
+        try
+        {
+            access = CacheAccess.getAccess( "test" );
+
+            assertNotNull( "We should have an access class", access );
+        }
+        catch ( CacheException e )
+        {
+            fail( "Shouldn't have received an error." + e.getMessage() );
+        }
+
+        String key = null;
+        String value = "myvalue";
+
+        try
+        {
+            access.put( key, value );
+            fail( "Should not have been able to put a null key." );
+        }
+        catch ( CacheException e )
+        {
+            // expected
+            assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
+        }
+    }
+
+    /**
+     * Try to put a null value and verify that we get an exception.
+     * 
+     */
+    public void testPutNullValue()
+    {
+
+        CacheAccess access = null;
+        try
+        {
+            access = CacheAccess.getAccess( "test" );
+
+            assertNotNull( "We should have an access class", access );
+        }
+        catch ( CacheException e )
+        {
+            fail( "Shouldn't have received an error." + e.getMessage() );
+        }
+
+        String key = "myKey";
+        String value = null;
+
+        try
+        {
+            access.put( key, value );
+            fail( "Should not have been able to put a null object." );
+        }
+        catch ( CacheException e )
+        {
+            // expected
+            assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
+        }
+    }
+
+    /**
+     * Verify that elements that go in the region after this call takethe new
+     * attributes.
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testSetDefaultElementAttributes()
+        throws Exception
+    {
+
+        CacheAccess access = null;
+
+        access = CacheAccess.getAccess( "test" );
+
+        assertNotNull( "We should have an access class", access );
+
+        long maxLife = 9876;
+        IElementAttributes attr = new ElementAttributes();
+        attr.setMaxLifeSeconds( maxLife );
+
+        access.setDefaultElementAttributes( attr );
+
+        assertEquals( "Wrong element attributes.", attr.getMaxLifeSeconds(), access.getDefaultElementAttributes()
+            .getMaxLifeSeconds() );
+
+        String key = "mykey";
+        String value = "myvalue";
+
+        access.put( key, value );
+
+        ICacheElement element = access.getCacheElement( key );
+
+        assertEquals( "Wrong max life.  Should have the new value.", maxLife, element.getElementAttributes()
+            .getMaxLifeSeconds() );
+    }
+
+    /**
+     * Verify that we can get a region using the define region method.
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testRegionDefiniton()
+        throws Exception
+    {
+        CacheAccess access = CacheAccess.defineRegion( "test" );
+        assertNotNull( "We should have an access class", access );
+    }
+
+    /**
+     * Verify that we can get a region using the define region method with cache attributes.
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testRegionDefinitonWithAttributes()
+        throws Exception
+    {
+        ICompositeCacheAttributes ca = new CompositeCacheAttributes();
+
+        long maxIdleTime = 8765;
+        ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
+
+        CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
+        assertNotNull( "We should have an access class", access );
+
+        ICompositeCacheAttributes ca2 = access.getCacheAttributes();
+        assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
+    }
     
+    /**
+     * Verify that we can get a region using the define region method with cache attributes and elemetn attributes.
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testRegionDefinitonWithBothAttributes()
+        throws Exception
+    {
+        ICompositeCacheAttributes ca = new CompositeCacheAttributes();
+
+        long maxIdleTime = 8765;
+        ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
+
+        long maxLife = 9876;
+        IElementAttributes attr = new ElementAttributes();
+        attr.setMaxLifeSeconds( maxLife );
+        
+        CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
+        assertNotNull( "We should have an access class", access );
+
+        ICompositeCacheAttributes ca2 = access.getCacheAttributes();
+        assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
+    }
     
 }

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java Wed Feb 15 15:07:30 2006
@@ -446,7 +446,7 @@
                             long n_start = System.currentTimeMillis();
                             for ( int n = 0; n < num; n++ )
                             {
-                                IElementAttributes attrp = cache_control.getElementAttributes();
+                                IElementAttributes attrp = cache_control.getDefaultElementAttributes();
                                 ElementEventHandlerMockImpl hand = new ElementEventHandlerMockImpl();
                                 attrp.addElementEventHandler( hand );
                                 cache_control.put( "key" + n, "data" + n + " put from ta = junk", attrp );
@@ -518,7 +518,7 @@
                     }
                     else if ( message.startsWith( "deattr" ) )
                     {
-                        IElementAttributes ae = cache_control.getElementAttributes();
+                        IElementAttributes ae = cache_control.getDefaultElementAttributes();
                         p( "Default IElementAttributes " + ae );
                     }
                     else if ( message.startsWith( "cloneattr" ) )

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java?rev=378115&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/admin/AdminBeanUnitTest.java Wed Feb 15 15:07:30 2006
@@ -0,0 +1,142 @@
+package org.apache.jcs.admin;
+
+import java.util.Iterator;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+
+/**
+ * Test the admin bean that is used by the JCSAdmin.jsp
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class AdminBeanUnitTest
+    extends TestCase
+{
+
+    /**
+     * Create a test region and then verify that we get it from the list.
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testGetRegionInfo()
+        throws Exception
+    {
+        String regionName = "myRegion";
+        JCS cache = JCS.getInstance( regionName );
+
+        cache.put( "key", "value" );
+
+        JCSAdminBean admin = new JCSAdminBean();
+
+        List regions = admin.buildCacheInfo();
+
+        boolean foundRegion = false;
+
+        Iterator it = regions.iterator();
+        while ( it.hasNext() )
+        {
+            CacheRegionInfo info = (CacheRegionInfo) it.next();
+            System.out.println( info );
+
+            if ( info.getCache().getCacheName().equals( regionName ) )
+            {
+                foundRegion = true;
+
+                assertTrue( "Byte count should be greater than 5.", info.getByteCount() > 5 );
+
+                assertNotNull( "Should have stats.", info.getStats() );
+            }
+        }
+
+        assertTrue( "Should have found the region we just created.", foundRegion );
+    }
+
+    /**
+     * Put a value in a region and verify that it shows up.
+     * 
+     * @throws Exception
+     */
+    public void testGetElementForRegionInfo()
+        throws Exception
+    {
+        String regionName = "myRegion";
+        JCS cache = JCS.getInstance( regionName );
+
+        // clear the region
+        cache.clear();
+
+        String key = "myKey";
+        cache.put( key, "value" );
+
+        JCSAdminBean admin = new JCSAdminBean();
+
+        List elements = admin.buildElementInfo( regionName );
+
+        assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
+
+        CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
+        System.out.println( elementInfo );
+        assertEquals( "Wrong key.", key, elementInfo.getKey() );
+    }
+
+    /**
+     * Remove an item via the remove method.
+     * 
+     * @throws Exception
+     */
+    public void testRemove()
+        throws Exception
+    {
+        JCSAdminBean admin = new JCSAdminBean();
+
+        String regionName = "myRegion";
+        JCS cache = JCS.getInstance( regionName );
+
+        // clear the region
+        cache.clear();
+        admin.clearRegion( regionName );
+
+        String key = "myKey";
+        cache.put( key, "value" );
+
+        List elements = admin.buildElementInfo( regionName );
+
+        assertEquals( "Wrong number of elements in the region.", 1, elements.size() );
+
+        CacheElementInfo elementInfo = (CacheElementInfo) elements.get( 0 );
+
+        assertEquals( "Wrong key.", key, elementInfo.getKey() );
+
+        admin.removeItem( regionName, key );
+
+        List elements2 = admin.buildElementInfo( regionName );
+        assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
+    }
+
+    /**
+     * Add an item toa region. Cal clear all and verify that it doesn't exist.
+     * 
+     * @throws Exception
+     */
+    public void testClearAll()
+        throws Exception
+    {
+        JCSAdminBean admin = new JCSAdminBean();
+
+        String regionName = "myRegion";
+        JCS cache = JCS.getInstance( regionName );
+
+        String key = "myKey";
+        cache.put( key, "value" );
+
+        admin.clearAllRegions();
+
+        List elements2 = admin.buildElementInfo( regionName );
+        assertEquals( "Wrong number of elements in the region after remove.", 0, elements2.size() );
+    }
+}

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java?rev=378115&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/admin/CountingStreamUnitTest.java Wed Feb 15 15:07:30 2006
@@ -0,0 +1,55 @@
+package org.apache.jcs.admin;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests for the counting only output stream.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class CountingStreamUnitTest
+    extends TestCase
+{
+
+    /**
+     * Write a single byte and verify the count.
+     * 
+     * @throws Exception
+     */
+    public void testSingleByte() throws Exception
+    {
+        CountingOnlyOutputStream out = new CountingOnlyOutputStream();
+        out.write( 1 );
+        assertEquals( "Wrong number of bytes written.", 1, out.getCount() );
+        out.write( 1 );
+        assertEquals( "Wrong number of bytes written.", 2, out.getCount() );
+    }
+    
+    /**
+     * This should count the size of the array.
+     * 
+     * @throws Exception
+     */
+    public void testByteArray() throws Exception
+    {
+        CountingOnlyOutputStream out = new CountingOnlyOutputStream();
+        byte[] array = new byte[]{1,2,3,4,5};
+        out.write( array );
+        assertEquals( "Wrong number of bytes written.", array.length, out.getCount() );        
+    } 
+    
+    /**
+     * This should count the len -- the tird arg
+     * 
+     * @throws Exception
+     */
+    public void testByteArrayLenCount() throws Exception
+    {
+        CountingOnlyOutputStream out = new CountingOnlyOutputStream();
+        byte[] array = new byte[]{1,2,3,4,5};
+        int len = 3;
+        out.write( array, 0, len );
+        assertEquals( "Wrong number of bytes written.", len, out.getCount() );        
+    }     
+}

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java?rev=378115&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java Wed Feb 15 15:07:30 2006
@@ -0,0 +1,85 @@
+package org.apache.jcs.auxiliary.disk.indexed;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+
+/**
+ * Tests for common functionality.
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class IndexDiskCacheUnitTest
+    extends TestCase
+{
+
+    /**
+     * Simply verify that we can put items in the disk cache and retrieve them.
+     * 
+     */
+    public void testSimplePutAndGet()
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testSimplePutAndGet" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( "testSimplePutAndGet", "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "Should have recevied an element.", element );
+            assertEquals( "Element is wrong.", "data:" + i, element.getVal() );
+        }
+    }
+
+    /**
+     * Add some items to the disk cache and then remove them one by one.
+     * 
+     */
+    public void testRemoveItems()
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testRemoveItems" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( "testRemoveItems", "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        // remove each
+        for ( int i = 0; i < cnt; i++ )
+        {
+            disk.remove( "key:" + i );
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNull( "Should not have recevied an element.", element );
+        }
+    }
+
+}

Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java (from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java&r1=377847&r2=378115&rev=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentNoDeadLockUnitTest.java Wed Feb 15 15:07:30 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.indexed;
+package org.apache.jcs.auxiliary.disk.indexed;
 
 /*
  * Copyright 2001-2004 The Apache Software Foundation.

Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java (from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentUnitTest.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentUnitTest.java&r1=377847&r2=378115&rev=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheConcurrentUnitTest.java Wed Feb 15 15:07:30 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.indexed;
+package org.apache.jcs.auxiliary.disk.indexed;
 
 /*
  * Copyright 2001-2004 The Apache Software Foundation.

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java?rev=378115&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheKeyStoreUnitTest.java Wed Feb 15 15:07:30 2006
@@ -0,0 +1,140 @@
+package org.apache.jcs.auxiliary.disk.indexed;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.engine.CacheElement;
+import org.apache.jcs.engine.ElementAttributes;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.behavior.IElementAttributes;
+
+/**
+ * Test store and load keys.
+ * 
+ * @author Aaron Smuts
+ * 
+ */
+public class IndexedDiskCacheKeyStoreUnitTest
+    extends TestCase
+{
+
+    /**
+     * Add some keys, store them, load them from disk, then check to see that we
+     * can get the items.
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testStoreKeys()
+        throws Exception
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testStoreKeys" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/KeyStoreUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( "testStoreKeys", "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "presave, Should have recevied an element.", element );
+            assertEquals( "presave, element is wrong.", "data:" + i, element.getVal() );
+        }
+
+        disk.saveKeys();
+
+        disk.loadKeys();
+
+        assertEquals( "The disk is the wrong size.", cnt, disk.getSize() );
+
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "postsave, Should have recevied an element.", element );
+            assertEquals( "postsave, element is wrong.", "data:" + i, element.getVal() );
+        }
+
+        disk.dump();
+        
+    }
+
+    
+    /**
+     * Add some elements, remove 1, call optiiize, verify that the removed isn't present.
+     * 
+     * We should also compare the data file sizes. . . .
+     * 
+     * @throws Exception
+     * 
+     */
+    public void testOptiimize()
+        throws Exception
+    {
+        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        cattr.setCacheName( "testOptiimize" );
+        cattr.setMaxKeySize( 100 );
+        cattr.setDiskPath( "target/test-sandbox/KeyStoreUnitTest" );
+        IndexedDiskCache disk = new IndexedDiskCache( cattr );
+
+        disk.doRemoveAll();
+
+        int cnt = 25;
+        for ( int i = 0; i < cnt; i++ )
+        {
+            IElementAttributes eAttr = new ElementAttributes();
+            eAttr.setIsSpool( true );
+            ICacheElement element = new CacheElement( "testOptiimize", "key:" + i, "data:" + i );
+            element.setElementAttributes( eAttr );
+            disk.doUpdate( element );
+        }
+        
+        long preAddRemoveSize = disk.getDataFileSize();
+        
+        IElementAttributes eAttr = new ElementAttributes();
+        eAttr.setIsSpool( true );
+        ICacheElement elementSetup = new CacheElement( "testOptiimize", "key:" + "A", "data:" + "A" );
+        elementSetup.setElementAttributes( eAttr );
+        disk.doUpdate( elementSetup );
+                
+        ICacheElement elementRet = disk.doGet( "key:" + "A" );
+        assertNotNull( "postsave, Should have recevied an element.", elementRet );
+        assertEquals( "postsave, element is wrong.", "data:" + "A", elementRet.getVal() );
+        
+        disk.remove( "key:" + "A" );
+
+        long preSize = disk.getDataFileSize();
+        // synchronous versoin
+        disk.optimizeRealTime();
+        long postSize = disk.getDataFileSize();
+        
+        System.out.println( "preAddRemoveSize " + preAddRemoveSize );
+        System.out.println( "preSize " + preSize );
+        System.out.println( "postSize " + postSize );
+        
+        assertTrue( "Should be smaller.", postSize < preSize );
+        assertEquals( "Should be the same size after optimization as before add and remove.", preAddRemoveSize, postSize );
+              
+        for ( int i = 0; i < cnt; i++ )
+        {
+            ICacheElement element = disk.doGet( "key:" + i );
+            assertNotNull( "postsave, Should have recevied an element.", element );
+            assertEquals( "postsave, element is wrong.", "data:" + i, element.getVal() );
+        }
+        
+        
+        
+    }
+        
+        
+}

Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java (from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheNoMemoryUnitTest.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheNoMemoryUnitTest.java&r1=377847&r2=378115&rev=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheNoMemoryUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheNoMemoryUnitTest.java Wed Feb 15 15:07:30 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.indexed;
+package org.apache.jcs.auxiliary.disk.indexed;
 
 /*
  * Copyright 2001-2004 The Apache Software Foundation.

Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java (from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java&r1=377847&r2=378115&rev=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheRandomConcurrentTestUtil.java Wed Feb 15 15:07:30 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.indexed;
+package org.apache.jcs.auxiliary.disk.indexed;
 
 import junit.framework.TestCase;
 

Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java (from r377847, jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java&r1=377847&r2=378115&rev=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java Wed Feb 15 15:07:30 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.auxiliary.indexed;
+package org.apache.jcs.auxiliary.disk.indexed;
 
 /*
  * Copyright 2001-2004 The Apache Software Foundation.

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java Wed Feb 15 15:07:30 2006
@@ -95,7 +95,7 @@
 
         JCS jcs = JCS.getInstance( "WithDisk" );
         // this should add the event handler to all items as they are created.
-        jcs.getElementAttributes().addElementEventHandler( meh );
+        jcs.getDefaultElementAttributes().addElementEventHandler( meh );
 
         // put them in
         for ( int i = 0; i <= items; i++ )
@@ -124,7 +124,7 @@
 
         JCS jcs = JCS.getInstance( "NoDisk" );
         // this should add the event handler to all items as they are created.
-        jcs.getElementAttributes().addElementEventHandler( meh );
+        jcs.getDefaultElementAttributes().addElementEventHandler( meh );
 
         // put them in
         for ( int i = 0; i <= items; i++ )
@@ -153,7 +153,7 @@
 
         JCS jcs = JCS.getInstance( "DiskButNotAllowed" );
         // this should add the event handler to all items as they are created.
-        jcs.getElementAttributes().addElementEventHandler( meh );
+        jcs.getDefaultElementAttributes().addElementEventHandler( meh );
 
         // put them in
         for ( int i = 0; i <= items; i++ )

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapUnitTest.java?rev=378115&r1=378114&r2=378115&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/LRUMapUnitTest.java Wed Feb 15 15:07:30 2006
@@ -1,6 +1,8 @@
 package org.apache.jcs.utils.struct;
 
 import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
 
 import org.apache.jcs.utils.struct.LRUMap;
 
@@ -85,6 +87,32 @@
         assertNull( "Shouldn't hvae anything.", returned );
     }
     
+    
+    /**
+     * Add items to the map and then test to see that they come back in the entry set.
+     *
+     */
+    public void testGetEntrySet()
+    {
+        int size = 10;
+        Map cache = new LRUMap( size );
+        
+        for ( int i = 0; i < size; i++ )
+        {
+            cache.put( "key:" + i, "data:" + i );
+        }
+        
+        Set entries = cache.entrySet();
+        assertEquals( "Set contains the wrong number of items.", size, entries.size() );
+        
+        // check minimal correctness
+        Object[] entryArray = entries.toArray();
+        for ( int i = 0; i < size; i++ )
+        {
+            Entry data = (Entry)entryArray[i];
+            assertTrue( "Data is wrong.", data.getValue().toString().indexOf( "data:") != -1  );
+        }        
+    }    
     
     
 }



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