jtaylor 02/02/16 13:59:33
Modified: src/java/org/apache/stratum/jcs JCS.java
src/java/org/apache/stratum/jcs/engine/control
CompositeCacheManager.java
Added: src/test/org/apache/stratum/jcs TestDiskCache.java
src/test-conf TestDiskCache.ccf
Log:
Added a unit test which causes objects to be pushed to the disk cache. This
required the addition of a means to set the cache configuration file. This
should be pushed up to the CacheAccess class (or some other means to change
the config file provided).
Revision Changes Path
1.6 +21 -2 jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/JCS.java
Index: JCS.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/JCS.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- JCS.java 16 Feb 2002 02:37:16 -0000 1.5
+++ JCS.java 16 Feb 2002 21:59:33 -0000 1.6
@@ -75,10 +75,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Aaron Smuts</a>
* @author <a href="mailto:[EMAIL PROTECTED]">James Taylor</a>
* @created February 13, 2002
- * @version $Id: JCS.java,v 1.5 2002/02/16 02:37:16 jtaylor Exp $
+ * @version $Id: JCS.java,v 1.6 2002/02/16 21:59:33 jtaylor Exp $
*/
public class JCS extends GroupCacheAccess
{
+ private static String configFilename = null;
+
private static GroupCacheManager cacheMgr;
/**
@@ -137,9 +139,26 @@
{
if ( cacheMgr == null )
{
- cacheMgr = GroupCacheManagerFactory.getInstance();
+ if ( configFilename == null )
+ {
+ cacheMgr = GroupCacheManagerFactory.getInstance();
+ }
+ else
+ {
+ cacheMgr = GroupCacheManagerFactory
+ .getInstance( configFilename );
+ }
}
}
}
+ }
+
+ /**
+ * Set the filename that the cache manager will be initialized with. Only
+ * matters before the instance is initialized.
+ */
+ public static void setConfigFilename( String configFilename )
+ {
+ JCS.configFilename = configFilename;
}
}
1.7 +1 -1
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/control/CompositeCacheManager.java
Index: CompositeCacheManager.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/engine/control/CompositeCacheManager.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- CompositeCacheManager.java 16 Feb 2002 17:58:12 -0000 1.6
+++ CompositeCacheManager.java 16 Feb 2002 21:59:33 -0000 1.7
@@ -104,7 +104,7 @@
{
is.close();
}
- catch ( IOException ignore )
+ catch ( Exception ignore )
{
// Ignored
}
1.1
jakarta-turbine-stratum/src/test/org/apache/stratum/jcs/TestDiskCache.java
Index: TestDiskCache.java
===================================================================
package org.apache.stratum.jcs;
/*
* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Turbine" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Turbine", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.stratum.jcs.JCS;
import org.apache.stratum.jcs.engine.behavior.ICompositeCacheAttributes;
/**
* Test which excercises the disk cache.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Aaron Smuts</a>
*/
public class TestDiskCache extends TestCase
{
/**
* Number of items to cache, twice the configured maxObjects for the
* memory cache
*/
private static int items = 200;
/**
* Constructor for the TestSimpleLoad object
*/
public TestDiskCache( String testName )
{
super( testName );
}
/**
* Main method passes this test to the text test runner.
*/
public static void main( String args[] )
{
String[] testCaseName = {TestDiskCache.class.getName()};
junit.textui.TestRunner.main( testCaseName );
}
/**
* A unit test suite for JUnit
*
* @return The test suite
*/
public static Test suite()
{
return new TestSuite( TestDiskCache.class );
}
/**
* Adds items to cache, gets them, and removes them. The item count is more
* than
*
* @exception Exception Description of the Exception
*/
public void testDiskCache()
throws Exception
{
JCS.setConfigFilename( "/TestDiskCache.ccf" );
JCS jcs = JCS.getInstance( "testCache" );
// Add items to cache
for ( int i = 0; i <= items; i++ )
{
jcs.put( i + ":key", "data" + i );
}
// Test that all items are in cache
for ( int i = 0; i <= items; i++ )
{
String value = ( String ) jcs.get( i + ":key" );
this.assertEquals( "data" + i, value );
}
// Remove all the items
for ( int i = 0; i <= items; i++ )
{
jcs.destroy( i + ":key" );
}
// Verify removal
for ( int i = 0; i <= items; i++ )
{
assertNull( jcs.get( i + ":key" ) );
}
}
}
1.1 jakarta-turbine-stratum/src/test-conf/TestDiskCache.ccf
Index: TestDiskCache.ccf
===================================================================
# 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=DC
jcs.default.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
# SYSTEM GROUP ID CACHE
jcs.system.groupIdCache=DC
jcs.system.groupIdCache.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
# CACHE REGIONS AVAILABLE
jcs.region.testCache=DC
jcs.region.testCache.cacheattributes=org.apache.stratum.jcs.engine.CompositeCacheAttributes
jcs.region.testCache.cacheattributes.MaxObjects=100
jcs.region.testCache.cacheattributes.MemoryCacheName=org.apache.stratum.jcs.engine.memory.lru.LRUMemoryCache
# AUXILIARY CACHES AVAILABLE
# Primary Disk Cache-- faster than the rest because of memory key storage
jcs.auxiliary.DC=org.apache.stratum.jcs.auxiliary.disk.DiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.stratum.jcs.auxiliary.disk.DiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=bin/test/disk-cache
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>