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:50:45 UTC
svn commit: r375417 - in /jakarta/jcs/trunk/src:
java/org/apache/jcs/utils/props/ java/org/apache/jcs/utils/struct/
java/org/apache/jcs/utils/threadpool/ test/org/apache/jcs/
test/org/apache/jcs/access/ test/org/apache/jcs/auxiliary/remote/
test/org/ap...
Author: asmuts
Date: Mon Feb 6 15:50:43 2006
New Revision: 375417
URL: http://svn.apache.org/viewcvs?rev=375417&view=rev
Log:
adding and cleeaning up tests
Added:
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java
- copied, changed from r375078, jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedList.java
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedListNode.java
- copied, changed from r375078, jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedListNode.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/EventQueueConcurrentUnitTest.java
- copied, changed from r293412, jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java
- copied, changed from r292446, jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestSystemPropertyUsage.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CacheManagerStatsUnitTest.java
- copied, changed from r292446, jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java
Removed:
jakarta/jcs/trunk/src/test/org/apache/jcs/TestSimpleEventHandling.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestSystemPropertyUsage.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/TestElementEventHandler.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/props/PropertyLoader.java
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUElementDescriptor.java
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUMap.java
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/threadpool/ThreadPoolManager.java
jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/props/PropertyLoader.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/props/PropertyLoader.java?rev=375417&r1=375416&r2=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/props/PropertyLoader.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/props/PropertyLoader.java Mon Feb 6 15:50:43 2006
@@ -31,7 +31,7 @@
* @author (C) <a
* href="http://www.javaworld.com/columns/jw-qna-index.shtml">Vlad
* Roubtsov </a>, 2003
- *
+ *
*/
public abstract class PropertyLoader
{
@@ -40,31 +40,33 @@
private static final String SUFFIX = ".ccf";
+ private static final String SUFFIX_PROPERTIES = ".properties";
+
/**
* Looks up a resource named 'name' in the classpath. The resource must map
* to a file with .ccf extention. The name is assumed to be absolute and can
* use either "/" or "." for package segment separation with an optional
* leading "/" and optional ".ccf" suffix.
* <p>
- * The suffix ".ccf" will be appended if it is not set.
+ * The suffix ".ccf" will be appended if it is not set. This can also handle .properties files
*
* Thus, the following names refer to the same resource:
*
* <pre>
- *
*
*
*
- * some.pkg.Resource
- * some.pkg.Resource.ccf
- * some/pkg/Resource
- * some/pkg/Resource.ccf
- * /some/pkg/Resource
- * /some/pkg/Resource.ccf
+ *
+ * some.pkg.Resource
+ * some.pkg.Resource.ccf
+ * some/pkg/Resource
+ * some/pkg/Resource.ccf
+ * /some/pkg/Resource
+ * /some/pkg/Resource.ccf
+ *
*
*
*
- *
* </pre>
*
* @param name
@@ -81,6 +83,8 @@
*/
public static Properties loadProperties( String name, ClassLoader loader )
{
+ boolean isCCFSuffix = true;
+
if ( name == null )
throw new IllegalArgumentException( "null input: name" );
@@ -89,27 +93,37 @@
name = name.substring( 1 );
}
- if (name.endsWith (SUFFIX))
- {
- name = name.substring (0, name.length () - SUFFIX.length ());
+ if ( name.endsWith( SUFFIX ) )
+ {
+ name = name.substring( 0, name.length() - SUFFIX.length() );
}
-
+
+ if ( name.endsWith( SUFFIX_PROPERTIES ) )
+ {
+ name = name.substring( 0, name.length() - SUFFIX_PROPERTIES.length() );
+ isCCFSuffix = false;
+ }
+
Properties result = null;
InputStream in = null;
try
{
if ( loader == null )
- {
+ {
loader = ClassLoader.getSystemClassLoader();
}
name = name.replace( '.', '/' );
- if ( !name.endsWith( SUFFIX ) )
+ if ( !name.endsWith( SUFFIX ) && isCCFSuffix )
{
name = name.concat( SUFFIX );
}
+ else if ( !name.endsWith( SUFFIX_PROPERTIES ) && !isCCFSuffix )
+ {
+ name = name.concat( SUFFIX_PROPERTIES );
+ }
// returns null on lookup failures:
in = loader.getResourceAsStream( name );
@@ -149,6 +163,7 @@
* that uses the current thread's context classloader. A better strategy
* would be to use techniques shown in
* http://www.javaworld.com/javaworld/javaqa/2003-06/01-qa-0606-load.html
+ *
* @param name
* @return Properties
*/
@@ -159,7 +174,7 @@
/**
* Can't use this one.
- *
+ *
*/
private PropertyLoader()
{
Copied: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java (from r375078, jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedList.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java?p2=jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java&p1=jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedList.java&r1=375078&r2=375417&rev=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedList.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedList.java Mon Feb 6 15:50:43 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.engine.memory.util;
+package org.apache.jcs.utils.struct;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Copied: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedListNode.java (from r375078, jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedListNode.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedListNode.java?p2=jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedListNode.java&p1=jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedListNode.java&r1=375078&r2=375417&rev=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/util/DoubleLinkedListNode.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/DoubleLinkedListNode.java Mon Feb 6 15:50:43 2006
@@ -1,4 +1,4 @@
-package org.apache.jcs.engine.memory.util;
+package org.apache.jcs.utils.struct;
/*
* Copyright 2001-2004 The Apache Software Foundation.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUElementDescriptor.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUElementDescriptor.java?rev=375417&r1=375416&r2=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUElementDescriptor.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/struct/LRUElementDescriptor.java Mon Feb 6 15:50:43 2006
@@ -1,6 +1,5 @@
package org.apache.jcs.utils.struct;
-import org.apache.jcs.engine.memory.util.DoubleLinkedListNode;
/**
* @author aaronsm
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=375417&r1=375416&r2=375417&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 Mon Feb 6 15:50:43 2006
@@ -13,7 +13,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.engine.control.group.GroupAttrName;
-import org.apache.jcs.engine.memory.util.DoubleLinkedList;
import org.apache.jcs.engine.stats.StatElement;
import org.apache.jcs.engine.stats.Stats;
import org.apache.jcs.engine.stats.behavior.IStatElement;
@@ -394,7 +393,7 @@
* consistency between List and map.
*
*/
- private void verifyCache()
+ protected void verifyCache()
{
if ( !log.isDebugEnabled() )
{
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/threadpool/ThreadPoolManager.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/threadpool/ThreadPoolManager.java?rev=375417&r1=375416&r2=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/threadpool/ThreadPoolManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/threadpool/ThreadPoolManager.java Mon Feb 6 15:50:43 2006
@@ -16,8 +16,6 @@
* limitations under the License.
*/
-import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -26,6 +24,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.utils.props.PropertyLoader;
import org.apache.jcs.utils.threadpool.behavior.IPoolConfiguration;
import EDU.oswego.cs.dl.util.concurrent.BoundedBuffer;
@@ -292,14 +291,12 @@
return props;
}
- //-------------------------- Private Methods ----------
-
/**
* Intialize the ThreadPoolManager and create all the pools defined in the
* configuration.
*
*/
- private void configure()
+ protected void configure()
{
if ( log.isDebugEnabled() )
{
@@ -308,36 +305,21 @@
if ( props == null )
{
-
- InputStream is = getClass().getResourceAsStream( "/" + propsFileName );
-
try
{
- props.load( is );
+ props = PropertyLoader.loadProperties( propsFileName );
- if ( log.isDebugEnabled() )
- {
- log.debug( "File contained " + props.size() + " properties" );
- }
- }
- catch ( IOException ex )
+ if ( log.isDebugEnabled() )
{
- log.error( "Failed to load properties", ex );
- throw new IllegalStateException( ex.getMessage() );
+ log.debug( "File contained " + props.size() + " properties" );
+ }
}
- finally
+ catch( Exception e )
{
- try
- {
- is.close();
- }
- catch ( Exception ignore )
- {
- // Ignored
- }
+ log.error( "Problem loading properties. propsFileName [" + propsFileName + "]", e );
}
-
}
+
if ( props == null )
{
log.warn( "No configuration settings found. Using hardcoded default values for all pools." );
@@ -360,7 +342,7 @@
* @return PoolConfiguration
*
*/
- private PoolConfiguration loadConfig( String root )
+ protected PoolConfiguration loadConfig( String root )
{
PoolConfiguration config = (PoolConfiguration) defaultConfig.clone();
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=375417&r1=375416&r2=375417&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 Mon Feb 6 15:50:43 2006
@@ -29,7 +29,7 @@
import org.apache.jcs.engine.ElementAttributes;
import org.apache.jcs.engine.behavior.IElementAttributes;
import org.apache.jcs.engine.control.CompositeCacheManager;
-import org.apache.jcs.engine.control.event.TestElementEventHandler;
+import org.apache.jcs.engine.control.event.ElementEventHandlerMockImpl;
/**
* Allows the user to run common cache commands from the command line for a test
@@ -447,7 +447,7 @@
for ( int n = 0; n < num; n++ )
{
IElementAttributes attrp = cache_control.getElementAttributes();
- TestElementEventHandler hand = new TestElementEventHandler();
+ ElementEventHandlerMockImpl hand = new ElementEventHandlerMockImpl();
attrp.addElementEventHandler( hand );
cache_control.put( "key" + n, "data" + n + " put from ta = junk", attrp );
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java?rev=375417&r1=375416&r2=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java Mon Feb 6 15:50:43 2006
@@ -23,7 +23,10 @@
private final static Log log = LogFactory.getLog( TestRemoteCache.class );
-
+ /**
+ *
+ *
+ */
public TestRemoteCache()
{
super();
Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/EventQueueConcurrentUnitTest.java (from r293412, jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/EventQueueConcurrentUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/engine/EventQueueConcurrentUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java&r1=293412&r2=375417&rev=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestEventQueueConcurrent.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/EventQueueConcurrentUnitTest.java Mon Feb 6 15:50:43 2006
@@ -33,7 +33,7 @@
*
* @author Aaron Smuts
*/
-public class TestEventQueueConcurrent
+public class EventQueueConcurrentUnitTest
extends TestCase
{
@@ -53,7 +53,7 @@
*
* @param testName
*/
- public TestEventQueueConcurrent( String testName )
+ public EventQueueConcurrentUnitTest( String testName )
{
super( testName );
}
@@ -65,7 +65,7 @@
*/
public static void main( String args[] )
{
- String[] testCaseName = { TestEventQueueConcurrent.class.getName() };
+ String[] testCaseName = { EventQueueConcurrentUnitTest.class.getName() };
junit.textui.TestRunner.main( testCaseName );
}
@@ -79,7 +79,7 @@
ActiveTestSuite suite = new ActiveTestSuite();
- suite.addTest( new TestEventQueueConcurrent( "testRunPutTest1" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testRunPutTest1" )
{
public void runTest()
throws Exception
@@ -88,7 +88,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testRunPutTest2" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testRunPutTest2" )
{
public void runTest()
throws Exception
@@ -97,7 +97,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testRunRemoveTest1" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testRunRemoveTest1" )
{
public void runTest()
throws Exception
@@ -106,7 +106,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testStopProcessing1" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testStopProcessing1" )
{
public void runTest()
throws Exception
@@ -115,7 +115,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testRunPutTest4" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testRunPutTest4" )
{
public void runTest()
throws Exception
@@ -124,7 +124,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testRunRemoveTest2" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testRunRemoveTest2" )
{
public void runTest()
throws Exception
@@ -133,7 +133,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testStopProcessing2" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testStopProcessing2" )
{
public void runTest()
throws Exception
@@ -142,7 +142,7 @@
}
} );
- suite.addTest( new TestEventQueueConcurrent( "testRunPutDelayTest" )
+ suite.addTest( new EventQueueConcurrentUnitTest( "testRunPutDelayTest" )
{
public void runTest()
throws Exception
Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java (from r292446, jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestSystemPropertyUsage.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestSystemPropertyUsage.java&r1=292446&r2=375417&rev=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/TestSystemPropertyUsage.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java Mon Feb 6 15:50:43 2006
@@ -11,7 +11,7 @@
/**
* Verify that system properties can override.
*/
-public class TestSystemPropertyUsage
+public class SystemPropertyUsageUnitTest
extends TestCase
{
Copied: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CacheManagerStatsUnitTest.java (from r292446, jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java)
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CacheManagerStatsUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CacheManagerStatsUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java&r1=292446&r2=375417&rev=375417&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/TestCacheManagerStats.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CacheManagerStatsUnitTest.java Mon Feb 6 15:50:43 2006
@@ -25,17 +25,26 @@
* @author Aaron Smuts
*
*/
-public class TestCacheManagerStats
+public class CacheManagerStatsUnitTest
extends TestCase
{
+ /**
+ * Just get the stats after putting a couple entries in the cache.
+ *
+ * @throws Exception
+ */
public void testSimpleGetStats() throws Exception
{
JCS cache = JCS.getInstance( "testCache1" );
// 1 miss, 1 hit, 1 put
cache.get( "testKey" );
- cache.put( "testkey", "testdata" );
+ cache.put( "testKey", "testdata" );
+ // should have 4 hits
+ cache.get( "testKey" );
+ cache.get( "testKey" );
+ cache.get( "testKey" );
cache.get( "testKey" );
CompositeCacheManager mgr = CompositeCacheManager.getInstance();
@@ -44,12 +53,14 @@
System.out.println( statsString );
assertTrue( "Should have the cacheName in here.", statsString.indexOf("testCache1") != -1 );
+ assertTrue( "Should have the HitCountRam in here.", statsString.indexOf("HitCountRam") != -1 );
+ assertTrue( "Should have the 4 in here.", statsString.indexOf("4") != -1 );
ICacheStats[] stats = mgr.getStatistics();
int statsLen = stats.length;
+ System.out.println( "statsLen = " + statsLen );
for ( int i = 0; i < statsLen; i++ )
{
- //buf.append( stats[i] );
// TODO finish
}
}
Added: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java?rev=375417&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java Mon Feb 6 15:50:43 2006
@@ -0,0 +1,50 @@
+package org.apache.jcs.engine.control.event;
+
+/*
+ * 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.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.apache.jcs.engine.control.event.behavior.IElementEvent;
+import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
+
+/**
+ *
+ * @author aaronsm
+ *
+ */
+public class ElementEventHandlerMockImpl
+ implements IElementEventHandler
+{
+
+ /**
+ * Times called.
+ */
+ public int callCount = 0;
+
+ private final static Log log = LogFactory.getLog( ElementEventHandlerMockImpl.class );
+
+ public void handleElementEvent( IElementEvent event )
+ {
+ callCount++;
+
+ log.debug( "HANDLER -- HANDLER -- HANDLER -- ---EVENT CODE = " + event.getElementEvent() );
+
+ log.debug( "/n/n EVENT CODE = " + event.getElementEvent() + " ***************************" );
+ //return "Done";
+ }
+}
Added: 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=375417&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java Mon Feb 6 15:50:43 2006
@@ -0,0 +1,268 @@
+package org.apache.jcs.engine.control.event;
+
+/*
+ * 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 junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.control.event.behavior.IElementEvent;
+import org.apache.jcs.engine.control.event.behavior.IElementEventConstants;
+import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
+
+/**
+ * This test suite verifies that the basic ElementEvent are called as they
+ * should be.
+ *
+ *
+ * @version $Id: TestSimpleEventHandling.java,v 1.1 2005/02/01 00:01:59 asmuts
+ * Exp $
+ */
+public class SimpleEventHandlingUnitTest
+ extends TestCase
+{
+
+ private static int items = 20000;
+
+ /**
+ * Constructor for test case.
+ *
+ * @param testName
+ * Description of the Parameter
+ */
+ public SimpleEventHandlingUnitTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Run at command line.
+ *
+ * @param args
+ * Description of the Parameter
+ */
+ public static void main( String args[] )
+ {
+ String[] testCaseName = { SimpleEventHandlingUnitTest.class.getName() };
+ junit.textui.TestRunner.main( testCaseName );
+ }
+
+ /**
+ * A unit test suite for JUnit
+ *
+ * @return The test suite
+ */
+ public static Test suite()
+ {
+ return new TestSuite( SimpleEventHandlingUnitTest.class );
+ }
+
+ /**
+ * Test setup with expected configuration parameters.
+ *
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestSimpleEventHandling.ccf" );
+ }
+
+ /**
+ * Verify that the spooled event is called as expected.
+ *
+ *
+ * @exception Exception
+ * Description of the Exception
+ */
+ public void testSpoolEvent()
+ throws Exception
+ {
+ MyEventHandler meh = new MyEventHandler();
+
+ JCS jcs = JCS.getInstance( "WithDisk" );
+ // this should add the event handler to all items as they are created.
+ jcs.getElementAttributes().addElementEventHandler( meh );
+
+ // put them in
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // wait a bit for it to finish
+ Thread.sleep( items / 20 );
+
+ // test to see if the count is right
+ assertTrue( "The number of ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE events [" + meh.getSpoolCount()
+ + "] does not equal the number expected [" + items + "]", meh.getSpoolCount() >= items );
+
+ }
+
+ /**
+ * Test overflow with no disk configured for the region.
+ *
+ * @throws Exception
+ */
+ public void testSpoolNoDiskEvent()
+ throws Exception
+ {
+ MyEventHandler meh = new MyEventHandler();
+
+ JCS jcs = JCS.getInstance( "NoDisk" );
+ // this should add the event handler to all items as they are created.
+ jcs.getElementAttributes().addElementEventHandler( meh );
+
+ // put them in
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // wait a bit for it to finish
+ Thread.sleep( items / 20 );
+
+ // test to see if the count is right
+ assertTrue( "The number of ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE events [" + meh.getSpoolNoDiskCount()
+ + "] does not equal the number expected.", meh.getSpoolNoDiskCount() >= items );
+
+ }
+
+ /**
+ * Test the ELEMENT_EVENT_SPOOLED_NOT_ALLOWED event.
+ *
+ * @throws Exception
+ */
+ public void testSpoolNotAllowedEvent()
+ throws Exception
+ {
+ MyEventHandler meh = new MyEventHandler();
+
+ JCS jcs = JCS.getInstance( "DiskButNotAllowed" );
+ // this should add the event handler to all items as they are created.
+ jcs.getElementAttributes().addElementEventHandler( meh );
+
+ // put them in
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", "data" + i );
+ }
+
+ // wait a bit for it to finish
+ Thread.sleep( items / 20 );
+
+ // test to see if the count is right
+ assertTrue( "The number of ELEMENT_EVENT_SPOOLED_NOT_ALLOWED events [" + meh.getSpoolNotAllowedCount()
+ + "] does not equal the number expected.", meh.getSpoolNotAllowedCount() >= items );
+
+ }
+
+ /**
+ * Simple event counter used to verify test results.
+ *
+ * @author aaronsm
+ *
+ */
+ public class MyEventHandler
+ implements IElementEventHandler
+ {
+
+ private int spoolCount = 0;
+
+ private int spoolNotAllowedCount = 0;
+
+ private int spoolNoDiskCount = 0;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.jcs.engine.control.event.behavior.IElementEventHandler#handleElementEvent(org.apache.jcs.engine.control.event.behavior.IElementEvent)
+ */
+ public synchronized void handleElementEvent( IElementEvent event )
+ {
+ //System.out.println( "Handling Event of Type " +
+ // event.getElementEvent() );
+
+ if ( event.getElementEvent() == IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE )
+ {
+ //System.out.println( "Handling Event of Type
+ // ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE, " + getSpoolCount() );
+ setSpoolCount( getSpoolCount() + 1 );
+ }
+ else if ( event.getElementEvent() == IElementEventConstants.ELEMENT_EVENT_SPOOLED_NOT_ALLOWED )
+ {
+ setSpoolNotAllowedCount( getSpoolNotAllowedCount() + 1 );
+ }
+ else if ( event.getElementEvent() == IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE )
+ {
+ setSpoolNoDiskCount( getSpoolNoDiskCount() + 1 );
+ }
+ }
+
+ /**
+ * @param spoolCount
+ * The spoolCount to set.
+ */
+ protected void setSpoolCount( int spoolCount )
+ {
+ this.spoolCount = spoolCount;
+ }
+
+ /**
+ * @return Returns the spoolCount.
+ */
+ protected int getSpoolCount()
+ {
+ return spoolCount;
+ }
+
+ /**
+ * @param spoolNotAllowedCount
+ * The spoolNotAllowedCount to set.
+ */
+ protected void setSpoolNotAllowedCount( int spoolNotAllowedCount )
+ {
+ this.spoolNotAllowedCount = spoolNotAllowedCount;
+ }
+
+ /**
+ * @return Returns the spoolNotAllowedCount.
+ */
+ protected int getSpoolNotAllowedCount()
+ {
+ return spoolNotAllowedCount;
+ }
+
+ /**
+ * @param spoolNoDiskCount
+ * The spoolNoDiskCount to set.
+ */
+ protected void setSpoolNoDiskCount( int spoolNoDiskCount )
+ {
+ this.spoolNoDiskCount = spoolNoDiskCount;
+ }
+
+ /**
+ * @return Returns the spoolNoDiskCount.
+ */
+ protected int getSpoolNoDiskCount()
+ {
+ return spoolNoDiskCount;
+ }
+
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org