Author: asmuts
Date: Wed Aug 16 10:40:26 2006
New Revision: 431961
URL: http://svn.apache.org/viewvc?rev=431961&view=rev
Log:
https://issues.apache.org/jira/browse/JCS-2
I'm adding a configuration option to the CompositeCacheAttributes. It's called
DiskUsagePattern. There are two patterns: update and swap. The changes are
isolated to the CompositeCache class and they are very easy to unit test.
SWAP is the default. Under the swap pattern, data is only put to disk when the
max memory size is reached. Since items puled from disk are put into memory,
if the memory cache is full and you get an item off disk, the lest recently
used item will be spooled to disk. If you have a low memory hit ration, you
end up thrashing.
The UPDATE usage pattern allows items to go to disk on an update. It disables
the swap. This allows you to persist all items to disk. If you are using the
JDBC disk cache for instance, you can get all item on disk use the memory cache
for performance, and not worry aobut lossing data on a system crash or improper
shutdown. Also, since all items are on disk, there is no need to swap to disk.
This prevents the possibility of threashing.
The configuration is done at the region level. The attrribute is called
DiskUsagePatternName and takes two values: SWAP and UPDATE.
For example, below there is a region defined called "Swap" that uses the SWAP
disk usage pattern and another called "Update" that uses the UPDATE usage
pattern.
##### CACHE REGIONS FOR TEST
jcs.region.Swap=indexedDiskCache
jcs.region.Swap.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.Swap.cacheattributes.MaxObjects=100
jcs.region.Swap.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.Swap.cacheattributes.DiskUsagePatternName=SWAP
jcs.region.Update=indexedDiskCache
jcs.region.Update.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.Update.cacheattributes.MaxObjects=100
jcs.region.Update.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.Update.cacheattributes.DiskUsagePatternName=UPDATE
Added:
jakarta/jcs/trunk/src/test-conf/TestDiskCacheUsagePattern.ccf
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CompositeCacheAttributes.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICompositeCacheAttributes.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CompositeCacheAttributes.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CompositeCacheAttributes.java?rev=431961&r1=431960&r2=431961&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CompositeCacheAttributes.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/CompositeCacheAttributes.java
Wed Aug 16 10:40:26 2006
@@ -1,25 +1,22 @@
package org.apache.jcs.engine;
/*
- * 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.
+ * 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 org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
/**
- * The CompositeCacheAttributes defines the general cache region settings. If a
- * region is not explicitly defined in the cache.ccf then it inherits the cache
- * default settings.
+ * The CompositeCacheAttributes defines the general cache region settings. If
a region is not
+ * explicitly defined in the cache.ccf then it inherits the cache default
settings.
* <p>
- * If all the default attributes are not defined in the default region
- * definition in the cache.ccf, the hard coded defaults will be used.
+ * If all the default attributes are not defined in the default region
definition in the cache.ccf,
+ * the hard coded defaults will be used.
*/
public class CompositeCacheAttributes
implements ICompositeCacheAttributes, Cloneable
@@ -72,6 +69,8 @@
/** The name of the memory cache implementation class. */
private String memoryCacheName;
+ private short diskUsagePattern = DISK_USAGE_PATTERN_SWAP;
+
/**
* Constructor for the CompositeCacheAttributes object
*/
@@ -85,8 +84,7 @@
/**
* Sets the maxObjects attribute of the CompositeCacheAttributes object
* <p>
- * @param maxObjs
- * The new maxObjects value
+ * @param maxObjs The new maxObjects value
*/
public void setMaxObjects( int maxObjs )
{
@@ -106,8 +104,7 @@
/**
* Sets the useDisk attribute of the CompositeCacheAttributes object
* <p>
- * @param useDisk
- * The new useDisk value
+ * @param useDisk The new useDisk value
*/
public void setUseDisk( boolean useDisk )
{
@@ -127,8 +124,7 @@
/**
* Sets the useLateral attribute of the CompositeCacheAttributes object
* <p>
- * @param b
- * The new useLateral value
+ * @param b The new useLateral value
*/
public void setUseLateral( boolean b )
{
@@ -148,8 +144,7 @@
/**
* Sets the useRemote attribute of the CompositeCacheAttributes object
* <p>
- * @param useRemote
- * The new useRemote value
+ * @param useRemote The new useRemote value
*/
public void setUseRemote( boolean useRemote )
{
@@ -169,8 +164,7 @@
/**
* Sets the cacheName attribute of the CompositeCacheAttributes object
* <p>
- * @param s
- * The new cacheName value
+ * @param s The new cacheName value
*/
public void setCacheName( String s )
{
@@ -190,8 +184,7 @@
/**
* Sets the memoryCacheName attribute of the CompositeCacheAttributes
object
* <p>
- * @param s
- * The new memoryCacheName value
+ * @param s The new memoryCacheName value
*/
public void setMemoryCacheName( String s )
{
@@ -211,8 +204,7 @@
/**
* Whether the memory cache should perform background memory shrinkage.
* <p>
- * @param useShrinker
- * The new UseMemoryShrinker value
+ * @param useShrinker The new UseMemoryShrinker value
*/
public void setUseMemoryShrinker( boolean useShrinker )
{
@@ -230,11 +222,9 @@
}
/**
- * If UseMemoryShrinker is true the memory cache should auto-expire
elements
- * to reclaim space.
+ * If UseMemoryShrinker is true the memory cache should auto-expire
elements to reclaim space.
* <p>
- * @param seconds
- * The new MaxMemoryIdleTimeSeconds value
+ * @param seconds The new MaxMemoryIdleTimeSeconds value
*/
public void setMaxMemoryIdleTimeSeconds( long seconds )
{
@@ -242,8 +232,7 @@
}
/**
- * If UseMemoryShrinker is true the memory cache should auto-expire
elements
- * to reclaim space.
+ * If UseMemoryShrinker is true the memory cache should auto-expire
elements to reclaim space.
* <p>
* @return The MaxMemoryIdleTimeSeconds value
*/
@@ -253,11 +242,10 @@
}
/**
- * If UseMemoryShrinker is true the memory cache should auto-expire
elements
- * to reclaim space. This sets the shrinker interval.
+ * If UseMemoryShrinker is true the memory cache should auto-expire
elements to reclaim space.
+ * This sets the shrinker interval.
* <p>
- * @param seconds
- * The new ShrinkerIntervalSeconds value
+ * @param seconds The new ShrinkerIntervalSeconds value
*/
public void setShrinkerIntervalSeconds( long seconds )
{
@@ -265,8 +253,8 @@
}
/**
- * If UseMemoryShrinker is true the memory cache should auto-expire
elements
- * to reclaim space. This gets the shrinker interval.
+ * If UseMemoryShrinker is true the memory cache should auto-expire
elements to reclaim space.
+ * This gets the shrinker interval.
* <p>
* @return The ShrinkerIntervalSeconds value
*/
@@ -276,14 +264,12 @@
}
/**
- * If UseMemoryShrinker is true the memory cache should auto-expire
elements
- * to reclaim space. This sets the maximum number of items to spool per
run.
+ * If UseMemoryShrinker is true the memory cache should auto-expire
elements to reclaim space.
+ * This sets the maximum number of items to spool per run.
* <p>
- * If the value is -1, then there is no limit to the number of items to be
- * spooled.
+ * If the value is -1, then there is no limit to the number of items to be
spooled.
* <p>
- * @param maxSpoolPerRun
- * The new maxSpoolPerRun value
+ * @param maxSpoolPerRun The new maxSpoolPerRun value
*/
public void setMaxSpoolPerRun( int maxSpoolPerRun )
{
@@ -291,8 +277,8 @@
}
/**
- * If UseMemoryShrinker is true the memory cache should auto-expire
elements
- * to reclaim space. This gets the maximum number of items to spool per
run.
+ * If UseMemoryShrinker is true the memory cache should auto-expire
elements to reclaim space.
+ * This gets the maximum number of items to spool per run.
* <p>
* @return The maxSpoolPerRun value
*/
@@ -302,6 +288,47 @@
}
/**
+ * By default this is SWAP_ONLY.
+ * <p>
+ * @param diskUsagePattern The diskUsagePattern to set.
+ */
+ public void setDiskUsagePattern( short diskUsagePattern )
+ {
+ this.diskUsagePattern = diskUsagePattern;
+ }
+
+ /**
+ * Translates the name to the disk usage pattern short value.
+ * <p>
+ * The allowed values are SWAP and UPDATE.
+ * <p>
+ * @param diskUsagePatternName The diskUsagePattern to set.
+ */
+ public void setDiskUsagePatternName( String diskUsagePatternName )
+ {
+ if ( diskUsagePatternName != null )
+ {
+ diskUsagePatternName = diskUsagePatternName.toUpperCase().trim();
+ if ( diskUsagePatternName.startsWith( "SWAP" ) )
+ {
+ this.setDiskUsagePattern( DISK_USAGE_PATTERN_SWAP );
+ }
+ else if ( diskUsagePatternName.startsWith( "UPDATE" ) )
+ {
+ this.setDiskUsagePattern( DISK_USAGE_PATTERN_UPDATE );
+ }
+ }
+ }
+
+ /**
+ * @return Returns the diskUsagePattern.
+ */
+ public short getDiskUsagePattern()
+ {
+ return diskUsagePattern;
+ }
+
+ /**
* Description of the Method
* <p>
* @return
@@ -321,9 +348,9 @@
}
/**
- * Description of the Method
+ * Dumps the core attributes.
* <p>
- * @return
+ * @return For debugging.
*/
public String toString()
{
@@ -335,10 +362,9 @@
dump.append( ", useDisk = " ).append( useDisk );
dump.append( ", maxObjs = " ).append( maxObjs );
dump.append( ", maxSpoolPerRun = " ).append( maxSpoolPerRun );
+ dump.append( ", diskUsagePattern = " ).append( diskUsagePattern );
dump.append( " ]" );
return dump.toString();
}
-
}
-// end class
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICompositeCacheAttributes.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICompositeCacheAttributes.java?rev=431961&r1=431960&r2=431961&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICompositeCacheAttributes.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/behavior/ICompositeCacheAttributes.java
Wed Aug 16 10:40:26 2006
@@ -19,21 +19,28 @@
import java.io.Serializable;
/**
- * Description of the Interface
- *
+ * This defines the minimla behavior for the Cache Configuration settings.
*/
public interface ICompositeCacheAttributes
extends Serializable
{
+ /** Items will only go to disk when the memory limit is reached. This is
the default. */
+ public static final short DISK_USAGE_PATTERN_SWAP = 0;
/**
+ * Items will go to disk on a normal put. If The disk usage pattern is
UPDATE, the swap will be
+ * disabled.
+ */
+ public static final short DISK_USAGE_PATTERN_UPDATE = 1;
+
+ /**
* SetMaxObjects is used to set the attribute to determine the maximum
* number of objects allowed in the memory cache. If the max number of
* objects or the cache size is set, the default for the one not set is
* ignored. If both are set, both are used to determine the capacity of the
* cache, i.e., object will be removed from the cache if either limit is
* reached. TODO: move to MemoryCache config file.
- *
+ * <p>
* @param size
* The new maxObjects value
*/
@@ -41,14 +48,14 @@
/**
* Gets the maxObjects attribute of the ICompositeCacheAttributes object
- *
+ * <p>
* @return The maxObjects value
*/
public int getMaxObjects();
/**
* Sets the useDisk attribute of the ICompositeCacheAttributes object
- *
+ * <p>
* @param useDisk
* The new useDisk value
*/
@@ -56,14 +63,14 @@
/**
* Gets the useDisk attribute of the ICompositeCacheAttributes object
- *
+ * <p>
* @return The useDisk value
*/
public boolean getUseDisk();
/**
* set whether the cache should use a lateral cache
- *
+ * <p>
* @param d
* The new useLateral value
*/
@@ -71,14 +78,14 @@
/**
* Gets the useLateral attribute of the ICompositeCacheAttributes object
- *
+ * <p>
* @return The useLateral value
*/
public boolean getUseLateral();
/**
* Sets whether the cache is remote enabled
- *
+ * <p>
* @param isRemote
* The new useRemote value
*/
@@ -86,14 +93,14 @@
/**
* returns whether the cache is remote enabled
- *
+ * <p>
* @return The useRemote value
*/
public boolean getUseRemote();
/**
* Sets the name of the cache, referenced by the appropriate manager.
- *
+ * <p>
* @param s
* The new cacheName value
*/
@@ -101,7 +108,7 @@
/**
* Gets the cacheName attribute of the ICompositeCacheAttributes object
- *
+ * <p>
* @return The cacheName value
*/
public String getCacheName();
@@ -109,7 +116,7 @@
/**
* Sets the name of the MemoryCache, referenced by the appropriate manager.
* TODO: create a separate memory cache attribute class.
- *
+ * <p>
* @param s
* The new memoryCacheName value
*/
@@ -118,14 +125,14 @@
/**
* Gets the memoryCacheName attribute of the ICompositeCacheAttributes
* object
- *
+ * <p>
* @return The memoryCacheName value
*/
public String getMemoryCacheName();
/**
* Whether the memory cache should perform background memory shrinkage.
- *
+ * <p>
* @param useShrinker
* The new UseMemoryShrinker value
*/
@@ -133,7 +140,7 @@
/**
* Whether the memory cache should perform background memory shrinkage.
- *
+ * <p>
* @return The UseMemoryShrinker value
*/
public boolean getUseMemoryShrinker();
@@ -141,7 +148,7 @@
/**
* If UseMemoryShrinker is true the memory cache should auto-expire
elements
* to reclaim space.
- *
+ * <p>
* @param seconds
* The new MaxMemoryIdleTimeSeconds value
*/
@@ -150,7 +157,7 @@
/**
* If UseMemoryShrinker is true the memory cache should auto-expire
elements
* to reclaim space.
- *
+ * <p>
* @return The MaxMemoryIdleTimeSeconds value
*/
public long getMaxMemoryIdleTimeSeconds();
@@ -158,7 +165,7 @@
/**
* If UseMemoryShrinker is true the memory cache should auto-expire
elements
* to reclaim space. This sets the shrinker interval.
- *
+ * <p>
* @param seconds
* The new ShrinkerIntervalSeconds value
*/
@@ -167,7 +174,7 @@
/**
* If UseMemoryShrinker is true the memory cache should auto-expire
elements
* to reclaim space. This gets the shrinker interval.
- *
+ * <p>
* @return The ShrinkerIntervalSeconds value
*/
public long getShrinkerIntervalSeconds();
@@ -175,7 +182,7 @@
/**
* If UseMemoryShrinker is true the memory cache should auto-expire
elements
* to reclaim space. This sets the maximum number of items to spool per
run.
- *
+ * <p>
* @param maxSpoolPerRun
* The new maxSpoolPerRun value
*/
@@ -184,17 +191,36 @@
/**
* If UseMemoryShrinker is true the memory cache should auto-expire
elements
* to reclaim space. This gets the maximum number of items to spool per
run.
- *
+ * <p>
* @return The maxSpoolPerRun value
*/
public int getMaxSpoolPerRun();
- // soultion to interface cloning
/**
- * Description of the Method
- *
- * @return
+ * Clones the attributes.
+ * <p>
+ * @return a new object with the same settings.
*/
public ICompositeCacheAttributes copy();
+ /**
+ * By default this is SWAP_ONLY.
+ * <p>
+ * @param diskUsagePattern The diskUsagePattern to set.
+ */
+ public void setDiskUsagePattern( short diskUsagePattern );
+
+ /**
+ * Translates the name to the disk usage pattern short value.
+ * <p>
+ * The allowed values are SWAP and UPDATE.
+ * <p>
+ * @param diskUsagePatternName The diskUsagePattern to set.
+ */
+ public void setDiskUsagePatternName( String diskUsagePatternName );
+
+ /**
+ * @return Returns the diskUsagePattern.
+ */
+ public short getDiskUsagePattern();
}
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=431961&r1=431960&r2=431961&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 Aug 16 10:40:26 2006
@@ -210,11 +210,13 @@
* <p>
* This is called by update( cacheElement, localOnly ) after it updates
the memory cache.
* <p>
+ * This is protected to make it testable.
+ * <p>
* @param cacheElement
* @param localOnly
* @throws IOException
*/
- private void updateAuxiliaries( ICacheElement cacheElement, boolean
localOnly )
+ protected void updateAuxiliaries( ICacheElement cacheElement, boolean
localOnly )
throws IOException
{
// UPDATE AUXILLIARY CACHES
@@ -280,8 +282,7 @@
else if ( aux.getCacheType() == ICache.LATERAL_CACHE )
{
// lateral can't do the checking since it is dependent on the
- // cache region
- // restrictions
+ // cache region restrictions
if ( log.isDebugEnabled() )
{
log.debug( "lateralcache in aux list: cattr " +
cacheAttr.getUseLateral() );
@@ -301,18 +302,34 @@
}
}
}
+ // update disk if the usage pattern permits
else if ( aux.getCacheType() == ICache.DISK_CACHE )
{
- // do nothing, the memory manager will call spool where
necesary
- // TODO: add option to put all element on disk
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "diskcache in aux list: cattr " +
cacheAttr.getUseDisk() );
+ }
+ if ( cacheAttr.getUseDisk()
+ && ( cacheAttr.getDiskUsagePattern() ==
ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE )
+ && cacheElement.getElementAttributes().getIsSpool() )
+ {
+ aux.update( cacheElement );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "updated disk cache for " +
cacheElement.getKey() );
+ }
+ }
}
}
}
/**
- * Writes the specified element to any disk auxilliaries .Might want to
rename this "overflow"
+ * Writes the specified element to any disk auxilliaries. Might want to
rename this "overflow"
* incase the hub wants to do something else.
* <p>
+ * If JCS is not configured to use the disk as a swap, that is if the the
+ * CompositeCacheAttribute diskUsagePattern is not SWAP_ONLY, then the
item will not be spooled.
+ * <p>
* @param ce The CacheElement
*/
public void spoolToDisk( ICacheElement ce )
@@ -336,26 +353,36 @@
{
diskAvailable = true;
- // write the last items to disk.2
- try
+ if ( cacheAttr.getDiskUsagePattern() ==
ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP )
{
- handleElementEvent( ce,
IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE );
+ // write the last items to disk.2
+ try
+ {
+ handleElementEvent( ce,
IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE );
- aux.update( ce );
- }
- catch ( IOException ex )
- {
- // impossible case.
- ex.printStackTrace();
- throw new IllegalStateException( ex.getMessage() );
- }
- catch ( Exception oee )
- {
- // swallow
+ aux.update( ce );
+ }
+ catch ( IOException ex )
+ {
+ // impossible case.
+ log.error( "Problem spooling item to disk cache.", ex
);
+ throw new IllegalStateException( ex.getMessage() );
+ }
+ catch ( Exception oee )
+ {
+ // swallow
+ }
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "spoolToDisk done for: " + ce.getKey() + "
on disk cache[" + i + "]" );
+ }
}
- if ( log.isDebugEnabled() )
+ else
{
- log.debug( "spoolToDisk done for: " + ce.getKey() + " on
disk cache[" + i + "]" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "DiskCache avaialbe, but JCS is not
configured to use the DiskCache as a swap." );
+ }
}
}
}
@@ -901,7 +928,7 @@
log.info( "In dispose, " + this.cacheName + " put " + cnt
+ " into auxiliary " + aux );
}
-
+
// Dispose of the auxiliary
aux.dispose();
}
Added: jakarta/jcs/trunk/src/test-conf/TestDiskCacheUsagePattern.ccf
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestDiskCacheUsagePattern.ccf?rev=431961&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestDiskCacheUsagePattern.ccf (added)
+++ jakarta/jcs/trunk/src/test-conf/TestDiskCacheUsagePattern.ccf Wed Aug 16
10:40:26 2006
@@ -0,0 +1,69 @@
+# Cache configuration for the 'TestDiskCache' test. The memory cache has a
+# a maximum of 100 objects, so objects should get pushed into the disk cache
+
+jcs.default=indexedDiskCache
+jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.default.cacheattributes.MaxObjects=100
+jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+
+
+##### CACHE REGIONS FOR TEST
+jcs.region.Swap=indexedDiskCache
+jcs.region.Swap.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.Swap.cacheattributes.MaxObjects=100
+jcs.region.Swap.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.Swap.cacheattributes.DiskUsagePatternName=SWAP
+
+jcs.region.Update=indexedDiskCache
+jcs.region.Update.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
+jcs.region.Update.cacheattributes.MaxObjects=100
+jcs.region.Update.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
+jcs.region.Update.cacheattributes.DiskUsagePatternName=UPDATE
+
+
+##### AUXILIARY CACHES
+# Indexed Disk Cache
+jcs.auxiliary.indexedDiskCache=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
+jcs.auxiliary.indexedDiskCache.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
+jcs.auxiliary.indexedDiskCache.attributes.DiskPath=target/test-sandbox/indexed-disk-cache-conc
+jcs.auxiliary.indexedDiskCache.attributes.MaxPurgatorySize=10000
+jcs.auxiliary.indexedDiskCache.attributes.MaxKeySize=10000
+jcs.auxiliary.indexedDiskCache.attributes.MaxRecycleBinSize=5000
+jcs.auxiliary.indexedDiskCache.attributes.OptimizeAtRemoveCount=300000
+jcs.auxiliary.indexedDiskCache.attributes.EventQueueType=SINGLE
+jcs.auxiliary.indexedDiskCache.attributes.EventQueuePoolName=disk_cache_event_queue
+
+
+##############################################################
+################## THREAD POOL CONFIGURATION ###################
+# Default thread pool config
+thread_pool.default.boundarySize=2000
+thread_pool.default.maximumPoolSize=150
+thread_pool.default.minimumPoolSize=4
+thread_pool.default.keepAliveTime=350000
+#RUN ABORT WAIT BLOCK DISCARDOLDEST
+thread_pool.default.whenBlockedPolicy=RUN
+thread_pool.default.startUpSize=4
+
+# Default Cache Event Queue thread pool config, used by auxiliaries
+thread_pool.cache_event_queue.useBoundary=false
+#thread_pool.cache_event_queue.boundarySize=2000
+#thread_pool.cache_event_queue.maximumPoolSize=10
+thread_pool.cache_event_queue.minimumPoolSize=1
+thread_pool.cache_event_queue.keepAliveTime=3500
+#thread_pool.cache_event_queue.whenBlockedPolicy=RUN
+thread_pool.cache_event_queue.startUpSize=1
+
+# Disk Cache pool
+thread_pool.disk_cache_event_queue.useBoundary=false
+thread_pool.disk_cache_event_queue.minimumPoolSize=2
+thread_pool.disk_cache_event_queue.keepAliveTime=3500
+thread_pool.disk_cache_event_queue.startUpSize=10
+
+# Remote cache client thread pool config
+thread_pool.remote_cache_client.boundarySize=75
+thread_pool.remote_cache_client.maximumPoolSize=150
+thread_pool.remote_cache_client.minimumPoolSize=4
+thread_pool.remote_cache_client.keepAliveTime=350000
+thread_pool.remote_cache_client.whenBlockedPolicy=RUN
+thread_pool.remote_cache_client.startUpSize=4
Added:
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
URL:
http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java?rev=431961&view=auto
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
(added)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheDiskUsageUnitTest.java
Wed Aug 16 10:40:26 2006
@@ -0,0 +1,421 @@
+package org.apache.jcs.engine.control;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.access.exception.CacheException;
+import org.apache.jcs.auxiliary.AuxiliaryCache;
+import org.apache.jcs.engine.CacheElement;
+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;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
+/**
+ * Tests of the disk usage settings for the CompositeCache.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class CompositeCacheDiskUsageUnitTest
+ extends TestCase
+{
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestDiskCacheUsagePattern.ccf" );
+ }
+
+ /**
+ * Verify that the swap region is set to the correct pattern.
+ * <p>
+ * @throws CacheException
+ */
+ public void testSwapConfig() throws CacheException
+ {
+ JCS swap = JCS.getInstance( "Swap" );
+ assertEquals( ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP,
swap.getCacheAttributes().getDiskUsagePattern() );
+ }
+
+ /**
+ * Verify that the swap region is set to the correct pattern.
+ * <p>
+ * @throws CacheException
+ */
+ public void testUpdateConfig() throws CacheException
+ {
+ JCS swap = JCS.getInstance( "Update" );
+ assertEquals( ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE,
swap.getCacheAttributes().getDiskUsagePattern() );
+ }
+
+ /**
+ * Setup a disk cache. Configure the disk usage pattern to swap. Call
spool. Verify that the
+ * item is put to disk.
+ */
+ public void testSpoolAllowed()
+ {
+ // SETUP
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setDiskUsagePattern(
ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP );
+
+ IElementAttributes attr = new ElementAttributes();
+
+ CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr,
attr );
+
+ MockAuxCache mock = new MockAuxCache();
+ mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+ cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+ ICacheElement inputElement = new CacheElement( "testSpoolAllowed",
"key", "value" );
+
+ // DO WORK
+ cache.spoolToDisk( inputElement );
+
+ // VERIFY
+ assertEquals( "Wrong number of calls to the disk cache update.", 1,
mock.updateCount );
+ assertEquals( "Wrong element updated.", inputElement,
mock.lastUpdatedItem );
+ }
+
+ /**
+ * Setup a disk cache. Configure the disk usage pattern to not swap. Call
spool. Verify that the
+ * item is not put to disk.
+ */
+ public void testSpoolNotAllowed()
+ {
+ // SETUP
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setDiskUsagePattern(
ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+ IElementAttributes attr = new ElementAttributes();
+
+ CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr,
attr );
+
+ MockAuxCache mock = new MockAuxCache();
+ mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+ cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+ ICacheElement inputElement = new CacheElement( "testSpoolAllowed",
"key", "value" );
+
+ // DO WORK
+ cache.spoolToDisk( inputElement );
+
+ // VERIFY
+ assertEquals( "Wrong number of calls to the disk cache update.", 0,
mock.updateCount );
+ }
+
+ /**
+ * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call
updateAuxiliaries.
+ * Verify that the item is put to disk.
+ * <p>
+ * This tests that the items are put to disk on a normal put when the
usage pattern is set
+ * appropriately.
+ * @throws IOException
+ */
+ public void testUpdateAllowed()
+ throws IOException
+ {
+ // SETUP
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setDiskUsagePattern(
ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+ IElementAttributes attr = new ElementAttributes();
+
+ CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr,
attr );
+
+ MockAuxCache mock = new MockAuxCache();
+ mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+ cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+ ICacheElement inputElement = new CacheElement( "testSpoolAllowed",
"key", "value" );
+
+ // DO WORK
+ cache.updateAuxiliaries( inputElement, true );
+
+ // VERIFY
+ assertEquals( "Wrong number of calls to the disk cache update.", 1,
mock.updateCount );
+ assertEquals( "Wrong element updated.", inputElement,
mock.lastUpdatedItem );
+ }
+
+ /**
+ * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call
updateAuxiliaries with
+ * local only set to false. Verify that the item is put to disk.
+ * <p>
+ * This tests that the items are put to disk on a normal put when the
usage pattern is set
+ * appropriately. The local setting should have no impact on whether the
item goes to disk.
+ * <p>
+ * @throws IOException
+ */
+ public void testUpdateAllowed_localFalse()
+ throws IOException
+ {
+ // SETUP
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setDiskUsagePattern(
ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+ IElementAttributes attr = new ElementAttributes();
+
+ CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr,
attr );
+
+ MockAuxCache mock = new MockAuxCache();
+ mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+ cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+ ICacheElement inputElement = new CacheElement( "testSpoolAllowed",
"key", "value" );
+
+ // DO WORK
+ cache.updateAuxiliaries( inputElement, false );
+
+ // VERIFY
+ assertEquals( "Wrong number of calls to the disk cache update.", 1,
mock.updateCount );
+ assertEquals( "Wrong element updated.", inputElement,
mock.lastUpdatedItem );
+ }
+
+ /**
+ * Setup a disk cache. Configure the disk usage pattern to SWAP. Call
updateAuxiliaries. Verify
+ * that the item is not put to disk.
+ * <p>
+ * This tests that the items are not put to disk on a normal put when the
usage pattern is set
+ * to SWAP.
+ * <p>
+ * @throws IOException
+ */
+ public void testUpdateNotAllowed()
+ throws IOException
+ {
+ // SETUP
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setDiskUsagePattern(
ICompositeCacheAttributes.DISK_USAGE_PATTERN_SWAP );
+
+ IElementAttributes attr = new ElementAttributes();
+
+ CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr,
attr );
+
+ MockAuxCache mock = new MockAuxCache();
+ mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+ cache.setAuxCaches( new AuxiliaryCache[] { mock } );
+
+ ICacheElement inputElement = new CacheElement( "testSpoolAllowed",
"key", "value" );
+
+ // DO WORK
+ cache.updateAuxiliaries( inputElement, true );
+
+ // VERIFY
+ assertEquals( "Wrong number of calls to the disk cache update.", 0,
mock.updateCount );
+ }
+
+ /**
+ * Setup a disk cache. Configure the disk usage pattern to UPDATE. Call
updateAuxiliaries.
+ * Verify that the item is put to disk.
+ * <p>
+ * This tests that the items are put to disk on a normal put when the
usage pattern is set
+ * appropriately.
+ * @throws IOException
+ */
+ public void testUpdateAllowed_withOtherCaches()
+ throws IOException
+ {
+ // SETUP
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setDiskUsagePattern(
ICompositeCacheAttributes.DISK_USAGE_PATTERN_UPDATE );
+
+ IElementAttributes attr = new ElementAttributes();
+
+ CompositeCache cache = new CompositeCache( "testSpoolAllowed", cattr,
attr );
+
+ MockAuxCache mock = new MockAuxCache();
+ mock.cacheType = AuxiliaryCache.DISK_CACHE;
+
+ MockAuxCache mockLateral = new MockAuxCache();
+ mockLateral.cacheType = AuxiliaryCache.LATERAL_CACHE;
+
+ cache.setAuxCaches( new AuxiliaryCache[] { mock, mockLateral } );
+
+ ICacheElement inputElement = new CacheElement( "testSpoolAllowed",
"key", "value" );
+
+ // DO WORK
+ cache.updateAuxiliaries( inputElement, false );
+
+ // VERIFY
+ assertEquals( "Wrong number of calls to the disk cache update.", 1,
mock.updateCount );
+ assertEquals( "Wrong element updated.", inputElement,
mock.lastUpdatedItem );
+
+ assertEquals( "Wrong number of calls to the lateral cache update.", 1,
mockLateral.updateCount );
+ assertEquals( "Wrong element updated with lateral.", inputElement,
mockLateral.lastUpdatedItem );
+ }
+
+ /**
+ * Used to test the disk cache functionality.
+ * <p>
+ * @author Aaron Smuts
+ */
+ public class MockAuxCache
+ implements AuxiliaryCache
+ {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The last item passed to update.
+ */
+ public ICacheElement lastUpdatedItem;
+
+ /**
+ * The number of times update was called.
+ */
+ public int updateCount = 0;
+
+ /**
+ * The type that should be returned from getCacheType.
+ */
+ public int cacheType = AuxiliaryCache.DISK_CACHE;
+
+ /**
+ * Resets counters and catchers.
+ */
+ public void reset()
+ {
+ updateCount = 0;
+ lastUpdatedItem = null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
+ */
+ public void update( ICacheElement ce )
+ throws IOException
+ {
+ lastUpdatedItem = ce;
+ updateCount++;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.jcs.auxiliary.AuxiliaryCache#get(java.io.Serializable)
+ */
+ public ICacheElement get( Serializable key )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.jcs.auxiliary.AuxiliaryCache#remove(java.io.Serializable)
+ */
+ public boolean remove( Serializable key )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#removeAll()
+ */
+ public void removeAll()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#dispose()
+ */
+ public void dispose()
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getSize()
+ */
+ public int getSize()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatus()
+ */
+ public int getStatus()
+ {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getCacheName()
+ */
+ public String getCacheName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
+ */
+ public Set getGroupKeys( String group )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatistics()
+ */
+ public IStats getStatistics()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICache#getStats()
+ */
+ public String getStats()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ /**
+ * Returns the setup cache type. This allows you to use this mock as
multiple cache types.
+ * <p>
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
+ */
+ public int getCacheType()
+ {
+ return cacheType;
+ }
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]