Author: asmuts
Date: Fri Feb 10 12:10:24 2006
New Revision: 376828
URL: http://svn.apache.org/viewcvs?rev=376828&view=rev
Log:
adding tests for worker, cleaning other tests, changing test naming
convention gradually
Added:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
- copied, changed from r292446,
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPIssueRemoveOnPut.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
- copied, changed from r292446,
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/TestUDPDiscovery.java
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/access/JCSWorkerUnitTest.java
Removed:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPIssueRemoveOnPut.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/TestUDPDiscovery.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java
jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java
jakarta/jcs/trunk/src/test/org/apache/jcs/TestCacheElementRetrieval.java
jakarta/jcs/trunk/src/test/org/apache/jcs/TestZeroSizeCache.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPConcurrentRandom.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPFilterRemoveHashCode.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/shrinking/ShrinkerThreadUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/servlet/ListTestCacheServlet.java
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCache.java?rev=376828&r1=376827&r2=376828&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
Fri Feb 10 12:10:24 2006
@@ -1281,7 +1281,7 @@
}
/**
- * Adds an ElementEvent to be handled tot he queue.
+ * Adds an ElementEvent to be handled to the queue.
*
* @param hand
* The IElementEventHandler
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java
(original)
+++
jakarta/jcs/trunk/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java
Fri Feb 10 12:10:24 2006
@@ -327,7 +327,14 @@
{
IElementEventHandler hand = (IElementEventHandler)
handlerIter.next();
- cache.getCompositeCache().addElementEvent( hand, event );
+ // extra safety
+ // TODO we shouldn't be operating on a variable of another
class.
+ // we did this to get away from the singelton composite cache.
+ // we will need to create an event manager and pass it around
instead.
+ if ( cache.getCompositeCache() != null )
+ {
+ cache.getCompositeCache().addElementEvent( hand, event );
+ }
}
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/RemovalTestUtil.java Fri Feb 10
12:10:24 2006
@@ -38,7 +38,11 @@
}
/**
- * A unit test for JUnit
+ * Adds elements in the range specified and then removes them using the
+ * categorical or substring removal method.
+ *
+ * @param start
+ * @param end
*
* @exception Exception
* Description of the Exception
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/TestCacheElementRetrieval.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/TestCacheElementRetrieval.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/TestCacheElementRetrieval.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/TestCacheElementRetrieval.java
Fri Feb 10 12:10:24 2006
@@ -28,6 +28,10 @@
extends TestCase
{
+ /**
+ *
+ * @throws Exception
+ */
public void testSimpleElementRetrieval()
throws Exception
{
@@ -40,7 +44,7 @@
assertEquals( "Name wasn't right", "testCache1", elem.getCacheName() );
long diff = elem.getElementAttributes().getCreateTime() - now;
- assertTrue( "Create time should have been at or after the call", now
>= 0 );
+ assertTrue( "Create time should have been at or after the call", diff
>= 0 );
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/TestZeroSizeCache.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/TestZeroSizeCache.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/TestZeroSizeCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/TestZeroSizeCache.java Fri Feb 10
12:10:24 2006
@@ -26,6 +26,7 @@
/**
* Verify that a 0 size cache does not result in errors. You should be able
* to disable a region this way.
+ * @throws Exception
*
*/
public void testPutGetRemove()
@@ -38,6 +39,7 @@
jcs.put( i + ":key", "data" + i );
}
+ // all the gets should be null
for ( int i = items; i >= 0; i-- )
{
String res = (String) jcs.get( i + ":key" );
Copied:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
(from r292446,
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPIssueRemoveOnPut.java)
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPIssueRemoveOnPut.java&r1=292446&r2=376828&rev=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPIssueRemoveOnPut.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPIssueRemoveOnPutUnitTest.java
Fri Feb 10 12:10:24 2006
@@ -9,14 +9,13 @@
import org.apache.jcs.engine.behavior.ICacheElement;
/**
+ * Tests the issue remove on put fuctionality.
+ *
* @author asmuts
*/
-public class TestLateralTCPIssueRemoveOnPut
+public class LateralTCPIssueRemoveOnPutUnitTest
extends TestCase
{
-
- //private static boolean isSysOut = false;
-
private static boolean isSysOut = true;
/**
@@ -24,7 +23,7 @@
*
* @param testName
*/
- public TestLateralTCPIssueRemoveOnPut( String testName )
+ public LateralTCPIssueRemoveOnPutUnitTest( String testName )
{
super( testName );
}
@@ -150,18 +149,14 @@
}
+ /**
+ * @param s String to be printed
+ */
public static void p( String s )
{
if ( isSysOut )
{
System.out.println( s );
- }
- else
- {
- //if ( log.isInfoEnabled() )
- //{
- // log.info( s );
- //}
}
}
}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPConcurrentRandom.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPConcurrentRandom.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPConcurrentRandom.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPConcurrentRandom.java
Fri Feb 10 12:10:24 2006
@@ -164,6 +164,9 @@
}
+ /**
+ * @param s string to print
+ */
public static void p( String s )
{
if ( isSysOut )
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPFilterRemoveHashCode.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPFilterRemoveHashCode.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPFilterRemoveHashCode.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestLateralTCPFilterRemoveHashCode.java
Fri Feb 10 12:10:24 2006
@@ -158,6 +158,9 @@
}
+ /**
+ * @param s String to print
+ */
public static void p( String s )
{
if ( isSysOut )
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java
Fri Feb 10 12:10:24 2006
@@ -18,6 +18,7 @@
extends LateralCache
implements ICache
{
+ private static final long serialVersionUID = 1L;
/**
* @param cattr
Copied:
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
(from r292446,
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/TestUDPDiscovery.java)
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java?p2=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java&p1=jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/TestUDPDiscovery.java&r1=292446&r2=376828&rev=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/TestUDPDiscovery.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/UDPDiscoveryUnitTest.java
Fri Feb 10 12:10:24 2006
@@ -18,7 +18,7 @@
* @author Aaron Smuts
*
*/
-public class TestUDPDiscovery
+public class UDPDiscoveryUnitTest
extends TestCase
{
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/SystemPropertyUsageUnitTest.java
Fri Feb 10 12:10:24 2006
@@ -1,5 +1,21 @@
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.
+ */
+
import java.util.Properties;
import junit.framework.TestCase;
Modified:
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=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
Fri Feb 10 12:10:24 2006
@@ -20,6 +20,7 @@
import org.apache.commons.logging.LogFactory;
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;
/**
@@ -34,17 +35,159 @@
/**
* Times called.
*/
- public int callCount = 0;
+ private int callCount = 0;
private final static Log log = LogFactory.getLog(
ElementEventHandlerMockImpl.class );
+
+ // ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE
+ private int spoolCount = 0;
+
+ // ELEMENT_EVENT_SPOOLED_NOT_ALLOWED
+ private int spoolNotAllowedCount = 0;
+
+ // ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE
+ private int spoolNoDiskCount = 0;
- public void handleElementEvent( IElementEvent event )
+ // ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND
+ private int exceededMaxLifeBackgroundCount = 0;
+
+ // ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND
+ private int exceededIdleTimeBackgroundCount = 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 )
{
- callCount++;
- log.debug( "HANDLER -- HANDLER -- HANDLER -- ---EVENT CODE = " +
event.getElementEvent() );
+ setCallCount( getCallCount() + 1 );
+
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "HANDLER -- HANDLER -- HANDLER -- ---EVENT CODE = " +
event.getElementEvent() );
+ log.debug( "/n/n EVENT CODE = " + event.getElementEvent() + "
***************************" );
+ }
+
+ if ( event.getElementEvent() ==
IElementEventConstants.ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE )
+ {
+ 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 );
+ }
+ else if ( event.getElementEvent() ==
IElementEventConstants.ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND )
+ {
+ setExceededMaxLifeBackgroundCount(
getExceededMaxLifeBackgroundCount() + 1 );
+ }
+ else if ( event.getElementEvent() ==
IElementEventConstants.ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND )
+ {
+ setExceededIdleTimeBackgroundCount(
getExceededIdleTimeBackgroundCount() + 1 );
+ }
+ }
+
+ /**
+ * @param spoolCount
+ * The spoolCount to set.
+ */
+ public void setSpoolCount( int spoolCount )
+ {
+ this.spoolCount = spoolCount;
+ }
+
+ /**
+ * @return Returns the spoolCount.
+ */
+ public int getSpoolCount()
+ {
+ return spoolCount;
+ }
+
+ /**
+ * @param spoolNotAllowedCount
+ * The spoolNotAllowedCount to set.
+ */
+ public void setSpoolNotAllowedCount( int spoolNotAllowedCount )
+ {
+ this.spoolNotAllowedCount = spoolNotAllowedCount;
+ }
+
+ /**
+ * @return Returns the spoolNotAllowedCount.
+ */
+ public int getSpoolNotAllowedCount()
+ {
+ return spoolNotAllowedCount;
+ }
+
+ /**
+ * @param spoolNoDiskCount
+ * The spoolNoDiskCount to set.
+ */
+ public void setSpoolNoDiskCount( int spoolNoDiskCount )
+ {
+ this.spoolNoDiskCount = spoolNoDiskCount;
+ }
- log.debug( "/n/n EVENT CODE = " + event.getElementEvent() + "
***************************" );
- //return "Done";
+ /**
+ * @return Returns the spoolNoDiskCount.
+ */
+ public int getSpoolNoDiskCount()
+ {
+ return spoolNoDiskCount;
+ }
+
+ /**
+ * @param exceededMaxLifeBackground The exceededMaxLifeBackground to set.
+ */
+ public void setExceededMaxLifeBackgroundCount( int
exceededMaxLifeBackground )
+ {
+ this.exceededMaxLifeBackgroundCount = exceededMaxLifeBackground;
}
+
+ /**
+ * @return Returns the exceededMaxLifeBackground.
+ */
+ public int getExceededMaxLifeBackgroundCount()
+ {
+ return exceededMaxLifeBackgroundCount;
+ }
+
+ /**
+ * @param callCount The callCount to set.
+ */
+ public void setCallCount( int callCount )
+ {
+ this.callCount = callCount;
+ }
+
+ /**
+ * @return Returns the callCount.
+ */
+ public int getCallCount()
+ {
+ return callCount;
+ }
+
+ /**
+ * @param exceededIdleTimeBackground The exceededIdleTimeBackground to set.
+ */
+ public void setExceededIdleTimeBackgroundCount( int
exceededIdleTimeBackground )
+ {
+ this.exceededIdleTimeBackgroundCount = exceededIdleTimeBackground;
+ }
+
+ /**
+ * @return Returns the exceededIdleTimeBackground.
+ */
+ public int getExceededIdleTimeBackgroundCount()
+ {
+ return exceededIdleTimeBackgroundCount;
+ }
}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MemoryCacheMockImpl.java
Fri Feb 10 12:10:24 2006
@@ -1,5 +1,21 @@
package org.apache.jcs.engine.memory;
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License")
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
import java.io.IOException;
import java.io.Serializable;
import java.util.HashMap;
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/shrinking/ShrinkerThreadUnitTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/shrinking/ShrinkerThreadUnitTest.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/shrinking/ShrinkerThreadUnitTest.java
(original)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/shrinking/ShrinkerThreadUnitTest.java
Fri Feb 10 12:10:24 2006
@@ -1,11 +1,28 @@
package org.apache.jcs.engine.memory.shrinking;
+/*
+ * 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.TestCase;
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.control.event.ElementEventHandlerMockImpl;
import org.apache.jcs.engine.memory.MemoryCacheMockImpl;
/**
@@ -111,4 +128,61 @@
assertEquals( "Wrong number of elements remain.", 7, memory.getSize()
);
}
+ /**
+ * Add a mock event handler to the items. Verify that it gets called.
+ * <p>
+ * This is only testing the spooled background event
+ *
+ * @throws Exception
+ */
+ public void testSimpleShrinkMutipleWithEventHandler()
+ throws Exception
+{
+ MemoryCacheMockImpl memory = new MemoryCacheMockImpl();
+
+ CompositeCacheAttributes cacheAttr = new CompositeCacheAttributes();
+ cacheAttr.setMaxMemoryIdleTimeSeconds( 1 );
+ cacheAttr.setMaxSpoolPerRun( 3 );
+
+ memory.setCacheAttributes( cacheAttr );
+
+ ElementEventHandlerMockImpl handler = new ElementEventHandlerMockImpl();
+
+ for ( int i = 0; i < 10; i++ )
+ {
+ String key = "key" + i;
+ String value = "value";
+
+ ICacheElement element = new CacheElement( "testRegion", key, value );
+
+ ElementAttributes elementAttr = new ElementAttributes();
+ elementAttr.addElementEventHandler( handler );
+ elementAttr.setIsEternal( false );
+ element.setElementAttributes( elementAttr );
+ element.getElementAttributes().setMaxLifeSeconds( 1 );
+ memory.update( element );
+
+ ICacheElement returnedElement1 = memory.get( key );
+ assertNotNull( "We should have received an element", returnedElement1
);
+
+ // set this to 2 seconds ago.
+ elementAttr.lastAccessTime = System.currentTimeMillis() - 2000;
+ }
+
+ ShrinkerThread shrinker = new ShrinkerThread( memory );
+ Thread runner = new Thread( shrinker );
+ runner.run();
+
+ Thread.sleep( 500 );
+
+ assertEquals( "Waterfall called the wrong number of times.", 3,
memory.waterfallCallCount );
+
+ // the shrinker delegates the the composite cache on the memory cache to
put the
+ // event on the queue. This make it hard to test. TODO we need to change
this to make it easier to verify.
+ //assertEquals( "Event handler ExceededIdleTimeBackground called the wrong
number of times.", 3, handler.getExceededIdleTimeBackgroundCount() );
+
+ assertEquals( "Wrong number of elements remain.", 7, memory.getSize() );
+}
+
+
}
Modified:
jakarta/jcs/trunk/src/test/org/apache/jcs/servlet/ListTestCacheServlet.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/servlet/ListTestCacheServlet.java?rev=376828&r1=376827&r2=376828&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/servlet/ListTestCacheServlet.java
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/servlet/ListTestCacheServlet.java
Fri Feb 10 12:10:24 2006
@@ -26,6 +26,8 @@
extends HttpServlet
{
+ private static final long serialVersionUID = 1L;
+
// /** Description of the Field */
// protected static CacheHub cacheMgr;
// /** Description of the Field */
Added:
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/access/JCSWorkerUnitTest.java
URL:
http://svn.apache.org/viewcvs/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/access/JCSWorkerUnitTest.java?rev=376828&view=auto
==============================================================================
---
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/access/JCSWorkerUnitTest.java
(added)
+++
jakarta/jcs/trunk/src/test/org/apache/jcs/utils/access/JCSWorkerUnitTest.java
Fri Feb 10 12:10:24 2006
@@ -0,0 +1,51 @@
+package org.apache.jcs.utils.access;
+
+import junit.framework.TestCase;
+
+/**
+ * Test cases for the JCS worker.
+ *
+ * @author Aaron Smuts
+ *
+ */
+public class JCSWorkerUnitTest
+ extends TestCase
+{
+
+ /**
+ * Test basic worker funtionality. This is a serial not a concurrent
test.
+ * <p>
+ * Just verify that the worker will go to the cache before asking the
helper.
+ *
+ * @throws Exception
+ *
+ */
+ public void testSimpleGet()
+ throws Exception
+ {
+ JCSWorker cachingWorker = new JCSWorker( "example region" );
+
+ // This is the helper.
+ JCSWorkerHelper helper = new AbstractJCSWorkerHelper()
+ {
+ int timesCalled = 0;
+
+ public Object doWork()
+ {
+ Object results = new Long( ++timesCalled );
+ return results;
+ }
+ };
+
+ String key = "abc";
+
+ Long result = (Long) cachingWorker.getResult( key, helper );
+ assertEquals( "Called the wrong number of times", new Long( 1 ),
result );
+
+ // should get it fromthe cache.
+ Long result2 = (Long) cachingWorker.getResult( key, helper );
+ assertEquals( "Called the wrong number of times", new Long( 1 ),
result2 );
+
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]