Modified: jakarta/jcs/trunk/src/test-conf/TestTCPLateralRemoveFilter.ccf
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test-conf/TestTCPLateralRemoveFilter.ccf?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test-conf/TestTCPLateralRemoveFilter.ccf (original)
+++ jakarta/jcs/trunk/src/test-conf/TestTCPLateralRemoveFilter.ccf Fri Apr 11 11:43:26 2008
@@ -36,8 +36,8 @@
# simple Lateral TCP auxiliary
jcs.auxiliary.LTCP=org.apache.jcs.auxiliary.lateral.socket.tcp.LateralTCPCacheFactory
jcs.auxiliary.LTCP.attributes=org.apache.jcs.auxiliary.lateral.socket.tcp.TCPLateralCacheAttributes
-jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1111
-jcs.auxiliary.LTCP.attributes.TcpListenerPort=1110
+jcs.auxiliary.LTCP.attributes.TcpServers=localhost:1117
+jcs.auxiliary.LTCP.attributes.TcpListenerPort=1118
jcs.auxiliary.LTCP.attributes.AllowGet=false
jcs.auxiliary.LTCP.attributes.IssueRemoveOnPut=true
jcs.auxiliary.LTCP.attributes.FilterRemoveByHashCode=true
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/access/CacheAccessUnitTest.java Fri Apr 11 11:43:26 2008
@@ -1,257 +1,255 @@
-package org.apache.jcs.access;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.access.exception.CacheException;
-import org.apache.jcs.access.exception.ObjectExistsException;
-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;
-
-/**
- * Tests the methods of the cache access class from which the class JCS extends.
- *
- * @author Aaron Smuts
- *
- */
-public class CacheAccessUnitTest
- extends TestCase
-{
-
- /**
- * Verify that we get an object exists exception if the item is in the
- * cache.
- *
- */
- public void testPutSafe()
- {
-
- CacheAccess access = null;
- try
- {
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
- }
- catch ( CacheException e )
- {
- fail( "Shouldn't have received an error." + e.getMessage() );
- }
-
- String key = "mykey";
- String value = "myvalue";
-
- try
- {
- access.put( key, value );
- }
- catch ( CacheException e )
- {
- fail( "Should have been able to put " + e.getMessage() );
- }
- String returnedValue1 = (String) access.get( key );
- assertEquals( "Wrong value returned.", value, returnedValue1 );
-
- try
- {
- access.putSafe( key, "someothervalue" );
- fail( "We should have received an eception since this key is alredy in the cache." );
- }
- catch ( CacheException e )
- {
- // e.printStackTrace();
- // expected
- assertTrue( "Wrong type of exception.", e instanceof ObjectExistsException );
- assertTrue( "Should have the key in the error message.", e.getMessage().indexOf( "[" + key + "]" ) != -1 );
- }
-
- String returnedValue2 = (String) access.get( key );
- assertEquals( "Wrong value returned. Shoudl still be the original.", value, returnedValue2 );
- }
-
- /**
- * Try to put a null key and verify that we get an exception.
- *
- */
- public void testPutNullKey()
- {
-
- CacheAccess access = null;
- try
- {
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
- }
- catch ( CacheException e )
- {
- fail( "Shouldn't have received an error." + e.getMessage() );
- }
-
- String key = null;
- String value = "myvalue";
-
- try
- {
- access.put( key, value );
- fail( "Should not have been able to put a null key." );
- }
- catch ( CacheException e )
- {
- // expected
- assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
- }
- }
-
- /**
- * Try to put a null value and verify that we get an exception.
- *
- */
- public void testPutNullValue()
- {
-
- CacheAccess access = null;
- try
- {
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
- }
- catch ( CacheException e )
- {
- fail( "Shouldn't have received an error." + e.getMessage() );
- }
-
- String key = "myKey";
- String value = null;
-
- try
- {
- access.put( key, value );
- fail( "Should not have been able to put a null object." );
- }
- catch ( CacheException e )
- {
- // expected
- assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
- }
- }
-
- /**
- * Verify that elements that go in the region after this call takethe new
- * attributes.
- *
- * @throws Exception
- *
- */
- public void testSetDefaultElementAttributes()
- throws Exception
- {
-
- CacheAccess access = null;
-
- access = CacheAccess.getAccess( "test" );
-
- assertNotNull( "We should have an access class", access );
-
- long maxLife = 9876;
- IElementAttributes attr = new ElementAttributes();
- attr.setMaxLifeSeconds( maxLife );
-
- access.setDefaultElementAttributes( attr );
-
- assertEquals( "Wrong element attributes.", attr.getMaxLifeSeconds(), access.getDefaultElementAttributes()
- .getMaxLifeSeconds() );
-
- String key = "mykey";
- String value = "myvalue";
-
- access.put( key, value );
-
- ICacheElement element = access.getCacheElement( key );
-
- assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes()
- .getMaxLifeSeconds() );
- }
-
- /**
- * Verify that we can get a region using the define region method.
- *
- * @throws Exception
- *
- */
- public void testRegionDefiniton()
- throws Exception
- {
- CacheAccess access = CacheAccess.defineRegion( "test" );
- assertNotNull( "We should have an access class", access );
- }
-
- /**
- * Verify that we can get a region using the define region method with cache attributes.
- *
- * @throws Exception
- *
- */
- public void testRegionDefinitonWithAttributes()
- throws Exception
- {
- ICompositeCacheAttributes ca = new CompositeCacheAttributes();
-
- long maxIdleTime = 8765;
- ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
-
- CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
- assertNotNull( "We should have an access class", access );
-
- ICompositeCacheAttributes ca2 = access.getCacheAttributes();
- assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
- }
-
- /**
- * Verify that we can get a region using the define region method with cache attributes and elemetn attributes.
- *
- * @throws Exception
- *
- */
- public void testRegionDefinitonWithBothAttributes()
- throws Exception
- {
- ICompositeCacheAttributes ca = new CompositeCacheAttributes();
-
- long maxIdleTime = 8765;
- ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
-
- long maxLife = 9876;
- IElementAttributes attr = new ElementAttributes();
- attr.setMaxLifeSeconds( maxLife );
-
- CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
- assertNotNull( "We should have an access class", access );
-
- ICompositeCacheAttributes ca2 = access.getCacheAttributes();
- assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
- }
-
-}
+package org.apache.jcs.access;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.jcs.access.exception.CacheException;
+import org.apache.jcs.access.exception.ObjectExistsException;
+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;
+
+/**
+ * Tests the methods of the cache access class from which the class JCS extends.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class CacheAccessUnitTest
+ extends TestCase
+{
+ /**
+ * Verify that we get an object exists exception if the item is in the
+ * cache.
+ * @throws Exception
+ */
+ public void testPutSafe()
+ throws Exception
+ {
+ CacheAccess access = CacheAccess.getAccess( "test" );
+ assertNotNull( "We should have an access class", access );
+
+ String key = "mykey";
+ String value = "myvalue";
+
+ access.put( key, value );
+
+ String returnedValue1 = (String) access.get( key );
+ assertEquals( "Wrong value returned.", value, returnedValue1 );
+
+ try
+ {
+ access.putSafe( key, "someothervalue" );
+ fail( "We should have received an eception since this key is alredy in the cache." );
+ }
+ catch ( CacheException e )
+ {
+ assertTrue( "Wrong type of exception.", e instanceof ObjectExistsException );
+ assertTrue( "Should have the key in the error message.", e.getMessage().indexOf( "[" + key + "]" ) != -1 );
+ }
+
+ String returnedValue2 = (String) access.get( key );
+ assertEquals( "Wrong value returned. Shoudl still be the original.", value, returnedValue2 );
+ }
+
+ /**
+ * Try to put a null key and verify that we get an exception.
+ * @throws Exception
+ */
+ public void testPutNullKey()
+ throws Exception
+ {
+ CacheAccess access = CacheAccess.getAccess( "test" );
+ assertNotNull( "We should have an access class", access );
+
+ String key = null;
+ String value = "myvalue";
+
+ try
+ {
+ access.put( key, value );
+ fail( "Should not have been able to put a null key." );
+ }
+ catch ( CacheException e )
+ {
+ assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
+ }
+ }
+
+ /**
+ * Try to put a null value and verify that we get an exception.
+ * @throws Exception
+ */
+ public void testPutNullValue()
+ throws Exception
+ {
+ CacheAccess access = CacheAccess.getAccess( "test" );
+ assertNotNull( "We should have an access class", access );
+
+ String key = "myKey";
+ String value = null;
+
+ try
+ {
+ access.put( key, value );
+ fail( "Should not have been able to put a null object." );
+ }
+ catch ( CacheException e )
+ {
+ assertTrue( "Should have the work null in the error message.", e.getMessage().indexOf( "null" ) != -1 );
+ }
+ }
+
+ /**
+ * Verify that elements that go in the region after this call takethe new
+ * attributes.
+ *
+ * @throws Exception
+ */
+ public void testSetDefaultElementAttributes()
+ throws Exception
+ {
+ CacheAccess access = CacheAccess.getAccess( "test" );
+ assertNotNull( "We should have an access class", access );
+
+ long maxLife = 9876;
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( maxLife );
+
+ access.setDefaultElementAttributes( attr );
+
+ assertEquals( "Wrong element attributes.", attr.getMaxLifeSeconds(), access.getDefaultElementAttributes()
+ .getMaxLifeSeconds() );
+
+ String key = "mykey";
+ String value = "myvalue";
+
+ access.put( key, value );
+
+ ICacheElement element = access.getCacheElement( key );
+
+ assertEquals( "Wrong max life. Should have the new value.", maxLife, element.getElementAttributes()
+ .getMaxLifeSeconds() );
+ }
+
+ /**
+ * Verify that getCacheElements returns the elements requested based on the key.
+ *
+ * @throws Exception
+ */
+ public void testGetCacheElements()
+ throws Exception
+ {
+ //SETUP
+ CacheAccess access = CacheAccess.getAccess( "test" );
+ assertNotNull( "We should have an access class", access );
+
+ String keyOne = "mykeyone";
+ String keyTwo = "mykeytwo";
+ String keyThree = "mykeythree";
+ String valueOne = "myvalueone";
+ String valueTwo = "myvaluetwo";
+ String valueThree = "myvaluethree";
+
+ access.put( keyOne, valueOne );
+ access.put( keyTwo, valueTwo );
+ access.put( keyThree, valueThree );
+
+ Set input = new HashSet();
+ input.add( keyOne );
+ input.add( keyTwo );
+
+ //DO WORK
+ Map result = access.getCacheElements( input );
+
+ //VERIFY
+ assertEquals( "map size", 2, result.size() );
+ ICacheElement elementOne = (ICacheElement) result.get( keyOne );
+ assertEquals( "value one", keyOne, elementOne.getKey() );
+ assertEquals( "value one", valueOne, elementOne.getVal() );
+ ICacheElement elementTwo = (ICacheElement) result.get( keyTwo );
+ assertEquals( "value two", keyTwo, elementTwo.getKey() );
+ assertEquals( "value two", valueTwo, elementTwo.getVal() );
+ }
+
+ /**
+ * Verify that we can get a region using the define region method.
+ *
+ * @throws Exception
+ */
+ public void testRegionDefiniton()
+ throws Exception
+ {
+ CacheAccess access = CacheAccess.defineRegion( "test" );
+ assertNotNull( "We should have an access class", access );
+ }
+
+ /**
+ * Verify that we can get a region using the define region method with cache attributes.
+ *
+ * @throws Exception
+ *
+ */
+ public void testRegionDefinitonWithAttributes()
+ throws Exception
+ {
+ ICompositeCacheAttributes ca = new CompositeCacheAttributes();
+
+ long maxIdleTime = 8765;
+ ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
+
+ CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca );
+ assertNotNull( "We should have an access class", access );
+
+ ICompositeCacheAttributes ca2 = access.getCacheAttributes();
+ assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
+ }
+
+ /**
+ * Verify that we can get a region using the define region method with cache attributes and elemetn attributes.
+ *
+ * @throws Exception
+ *
+ */
+ public void testRegionDefinitonWithBothAttributes()
+ throws Exception
+ {
+ ICompositeCacheAttributes ca = new CompositeCacheAttributes();
+
+ long maxIdleTime = 8765;
+ ca.setMaxMemoryIdleTimeSeconds( maxIdleTime );
+
+ long maxLife = 9876;
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( maxLife );
+
+ CacheAccess access = CacheAccess.defineRegion( "testRegionDefinitonWithAttributes", ca, attr );
+ assertNotNull( "We should have an access class", access );
+
+ ICompositeCacheAttributes ca2 = access.getCacheAttributes();
+ assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/access/TestCacheAccess.java?rev=647264&r1=647263&r2=647264&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 Fri Apr 11 11:43:26 2008
@@ -39,20 +39,19 @@
* cache.
*
* This also provide basic methods for use in unit tests.
- *
*/
public class TestCacheAccess
{
+ /** log instance */
private final static Log log = LogFactory.getLog( TestCacheAccess.class );
+ /** cache instance to use in testing*/
private JCS cache_control = null;
+ /** do we use system.out.println to print out debug data?*/
private static boolean isSysOut = false;
- /**
- * Construct and initialize the cachecontrol based on the config file.
- *
- */
+ /**Construct and initialize the cachecontrol based on the config file. */
public TestCacheAccess()
{
this( "testCache1" );
@@ -79,12 +78,10 @@
*/
public void runLoop()
{
-
try
{
try
{
-
// process user input till done
boolean notDone = true;
String message = null;
@@ -135,13 +132,10 @@
//System.exit( -1 );
return;
}
- else
-
/////////////////////////////////////////////////////////////////////
// get multiple from a region
- if ( message.startsWith( "getm" ) )
+ else if ( message.startsWith( "getm" ) )
{
-
int num = 0;
boolean show = true;
@@ -177,12 +171,8 @@
getMultiple( num, show );
}
}
- else
-
- /////////////////////////////////////////////////////////////////////
- if ( message.startsWith( "getg" ) )
+ else if ( message.startsWith( "getg" ) )
{
-
String key = null;
String group = null;
boolean show = true;
@@ -213,7 +203,6 @@
}
else
{
-
long n_start = System.currentTimeMillis();
try
{
@@ -232,10 +221,7 @@
+ " millis ---" );
}
}
- else
-
- /////////////////////////////////////////////////////////////////////
- if ( message.startsWith( "getag" ) )
+ else if ( message.startsWith( "getag" ) )
{
// get auto from group
@@ -269,7 +255,6 @@
}
else
{
-
long n_start = System.currentTimeMillis();
try
{
@@ -291,10 +276,7 @@
+ " millis ---" );
}
}
- else
-
- /////////////////////////////////////////////////////////////////////
- if ( message.startsWith( "get" ) )
+ else if ( message.startsWith( "get" ) )
{
// plain old get
@@ -323,7 +305,6 @@
}
else
{
-
long n_start = System.currentTimeMillis();
try
{
@@ -343,7 +324,6 @@
}
else if ( message.startsWith( "putg" ) )
{
-
String group = null;
String key = null;
StringTokenizer toke = new StringTokenizer( message );
@@ -376,10 +356,8 @@
+ " millis ---" );
}
}
- else
-
// put automatically
- if ( message.startsWith( "putag" ) )
+ else if ( message.startsWith( "putag" ) )
{
String group = null;
@@ -417,10 +395,7 @@
+ " millis ---" );
}
}
- else
-
- /////////////////////////////////////////////////////////////////////
- if ( message.startsWith( "putm" ) )
+ else if ( message.startsWith( "putm" ) )
{
String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
int num = Integer.parseInt( numS.trim() );
@@ -433,10 +408,7 @@
putMultiple( num );
}
}
- else
-
- /////////////////////////////////////////////////////////////////////
- if ( message.startsWith( "pute" ) )
+ else if ( message.startsWith( "pute" ) )
{
String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
int num = Integer.parseInt( numS.trim() );
@@ -460,7 +432,6 @@
}
else if ( message.startsWith( "put" ) )
{
-
String key = null;
String val = null;
StringTokenizer toke = new StringTokenizer( message );
@@ -493,7 +464,6 @@
+ " millis ---" );
}
}
- /////////////////////////////////////////////////////////////////////
if ( message.startsWith( "removem" ) )
{
String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
@@ -507,7 +477,6 @@
removeMultiple( num );
}
}
-
else if ( message.startsWith( "removeall" ) )
{
cache_control.clear();
@@ -562,6 +531,7 @@
p( "Called system.gc()" );
}
else if ( message.startsWith( "random" ) )
+ {
if ( message.startsWith( "random" ) )
{
String rangeS = "";
@@ -612,7 +582,7 @@
random( range, numOps, show );
}
}
-
+ }
}
}
catch ( Exception e )
@@ -620,15 +590,13 @@
p( e.toString() );
e.printStackTrace( System.out );
}
-
}
catch ( Exception e )
{
p( e.toString() );
e.printStackTrace( System.out );
}
-
- } // end runLoop
+ }
/**
* Test harness.
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/AuxiliaryCacheMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/AuxiliaryCacheMockImpl.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/AuxiliaryCacheMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/AuxiliaryCacheMockImpl.java Fri Apr 11 11:43:26 2008
@@ -1,179 +1,192 @@
-package org.apache.jcs.auxiliary;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.Set;
-
-import org.apache.jcs.engine.CacheConstants;
-import org.apache.jcs.engine.behavior.ICache;
-import org.apache.jcs.engine.behavior.ICacheElement;
-import org.apache.jcs.engine.stats.behavior.IStats;
-
-/**
- * Mock auxiliary for unit tests.
- * <p>
- * @author Aaron Smuts
- */
-public class AuxiliaryCacheMockImpl
- implements AuxiliaryCache
-{
- private static final long serialVersionUID = 1L;
-
- /** Can setup the cache type */
- public int cacheType = ICache.DISK_CACHE;
-
- /** Can setup status */
- public int status = CacheConstants.STATUS_ALIVE;
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
- */
- public void update( ICacheElement ce )
- throws IOException
- {
- // TODO Auto-generated method stub
-
- }
-
- /*
- * (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 status;
- }
-
- /*
- * (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;
- }
-
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
- */
- public int getCacheType()
- {
- return cacheType;
- }
-
- /**
- * @return Returns the AuxiliaryCacheAttributes.
- */
- public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
- {
- return null;
- }
-}
+package org.apache.jcs.auxiliary;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.jcs.engine.CacheConstants;
+import org.apache.jcs.engine.behavior.ICache;
+import org.apache.jcs.engine.behavior.ICacheElement;
+import org.apache.jcs.engine.stats.behavior.IStats;
+
+/**
+ * Mock auxiliary for unit tests.
+ * <p>
+ * @author Aaron Smuts
+ */
+public class AuxiliaryCacheMockImpl
+ implements AuxiliaryCache
+{
+ private static final long serialVersionUID = 1L;
+
+ /** Can setup the cache type */
+ public int cacheType = ICache.DISK_CACHE;
+
+ /** Can setup status */
+ public int status = CacheConstants.STATUS_ALIVE;
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.auxiliary.AuxiliaryCache#update(org.apache.jcs.engine.behavior.ICacheElement)
+ */
+ public void update( ICacheElement ce )
+ throws IOException
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ /*
+ * (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;
+ }
+
+ /**
+ * Gets multiple items from the cache based on the given set of keys.
+ * <p>
+ * @param keys
+ * @return a map of Serializable key to ICacheElement element, or an empty map if there is no data in cache for any of these keys
+ */
+ public Map getMultiple( Set keys )
+ {
+ return new HashMap();
+ }
+
+ /*
+ * (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 status;
+ }
+
+ /*
+ * (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;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
+ */
+ public int getCacheType()
+ {
+ return cacheType;
+ }
+
+ /**
+ * @return Returns the AuxiliaryCacheAttributes.
+ */
+ public AuxiliaryCacheAttributes getAuxiliaryCacheAttributes()
+ {
+ return null;
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheConcurrentUnitTest.java Fri Apr 11 11:43:26 2008
@@ -1,216 +1,253 @@
-package org.apache.jcs.auxiliary.disk.block;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.extensions.ActiveTestSuite;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Test which exercises the block disk cache. This one uses three different
- * regions for thre threads.
- */
-public class BlockDiskCacheConcurrentUnitTest
- extends TestCase
-{
- /**
- * Number of items to cache, twice the configured maxObjects for the memory
- * cache regions.
- */
- private static int items = 200;
-
- /**
- * Constructor for the TestDiskCache object.
- *
- * @param testName
- * @throws Exception
- */
- public BlockDiskCacheConcurrentUnitTest( String testName ) throws Exception
- {
- super( testName );
- }
-
- /**
- * Main method passes this test to the text test runner.
- *
- * @param args
- */
- public static void main( String args[] )
- {
- String[] testCaseName = { BlockDiskCacheConcurrentUnitTest.class.getName() };
- junit.textui.TestRunner.main( testCaseName );
- }
-
- /**
- * A unit test suite for JUnit
- *
- * @return The test suite
- * @throws Exception
- */
- public static Test suite() throws Exception
- {
- ActiveTestSuite suite = new ActiveTestSuite();
-
- JCS.setConfigFilename( "/TestBlockDiskCache.ccf" );
- JCS.getInstance( "indexedRegion1" ).clear();
- JCS.getInstance( "indexedRegion2" ).clear();
- JCS.getInstance( "indexedRegion3" ).clear();
-
- suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache1" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "indexedRegion1" );
- }
- } );
-
- suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache2" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "indexedRegion2" );
- }
- } );
-
- suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache3" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "indexedRegion3" );
- }
- } );
-
- suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache4" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegionInRange( "indexedRegion3", 300, 600 );
- }
- } );
-
- return suite;
- }
-
- /**
- * Test setup
- */
- public void setUp()
- {
- JCS.setConfigFilename( "/TestBlockDiskCache.ccf" );
- }
-
- /**
- * Adds items to cache, gets them, and removes them. The item count is more
- * than the size of the memory cache, so items should spool to disk.
- *
- * @param region
- * Name of the region to access
- *
- * @exception Exception
- * If an error occurs
- */
- public void runTestForRegion( String region )
- throws Exception
- {
- JCS jcs = JCS.getInstance( region );
-
- // Add items to cache
- for ( int i = 0; i <= items; i++ )
- {
- jcs.put( i + ":key", region + " data " + i );
- }
-
- // Test that all items are in cache
- for ( int i = 0; i <= items; i++ )
- {
- String value = (String) jcs.get( i + ":key" );
-
- assertEquals( region + " data " + i, value );
- }
-
- // Remove all the items
- for ( int i = 0; i <= items; i++ )
- {
- jcs.remove( i + ":key" );
- }
-
- // Verify removal
- // another thread may have inserted since
- for ( int i = 0; i <= items; i++ )
- {
- assertNull( "Removed key should be null: " + i + ":key" + "\n stats " + jcs.getStats(), jcs
- .get( i + ":key" ) );
- }
- }
-
- /**
- * Adds items to cache, gets them, and removes them. The item count is more
- * than the size of the memory cache, so items should spool to disk.
- *
- * @param region
- * Name of the region to access
- * @param start
- * @param end
- *
- * @exception Exception
- * If an error occurs
- */
- public void runTestForRegionInRange( String region, int start, int end )
- throws Exception
- {
- JCS jcs = JCS.getInstance( region );
-
- // Add items to cache
- for ( int i = start; i <= end; i++ )
- {
- jcs.put( i + ":key", region + " data " + i );
- }
-
- // Test that all items are in cache
- for ( int i = start; i <= end; i++ )
- {
- String value = (String) jcs.get( i + ":key" );
-
- assertEquals( region + " data " + i, value );
- }
-
- // Remove all the items
- for ( int i = start; i <= end; i++ )
- {
- jcs.remove( i + ":key" );
- }
-
- System.out.println( jcs.getStats() );
-
- // Verify removal
- // another thread may have inserted since
- for ( int i = start; i <= end; i++ )
- {
- assertNull( "Removed key should be null: " + i + ":key " + "\n stats " + jcs.getStats(), jcs.get( i
- + ":key" ) );
- }
- }
-}
+package org.apache.jcs.auxiliary.disk.block;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.extensions.ActiveTestSuite;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Test which exercises the block disk cache. This one uses three different
+ * regions for thre threads.
+ */
+public class BlockDiskCacheConcurrentUnitTest
+ extends TestCase
+{
+ /**
+ * Number of items to cache, twice the configured maxObjects for the memory
+ * cache regions.
+ */
+ private static int items = 200;
+
+ /**
+ * Constructor for the TestDiskCache object.
+ *
+ * @param testName
+ * @throws Exception
+ */
+ public BlockDiskCacheConcurrentUnitTest( String testName )
+ throws Exception
+ {
+ super( testName );
+ }
+
+ /**
+ * Main method passes this test to the text test runner.
+ *
+ * @param args
+ */
+ public static void main( String args[] )
+ {
+ String[] testCaseName = { BlockDiskCacheConcurrentUnitTest.class.getName() };
+ junit.textui.TestRunner.main( testCaseName );
+ }
+
+ /**
+ * A unit test suite for JUnit
+ *
+ * @return The test suite
+ * @throws Exception
+ */
+ public static Test suite()
+ throws Exception
+ {
+ ActiveTestSuite suite = new ActiveTestSuite();
+
+ JCS.setConfigFilename( "/TestBlockDiskCache.ccf" );
+ JCS.getInstance( "indexedRegion1" ).clear();
+ JCS.getInstance( "indexedRegion2" ).clear();
+ JCS.getInstance( "indexedRegion3" ).clear();
+
+ suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache1" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "indexedRegion1" );
+ }
+ } );
+
+ suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache2" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "indexedRegion2" );
+ }
+ } );
+
+ suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache3" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "indexedRegion3" );
+ }
+ } );
+
+ suite.addTest( new BlockDiskCacheConcurrentUnitTest( "testBlockDiskCache4" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegionInRange( "indexedRegion3", 300, 600 );
+ }
+ } );
+
+ return suite;
+ }
+
+ /**
+ * Test setup
+ */
+ public void setUp()
+ {
+ JCS.setConfigFilename( "/TestBlockDiskCache.ccf" );
+ }
+
+ /**
+ * Adds items to cache, gets them, and removes them. The item count is more
+ * than the size of the memory cache, so items should spool to disk.
+ *
+ * @param region
+ * Name of the region to access
+ *
+ * @exception Exception
+ * If an error occurs
+ */
+ public void runTestForRegion( String region )
+ throws Exception
+ {
+ JCS jcs = JCS.getInstance( region );
+
+ // Add items to cache
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.put( i + ":key", region + " data " + i );
+ }
+
+ // Test that all items are in cache
+ for ( int i = 0; i <= items; i++ )
+ {
+ String value = (String) jcs.get( i + ":key" );
+
+ assertEquals( region + " data " + i, value );
+ }
+
+ // Test that getElements returns all the expected values
+ Set keys = new HashSet();
+ for ( int i = 0; i <= items; i++ )
+ {
+ keys.add( i + ":key" );
+ }
+
+ Map elements = jcs.getCacheElements( keys );
+ for ( int i = 0; i <= items; i++ )
+ {
+ ICacheElement element = (ICacheElement) elements.get( i + ":key" );
+ assertNotNull( "element " + i + ":key is missing", element );
+ assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
+ }
+
+ // Remove all the items
+ for ( int i = 0; i <= items; i++ )
+ {
+ jcs.remove( i + ":key" );
+ }
+
+ // Verify removal
+ // another thread may have inserted since
+ for ( int i = 0; i <= items; i++ )
+ {
+ assertNull( "Removed key should be null: " + i + ":key" + "\n stats " + jcs.getStats(), jcs
+ .get( i + ":key" ) );
+ }
+ }
+
+ /**
+ * Adds items to cache, gets them, and removes them. The item count is more
+ * than the size of the memory cache, so items should spool to disk.
+ *
+ * @param region
+ * Name of the region to access
+ * @param start
+ * @param end
+ *
+ * @exception Exception
+ * If an error occurs
+ */
+ public void runTestForRegionInRange( String region, int start, int end )
+ throws Exception
+ {
+ JCS jcs = JCS.getInstance( region );
+
+ // Add items to cache
+ for ( int i = start; i <= end; i++ )
+ {
+ jcs.put( i + ":key", region + " data " + i );
+ }
+
+ // Test that all items are in cache
+ for ( int i = start; i <= end; i++ )
+ {
+ String value = (String) jcs.get( i + ":key" );
+
+ assertEquals( region + " data " + i, value );
+ }
+
+ // Test that getElements returns all the expected values
+ Set keys = new HashSet();
+ for ( int i = start; i <= end; i++ )
+ {
+ keys.add( i + ":key" );
+ }
+
+ Map elements = jcs.getCacheElements( keys );
+ for ( int i = start; i <= end; i++ )
+ {
+ ICacheElement element = (ICacheElement) elements.get( i + ":key" );
+ assertNotNull( "element " + i + ":key is missing", element );
+ assertEquals( "value " + i + ":key", region + " data " + i, element.getVal() );
+ }
+
+ // Remove all the items
+ for ( int i = start; i <= end; i++ )
+ {
+ jcs.remove( i + ":key" );
+ }
+
+ System.out.println( jcs.getStats() );
+
+ // Verify removal
+ // another thread may have inserted since
+ for ( int i = start; i <= end; i++ )
+ {
+ assertNull( "Removed key should be null: " + i + ":key " + "\n stats " + jcs.getStats(), jcs.get( i
+ + ":key" ) );
+ }
+ }
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java?rev=647264&r1=647263&r2=647264&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheSameRegionConcurrentUnitTest.java Fri Apr 11 11:43:26 2008
@@ -1,143 +1,164 @@
-package org.apache.jcs.auxiliary.disk.block;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.extensions.ActiveTestSuite;
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-import org.apache.jcs.JCS;
-
-/**
- * Test which exercises the block disk cache. Runs three threads against the same region.
- */
-public class BlockDiskCacheSameRegionConcurrentUnitTest
- extends TestCase
-{
- /**
- * Constructor for the TestDiskCache object.
- * <p>
- * @param testName
- */
- public BlockDiskCacheSameRegionConcurrentUnitTest( String testName )
- {
- super( testName );
- }
-
- /**
- * Main method passes this test to the text test runner.
- * <p>
- * @param args
- */
- public static void main( String args[] )
- {
- String[] testCaseName = { BlockDiskCacheSameRegionConcurrentUnitTest.class.getName() };
- junit.textui.TestRunner.main( testCaseName );
- }
-
- /**
- * A unit test suite for JUnit
- * @return The test suite
- */
- public static Test suite()
- {
- ActiveTestSuite suite = new ActiveTestSuite();
-
- suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache1" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "blockRegion4", 0, 200 );
- }
- } );
-
- suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache2" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "blockRegion4", 1000, 1200 );
- }
- } );
-
- suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache3" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "blockRegion4", 2000, 2200 );
- }
- } );
-
- suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache4" )
- {
- public void runTest()
- throws Exception
- {
- this.runTestForRegion( "blockRegion4", 2200, 5200 );
- }
- } );
-
- return suite;
- }
-
- /**
- * Test setup. Sets the config name and clears the region.
- * <p>
- * @throws Exception
- */
- public void setUp() throws Exception
- {
- JCS.setConfigFilename( "/TestBlockDiskCacheCon.ccf" );
- JCS.getInstance( "blockRegion4" ).clear();
- }
-
- /**
- * Adds items to cache, gets them, and removes them. The item count is more than the size of the
- * memory cache, so items should spool to disk.
- * @param region Name of the region to access
- * @param start
- * @param end
- * @exception Exception If an error occurs
- */
- public void runTestForRegion( String region, int start, int end )
- throws Exception
- {
- JCS jcs = JCS.getInstance( region );
-
- // Add items to cache
-
- for ( int i = start; i <= end; i++ )
- {
- jcs.put( i + ":key", region + " data " + i + "-" + region );
- }
-
- // Test that all items are in cache
-
- for ( int i = start; i <= end; i++ )
- {
- String key = i + ":key";
- String value = (String) jcs.get( key );
-
- assertEquals( "Wrong value for key [" + key + "]", region + " data " + i + "-" + region, value );
- }
- }
-}
+package org.apache.jcs.auxiliary.disk.block;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import junit.extensions.ActiveTestSuite;
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+import org.apache.jcs.JCS;
+import org.apache.jcs.engine.behavior.ICacheElement;
+
+/**
+ * Test which exercises the block disk cache. Runs three threads against the same region.
+ */
+public class BlockDiskCacheSameRegionConcurrentUnitTest
+ extends TestCase
+{
+ /**
+ * Constructor for the TestDiskCache object.
+ * <p>
+ * @param testName
+ */
+ public BlockDiskCacheSameRegionConcurrentUnitTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * Main method passes this test to the text test runner.
+ * <p>
+ * @param args
+ */
+ public static void main( String args[] )
+ {
+ String[] testCaseName = { BlockDiskCacheSameRegionConcurrentUnitTest.class.getName() };
+ junit.textui.TestRunner.main( testCaseName );
+ }
+
+ /**
+ * A unit test suite for JUnit
+ * @return The test suite
+ */
+ public static Test suite()
+ {
+ ActiveTestSuite suite = new ActiveTestSuite();
+
+ suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache1" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "blockRegion4", 0, 200 );
+ }
+ } );
+
+ suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache2" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "blockRegion4", 1000, 1200 );
+ }
+ } );
+
+ suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache3" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "blockRegion4", 2000, 2200 );
+ }
+ } );
+
+ suite.addTest( new BlockDiskCacheSameRegionConcurrentUnitTest( "testBlockDiskCache4" )
+ {
+ public void runTest()
+ throws Exception
+ {
+ this.runTestForRegion( "blockRegion4", 2200, 5200 );
+ }
+ } );
+
+ return suite;
+ }
+
+ /**
+ * Test setup. Sets the config name and clears the region.
+ * <p>
+ * @throws Exception
+ */
+ public void setUp()
+ throws Exception
+ {
+ JCS.setConfigFilename( "/TestBlockDiskCacheCon.ccf" );
+ JCS.getInstance( "blockRegion4" ).clear();
+ }
+
+ /**
+ * Adds items to cache, gets them, and removes them. The item count is more than the size of the
+ * memory cache, so items should spool to disk.
+ * @param region Name of the region to access
+ * @param start
+ * @param end
+ * @exception Exception If an error occurs
+ */
+ public void runTestForRegion( String region, int start, int end )
+ throws Exception
+ {
+ JCS jcs = JCS.getInstance( region );
+
+ // Add items to cache
+
+ for ( int i = start; i <= end; i++ )
+ {
+ jcs.put( i + ":key", region + " data " + i + "-" + region );
+ }
+
+ // Test that all items are in cache
+
+ for ( int i = start; i <= end; i++ )
+ {
+ String key = i + ":key";
+ String value = (String) jcs.get( key );
+
+ assertEquals( "Wrong value for key [" + key + "]", region + " data " + i + "-" + region, value );
+ }
+
+ // Test that getElements returns all the expected values
+ Set keys = new HashSet();
+ for ( int i = start; i <= end; i++ )
+ {
+ keys.add( i + ":key" );
+ }
+
+ Map elements = jcs.getCacheElements( keys );
+ for ( int i = start; i <= end; i++ )
+ {
+ ICacheElement element = (ICacheElement) elements.get( i + ":key" );
+ assertNotNull( "element " + i + ":key is missing", element );
+ assertEquals( "value " + i + ":key", region + " data " + i + "-" + region, element.getVal() );
+ }
+ }
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.