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/07 00:53:22 UTC
svn commit: r375419 - in /jakarta/jcs/trunk:
src/experimental/org/apache/jcs/engine/memory/arc/
src/java/org/apache/jcs/auxiliary/disk/hsql/
src/java/org/apache/jcs/engine/memory/behavior/
src/java/org/apache/jcs/engine/memory/lru/ src/java/org/apache/...
Author: asmuts
Date: Mon Feb 6 15:53:20 2006
New Revision: 375419
URL: http://svn.apache.org/viewcvs?rev=375419&view=rev
Log:
adding and cleeaning up tests
Added:
jakarta/jcs/trunk/src/test-conf/thread_pool.properties
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolManagerUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolUnitTest.java
Modified:
jakarta/jcs/trunk/src/experimental/org/apache/jcs/engine/memory/arc/ARCMemoryCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java
jakarta/jcs/trunk/src/test-conf/cache.ccf
jakarta/jcs/trunk/xdocs/faq.fml
Modified: jakarta/jcs/trunk/src/experimental/org/apache/jcs/engine/memory/arc/ARCMemoryCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/experimental/org/apache/jcs/engine/memory/arc/ARCMemoryCache.java?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/experimental/org/apache/jcs/engine/memory/arc/ARCMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/experimental/org/apache/jcs/engine/memory/arc/ARCMemoryCache.java Mon Feb 6 15:53:20 2006
@@ -29,7 +29,7 @@
import org.apache.jcs.engine.control.CompositeCache;
import org.apache.jcs.engine.behavior.ICacheElement;
import org.apache.jcs.engine.memory.AbstractMemoryCache;
-import org.apache.jcs.engine.memory.util.DoubleLinkedList;
+import org.apache.jcs.utils.struct.DoubleLinkedList;
import org.apache.jcs.engine.memory.util.MemoryElementDescriptor;
import org.apache.jcs.engine.stats.StatElement;
import org.apache.jcs.engine.stats.Stats;
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/hsql/HSQLCache.java Mon Feb 6 15:53:20 2006
@@ -38,7 +38,7 @@
import org.apache.jcs.auxiliary.disk.AbstractDiskCache;
import org.apache.jcs.engine.CacheConstants;
import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.utils.data.PropertyGroups;
+import org.apache.jcs.utils.props.PropertyLoader;
/**
* HSQLDB Based Local Persistence.
@@ -80,13 +80,13 @@
numInstances++;
- //String rafroot = cattr.getDiskPath();
+ // String rafroot = cattr.getDiskPath();
if ( rafroot == null )
{
try
{
- PropertyGroups pg = new PropertyGroups( "/cache.properties" );
- rafroot = pg.getProperty( "diskPath" );
+ Properties props = PropertyLoader.loadProperties( "/cache.ccf" );
+ rafroot = props.getProperty( "diskPath" );
}
catch ( Exception e )
{
@@ -191,7 +191,7 @@
catch ( SQLException e )
{
log.error( "Problem creating statement.", e );
- //System.out.println( "Exception: " + e );
+ // System.out.println( "Exception: " + e );
alive = false;
return;
}
@@ -325,7 +325,7 @@
psInsert.setBytes( 2, element );
psInsert.execute();
psInsert.close();
- //sStatement.executeUpdate(sql);
+ // sStatement.executeUpdate(sql);
}
catch ( SQLException e )
{
@@ -418,9 +418,9 @@
log.error( e );
}
}
- //else {
- //return null;
- //}
+ // else {
+ // return null;
+ // }
}
catch ( SQLException sqle )
{
@@ -492,12 +492,12 @@
{
try
{
- //reset();
+ // reset();
}
catch ( RuntimeException e )
{
log.error( e );
- //reset();
+ // reset();
}
}
@@ -551,7 +551,7 @@
/**
* @param groupName
* @return
- *
+ *
*/
public Set getGroupKeys( String groupName )
{
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/behavior/IMemoryCache.java Mon Feb 6 15:53:20 2006
@@ -33,9 +33,8 @@
extends ICacheType
{
- // for initialization
/**
- * Description of the Method
+ * Initialize the memory cache.
*
* @param cacheName
* Description of the Parameter
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/lru/LRUMemoryCache.java Mon Feb 6 15:53:20 2006
@@ -32,12 +32,12 @@
import org.apache.jcs.engine.control.group.GroupAttrName;
import org.apache.jcs.engine.control.group.GroupId;
import org.apache.jcs.engine.memory.AbstractMemoryCache;
-import org.apache.jcs.engine.memory.util.DoubleLinkedList;
import org.apache.jcs.engine.memory.util.MemoryElementDescriptor;
import org.apache.jcs.engine.stats.StatElement;
import org.apache.jcs.engine.stats.Stats;
import org.apache.jcs.engine.stats.behavior.IStatElement;
import org.apache.jcs.engine.stats.behavior.IStats;
+import org.apache.jcs.utils.struct.DoubleLinkedList;
/**
* A fast reference management system. The least recently used items move to the
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/MemoryElementDescriptor.java Mon Feb 6 15:53:20 2006
@@ -17,6 +17,7 @@
*/
import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.utils.struct.DoubleLinkedListNode;
/**
* This wrapper is needed for double linked lists.
Modified: jakarta/jcs/trunk/src/test-conf/cache.ccf
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test-conf/cache.ccf?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/cache.ccf (original)
+++ jakarta/jcs/trunk/src/test-conf/cache.ccf Mon Feb 6 15:53:20 2006
@@ -16,7 +16,7 @@
################## THREAD POOL CONFIGURATION ###################
# Default thread pool config
thread_pool.default.boundarySize=2000
-thread_pool.default.maximumPoolSize=150
+thread_pool.default.maximumPoolSize=151
thread_pool.default.minimumPoolSize=4
thread_pool.default.keepAliveTime=350000
#RUN ABORT WAIT BLOCK DISCARDOLDEST
Added: jakarta/jcs/trunk/src/test-conf/thread_pool.properties
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test-conf/thread_pool.properties?rev=375419&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/thread_pool.properties (added)
+++ jakarta/jcs/trunk/src/test-conf/thread_pool.properties Mon Feb 6 15:53:20 2006
@@ -0,0 +1,46 @@
+# This is used for unit testing the thread pool manager.
+# Normally these settings are loaded from the cache.ccf file.
+
+##############################################################
+################## THREAD POOL CONFIGURATION ###################
+# Default thread pool config
+thread_pool.default.boundarySize=2000
+thread_pool.default.maximumPoolSize=151
+thread_pool.default.minimumPoolSize=6
+thread_pool.default.keepAliveTime=350000
+#RUN ABORT WAIT BLOCK DISCARDOLDEST
+thread_pool.default.whenBlockedPolicy=RUN
+thread_pool.default.startUpSize=6
+
+# Remote cache client thread pool config
+thread_pool.test1.boundarySize=75
+thread_pool.test1.maximumPoolSize=150
+thread_pool.test1.minimumPoolSize=4
+thread_pool.test1.keepAliveTime=350001
+thread_pool.test1.whenBlockedPolicy=RUN
+thread_pool.test1.startUpSize=4
+
+# max size test thread pool config
+thread_pool.maxtest.boundarySize=72
+thread_pool.maxtest.maximumPoolSize=142
+thread_pool.maxtest.minimumPoolSize=5
+thread_pool.maxtest.keepAliveTime=350002
+thread_pool.maxtest.whenBlockedPolicy=RUN
+thread_pool.maxtest.startUpSize=5
+
+# wait test thread pool config
+thread_pool.waittest.boundarySize=1
+thread_pool.waittest.maximumPoolSize=11
+thread_pool.waittest.minimumPoolSize=1
+thread_pool.waittest.keepAliveTime=1
+thread_pool.waittest.whenBlockedPolicy=WAIT
+thread_pool.waittest.startUpSize=1
+
+# no boundary test thread pool config
+thread_pool.nobound.useBoundary=false
+thread_pool.nobound.boundarySize=1000
+thread_pool.nobound.maximumPoolSize=11
+thread_pool.nobound.minimumPoolSize=1
+thread_pool.nobound.keepAliveTime=1
+thread_pool.nobound.whenBlockedPolicy=WAIT
+thread_pool.nobound.startUpSize=1
\ No newline at end of file
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolManagerUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolManagerUnitTest.java?rev=375419&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolManagerUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolManagerUnitTest.java Mon Feb 6 15:53:20 2006
@@ -0,0 +1,164 @@
+package org.apache.jcs.utils.threadpool;
+
+import java.util.ArrayList;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.utils.props.PropertyLoader;
+
+import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
+
+/**
+ * Verify that the manager can create pools as intended by the default and
+ * specified file names.
+ *
+ * @author asmuts
+ */
+public class ThreadPoolManagerUnitTest
+ extends TestCase
+{
+
+ /**
+ * Make sure it can load a default cache.ccf file
+ */
+ public void testDefaultConfig()
+ {
+ ThreadPoolManager.setPropsFileName( "thread_pool.properties" );
+ ThreadPoolManager mgr = ThreadPoolManager.getInstance();
+ assertNotNull( mgr );
+
+ ThreadPool pool = mgr.getPool( "test1" );
+ assertNotNull( pool );
+
+ int poolSize = pool.getPool().getPoolSize();
+ int expectedPoolSize = Integer.parseInt( PropertyLoader.loadProperties( "thread_pool.properties" )
+ .getProperty( "thread_pool.test1.startUpSize" ) );
+ assertEquals( poolSize, expectedPoolSize );
+
+ // int qs = ((BoundedBuffer)pool.getQueue()).size();
+
+ int max = pool.getPool().getMaximumPoolSize();
+ System.out.println( max );
+
+ int expected = Integer.parseInt( PropertyLoader.loadProperties( "thread_pool.properties" )
+ .getProperty( "thread_pool.test1.maximumPoolSize" ) );
+ // "Max should be " + expected",
+ assertEquals( max, expected );
+ }
+
+ /**
+ * Try to get an undefined pool from an existing default file.
+ */
+ public void testDefaultConfigUndefinedPool()
+ {
+ ThreadPoolManager.setPropsFileName( "thread_pool.properties" );
+ ThreadPoolManager mgr = ThreadPoolManager.getInstance();
+ assertNotNull( mgr );
+
+ ThreadPool pool = mgr.getPool( "doesnotexist" );
+ assertNotNull( pool );
+
+ int max = pool.getPool().getMaximumPoolSize();
+ System.out.println( max );
+
+ int expected = Integer.parseInt( PropertyLoader.loadProperties( "thread_pool.properties" )
+ .getProperty( "thread_pool.default.maximumPoolSize" ) );
+ // "Max should be " + expected",
+ assertEquals( max, expected );
+ }
+
+ /**
+ * Makes ure we can get a non existent pool from the non exitent config
+ * file.
+ */
+ public void testNonExistentConfigFile()
+ {
+ ThreadPoolManager.setPropsFileName( "somefilethatdoesntexist" );
+ ThreadPoolManager mgr = ThreadPoolManager.getInstance();
+ assertNotNull( mgr );
+
+ ThreadPool pool = mgr.getPool( "doesntexist" );
+ assertNotNull( "Should have gotten back a pool configured like the default", pool );
+
+ int max = pool.getPool().getMaximumPoolSize();
+ System.out.println( max );
+
+ // it will load from the default file
+ int expected = Integer.parseInt( PropertyLoader.loadProperties( "cache.ccf" )
+ .getProperty( "thread_pool.default.maximumPoolSize" ) );
+
+ // "Max should be " + expected",
+ assertEquals( max, expected );
+ }
+
+ /**
+ * Get a couple pools by name and then see if they are in the list.
+ *
+ */
+ public void testGetPoolNames()
+ {
+ ThreadPoolManager mgr = ThreadPoolManager.getInstance();
+ assertNotNull( mgr );
+
+ String poolName1 = "testGetPoolNames1";
+ mgr.getPool( poolName1 );
+
+ String poolName2 = "testGetPoolNames2";
+ mgr.getPool( poolName2 );
+
+ ArrayList names = mgr.getPoolNames();
+ assertTrue( "Should have name in list.", names.contains( poolName1 ) );
+ assertTrue( "Should have name in list.", names.contains( poolName2 ) );
+ }
+
+ /**
+ * Verify that the wait policy gets set correctly.
+ *
+ */
+ public void testWaitPolicyConfig()
+ {
+ ThreadPoolManager.setPropsFileName( "thread_pool.properties" );
+ ThreadPoolManager mgr = ThreadPoolManager.getInstance();
+ // force config from new props file
+ mgr.configure();
+ assertNotNull( mgr );
+
+ ThreadPool pool = mgr.getPool( "waittest" );
+ assertNotNull( "Should have gotten back a pool.", pool );
+
+ int max = pool.getPool().getMaximumPoolSize();
+ System.out.println( "testWaitPolicyConfig " + max );
+
+ // it will load from the default file
+ int expected = Integer.parseInt( PropertyLoader.loadProperties( "thread_pool.properties" )
+ .getProperty( "thread_pool.waittest.maximumPoolSize" ) );
+
+ // "Max should be " + expected",
+ assertEquals( "Max is wrong", max, expected );
+
+ PoolConfiguration config = mgr.loadConfig( "thread_pool.waittest" );
+
+ assertEquals( "Policy is wrong.", PoolConfiguration.POLICY_WAIT, config.getWhenBlockedPolicy() );
+
+ }
+
+ /**
+ * Verify that if we specify not to use a buffer boundary that we get a
+ * linked queue.
+ *
+ */
+ public void testNoBoundary()
+ {
+ ThreadPoolManager.setPropsFileName( "thread_pool.properties" );
+ ThreadPoolManager mgr = ThreadPoolManager.getInstance();
+ // force config from new props file
+ mgr.configure();
+ assertNotNull( mgr );
+
+ ThreadPool pool = mgr.getPool( "nobound" );
+ assertNotNull( "Should have gotten back a pool.", pool );
+
+ assertTrue( "Should have a linked queue and not a bounded buffer.", pool.getQueue() instanceof LinkedQueue );
+
+ }
+}
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolUnitTest.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolUnitTest.java?rev=375419&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/threadpool/ThreadPoolUnitTest.java Mon Feb 6 15:53:20 2006
@@ -0,0 +1,82 @@
+package org.apache.jcs.utils.threadpool;
+
+import junit.framework.TestCase;
+
+/**
+ * This test is experiemental. I'm trying to find out if the max size setting
+ * will result in the removal of threads.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class ThreadPoolUnitTest
+ extends TestCase
+{
+
+ /**
+ * Make sure that the max size setting takes effect before the idle
+ * time is reached.
+ *
+ * We just want to ensure that we can adjust the max size of an active pool.
+ *
+ * http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/PooledExecutor.html#setMaximumPoolSize(int)
+ *
+ * @throws Exception
+ */
+ public void testMaxReduction()
+ throws Exception
+ {
+ //ThreadPoolManager.setPropsFileName( "thread_pool_test.properties" );
+ ThreadPool pool = ThreadPoolManager.getInstance().getPool( "maxtest" );
+
+ System.out.println( "pool = " + pool );
+
+ pool.getPool().setMaximumPoolSize( 5 );
+
+ System.out.println( "current size before execute = " + pool.getPool().getPoolSize() );
+
+
+ // add 6
+ for ( int i = 1; i < 30; i++ )
+ {
+ final ThreadPool myPool = pool;
+ final int cnt = i;
+ pool.execute( new Runnable()
+ {
+
+ public void run()
+ {
+ try
+ {
+ //System.out.println( cnt );
+ System.out.println( "count = " + cnt + " before sleep current size = " + myPool.getPool().getPoolSize() );
+ Thread.sleep( 200 / cnt );
+ System.out.println( "count = " + cnt + " after sleep current size = " + myPool.getPool().getPoolSize() );
+ }
+ catch ( InterruptedException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ } );
+
+ }
+
+ System.out.println( "current size = " + pool.getPool().getPoolSize() );
+
+ pool.getPool().setMaximumPoolSize( 4 );
+
+ //Thread.sleep( 200 );
+
+ System.out.println( "current size after set size to 4= " + pool.getPool().getPoolSize() );
+
+ Thread.sleep( 200 );
+
+ System.out.println( "current size again after sleep = " + pool.getPool().getPoolSize() );
+
+ assertEquals( "Pool size should have been reduced.", 4, pool.getPool().getPoolSize() );
+ }
+
+}
Modified: jakarta/jcs/trunk/xdocs/faq.fml
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/xdocs/faq.fml?rev=375419&r1=375418&r2=375419&view=diff
==============================================================================
--- jakarta/jcs/trunk/xdocs/faq.fml (original)
+++ jakarta/jcs/trunk/xdocs/faq.fml Mon Feb 6 15:53:20 2006
@@ -47,5 +47,27 @@
The documentation describes how to configure the cache.</p>
</answer>
</faq>
+
+ <faq id="manual-configuration">
+ <question>
+ How can I configure JCS with my own properties?
+ </question>
+ </faq>
+ <answer>
+ <p>
+ You don't have to put the cache.ccf file in the classpath; instead you can do the following:
+ </p>
+ <code>
+CompositeCacheManager ccm =
+CompositeCacheManager.getUnconfiguredInstance();
+
+Properties props = new Properties();
+
+props.load(/* load properties from some location defined by your app
+*/);
+
+ccm.configure(props);
+ </code>
+ </answer>
</part>
</faqs>
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org