svn commit: r714178 [2/3] - in /jakarta/jcs/trunk/src: java/org/apache/jcs/access/ java/org/apache/jcs/auxiliary/ java/org/apache/jcs/auxiliary/disk/ java/org/apache/jcs/auxiliary/disk/block/ java/org/apache/jcs/auxiliary/disk/indexed/ java/org/apache/...
[email protected] Fri, 14 Nov 2008 22:50:14 -0000
| Newsgroups | gmane.comp.jakarta.turbine.jcs.devel |
|---|---|
| Message-ID | <[email protected]> |
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/control/CompositeCacheManager.java Fri Nov 14 14:50:12 2008
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
+import java.security.AccessControlException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
@@ -192,7 +193,14 @@
protected CompositeCacheManager()
{
ShutdownHook shutdownHook = new ShutdownHook();
- Runtime.getRuntime().addShutdownHook( shutdownHook );
+ try
+ {
+ Runtime.getRuntime().addShutdownHook( shutdownHook );
+ }
+ catch ( AccessControlException e )
+ {
+ log.error( "Could not register shutdown hook.", e );
+ }
}
/**
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java?rev=714178&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/KeyMatcherPatternImpl.java Fri Nov 14 14:50:12 2008
@@ -0,0 +1,42 @@
+package org.apache.jcs.engine.match;
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.jcs.engine.match.behavior.IKeyMatcher;
+
+/** This implementation of the KeyMatcher uses standard Java Pattern matching. */
+public class KeyMatcherPatternImpl
+ implements IKeyMatcher
+{
+ /**
+ * Creates a pattern and find matches on the array.
+ * <p>
+ * @param pattern
+ * @param keyArray
+ * @return Set of the matching keys
+ */
+ public Set getMatchingKeysFromArray( String pattern, Object[] keyArray )
+ {
+ Pattern compiledPattern = Pattern.compile( pattern );
+
+ Set matchingKeys = new HashSet();
+
+ // Look for matches
+ for ( int i = 0; i < keyArray.length; i++ )
+ {
+ Object key = keyArray[i];
+ if ( key instanceof String )
+ {
+ Matcher matcher = compiledPattern.matcher( (String) key );
+ if ( matcher.matches() )
+ {
+ matchingKeys.add( key );
+ }
+ }
+ }
+ return matchingKeys;
+ }
+}
Added: jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java?rev=714178&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java (added)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/engine/match/behavior/IKeyMatcher.java Fri Nov 14 14:50:12 2008
@@ -0,0 +1,16 @@
+package org.apache.jcs.engine.match.behavior;
+
+import java.util.Set;
+
+/** Key matchers need to implement this interface. */
+public interface IKeyMatcher
+{
+ /**
+ * Creates a pattern and find matches on the array.
+ * <p>
+ * @param pattern
+ * @param keyArray
+ * @return Set of the matching keys
+ */
+ Set getMatchingKeysFromArray( String pattern, Object[] keyArray );
+}
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=714178&r1=714177&r2=714178&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 Nov 14 14:50:12 2008
@@ -20,6 +20,7 @@
*/
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Map;
import java.util.Set;
@@ -42,9 +43,8 @@
extends TestCase
{
/**
- * Verify that we get an object exists exception if the item is in the
- * cache.
- * @throws Exception
+ * Verify that we get an object exists exception if the item is in the cache.
+ * @throws Exception
*/
public void testPutSafe()
throws Exception
@@ -77,7 +77,7 @@
/**
* Try to put a null key and verify that we get an exception.
- * @throws Exception
+ * @throws Exception
*/
public void testPutNullKey()
throws Exception
@@ -124,9 +124,7 @@
}
/**
- * Verify that elements that go in the region after this call takethe new
- * attributes.
- *
+ * Verify that elements that go in the region after this call takethe new attributes.
* @throws Exception
*/
public void testSetDefaultElementAttributes()
@@ -157,7 +155,6 @@
/**
* Verify that getCacheElements returns the elements requested based on the key.
- *
* @throws Exception
*/
public void testGetCacheElements()
@@ -197,7 +194,6 @@
/**
* Verify that we can get a region using the define region method.
- *
* @throws Exception
*/
public void testRegionDefiniton()
@@ -209,9 +205,7 @@
/**
* Verify that we can get a region using the define region method with cache attributes.
- *
* @throws Exception
- *
*/
public void testRegionDefinitonWithAttributes()
throws Exception
@@ -229,10 +223,9 @@
}
/**
- * Verify that we can get a region using the define region method with cache attributes and elemetn attributes.
- *
+ * 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
@@ -252,4 +245,118 @@
ICompositeCacheAttributes ca2 = access.getCacheAttributes();
assertEquals( "Wrong idle time setting.", ca.getMaxMemoryIdleTimeSeconds(), ca2.getMaxMemoryIdleTimeSeconds() );
}
+
+ /**
+ * Verify we can get some matching elements..
+ * <p>
+ * @throws Exception
+ */
+ public void testGetMatching_Normal()
+ throws Exception
+ {
+ // SETUP
+ int maxMemorySize = 1000;
+ String keyprefix1 = "MyPrefix1";
+ String keyprefix2 = "MyPrefix2";
+ String memoryCacheClassName = "org.apache.jcs.engine.memory.lru.LRUMemoryCache";
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setMemoryCacheName( memoryCacheClassName );
+ cattr.setMaxObjects( maxMemorySize );
+
+ long maxLife = 9876;
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( maxLife );
+
+ CacheAccess access = CacheAccess.defineRegion( "testGetMatching_Normal", cattr, attr );
+
+ // DO WORK
+ int numToInsertPrefix1 = 10;
+ // insert with prefix1
+ for ( int i = 0; i < numToInsertPrefix1; i++ )
+ {
+ access.put( keyprefix1 + String.valueOf( i ), new Integer( i ) );
+ }
+
+ int numToInsertPrefix2 = 50;
+ // insert with prefix1
+ for ( int i = 0; i < numToInsertPrefix2; i++ )
+ {
+ access.put( keyprefix2 + String.valueOf( i ), new Integer( i ) );
+ }
+
+ Map result1 = access.getMatching( keyprefix1 + ".+" );
+ Map result2 = access.getMatching( keyprefix2 + "\\S+" );
+
+ // VERIFY
+ assertEquals( "Wrong number returned 1:", numToInsertPrefix1, result1.size() );
+ assertEquals( "Wrong number returned 2:", numToInsertPrefix2, result2.size() );
+ //System.out.println( result1 );
+
+ // verify that the elements are unwrapped
+ Set keySet1 = result1.keySet();
+ Iterator it1 = keySet1.iterator();
+ while ( it1.hasNext() )
+ {
+ Object key = it1.next();
+ Object value = result1.get( key );
+ assertFalse( "Should not be a cache element.", value instanceof ICacheElement );
+ }
+ }
+
+ /**
+ * Verify we can get some matching elements..
+ * <p>
+ * @throws Exception
+ */
+ public void testGetMatchingElements_Normal()
+ throws Exception
+ {
+ // SETUP
+ int maxMemorySize = 1000;
+ String keyprefix1 = "MyPrefix1";
+ String keyprefix2 = "MyPrefix2";
+ String memoryCacheClassName = "org.apache.jcs.engine.memory.lru.LRUMemoryCache";
+ ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+ cattr.setMemoryCacheName( memoryCacheClassName );
+ cattr.setMaxObjects( maxMemorySize );
+
+ long maxLife = 9876;
+ IElementAttributes attr = new ElementAttributes();
+ attr.setMaxLifeSeconds( maxLife );
+
+ CacheAccess access = CacheAccess.defineRegion( "testGetMatching_Normal", cattr, attr );
+
+ // DO WORK
+ int numToInsertPrefix1 = 10;
+ // insert with prefix1
+ for ( int i = 0; i < numToInsertPrefix1; i++ )
+ {
+ access.put( keyprefix1 + String.valueOf( i ), new Integer( i ) );
+ }
+
+ int numToInsertPrefix2 = 50;
+ // insert with prefix1
+ for ( int i = 0; i < numToInsertPrefix2; i++ )
+ {
+ access.put( keyprefix2 + String.valueOf( i ), new Integer( i ) );
+ }
+
+ Map result1 = access.getMatchingCacheElements( keyprefix1 + "\\S+" );
+ Map result2 = access.getMatchingCacheElements( keyprefix2 + ".+" );
+
+ // VERIFY
+ assertEquals( "Wrong number returned 1:", numToInsertPrefix1, result1.size() );
+ assertEquals( "Wrong number returned 2:", numToInsertPrefix2, result2.size() );
+ //System.out.println( result1 );
+
+ // verify that the elements are wrapped
+ Set keySet1 = result1.keySet();
+ Iterator it1 = keySet1.iterator();
+ while ( it1.hasNext() )
+ {
+ Object key = it1.next();
+ Object value = result1.get( key );
+ assertTrue( "Should be a cache element.", value instanceof ICacheElement );
+ }
+ }
}
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=714178&r1=714177&r2=714178&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 Nov 14 14:50:12 2008
@@ -22,36 +22,35 @@
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
+import java.util.Map;
import java.util.Random;
import java.util.StringTokenizer;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.apache.jcs.JCS;
+import org.apache.jcs.access.exception.CacheException;
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.ElementEventHandlerMockImpl;
/**
- * Allows the user to run common cache commands from the command line for a test
- * cache.
- *
- * This also provide basic methods for use in unit tests.
+ * Allows the user to run common cache commands from the command line for a test 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*/
+ /** cache instance to use in testing */
private JCS cache_control = null;
- /** do we use system.out.println to print out debug data?*/
+ /** 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" );
@@ -80,529 +79,635 @@
{
try
{
- try
- {
- // process user input till done
- boolean notDone = true;
- String message = null;
- // wait to dispose
- BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
+ // process user input till done
+ boolean notDone = true;
+ String message = null;
+ // wait to dispose
+ BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
- help();
+ help();
- while ( notDone )
- {
- p( "enter command:" );
+ while ( notDone )
+ {
+ p( "enter command:" );
- message = br.readLine();
+ message = br.readLine();
- if ( message.startsWith( "help" ) )
+ if ( message.startsWith( "help" ) )
+ {
+ help();
+ }
+ else if ( message.startsWith( "gc" ) )
+ {
+ System.gc();
+ }
+ else if ( message.startsWith( "getAttributeNames" ) )
+ {
+ long n_start = System.currentTimeMillis();
+ String groupName = null;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ groupName = t.trim();
+ }
+ }
+ getAttributeNames( groupName );
+ long n_end = System.currentTimeMillis();
+ p( "---got attrNames for " + groupName + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ else if ( message.startsWith( "shutDown" ) )
+ {
+ CompositeCacheManager.getInstance().shutDown();
+ //cache_control.dispose();
+ notDone = false;
+ //System.exit( -1 );
+ return;
+ }
+ /////////////////////////////////////////////////////////////////////
+ // get multiple from a region
+ else if ( message.startsWith( "getm" ) )
+ {
+ processGetMultiple( message );
+ }
+ else if ( message.startsWith( "getg" ) )
+ {
+ processGetGroup( message );
+ }
+ else if ( message.startsWith( "getag" ) )
+ {
+ processGetAutoGroup( message );
+ }
+ else if ( message.startsWith( "getMatching" ) )
+ {
+ processGetMatching( message );
+ }
+ else if ( message.startsWith( "get" ) )
+ {
+ processGet( message );
+ }
+ else if ( message.startsWith( "putg" ) )
+ {
+ processPutGroup( message );
+ }
+ // put automatically
+ else if ( message.startsWith( "putag" ) )
+ {
+ processPutAutoGroup( message );
+ }
+ else if ( message.startsWith( "putm" ) )
+ {
+ String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if ( numS == null )
{
- help();
+ p( "usage: putm numbertoput" );
}
- else if ( message.startsWith( "gc" ) )
+ else
+ {
+ putMultiple( num );
+ }
+ }
+ else if ( message.startsWith( "pute" ) )
+ {
+ String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if ( numS == null )
{
- System.gc();
+ p( "usage: putme numbertoput" );
}
- else if ( message.startsWith( "getAttributeNames" ) )
+ else
{
long n_start = System.currentTimeMillis();
- String groupName = null;
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
+ for ( int n = 0; n < num; n++ )
{
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- groupName = t.trim();
- }
+ IElementAttributes attrp = cache_control.getDefaultElementAttributes();
+ ElementEventHandlerMockImpl hand = new ElementEventHandlerMockImpl();
+ attrp.addElementEventHandler( hand );
+ cache_control.put( "key" + n, "data" + n + " put from ta = junk", attrp );
}
- getAttributeNames( groupName );
long n_end = System.currentTimeMillis();
- p( "---got attrNames for " + groupName + " in " + String.valueOf( n_end - n_start )
- + " millis ---" );
+ p( "---put " + num + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
}
- else if ( message.startsWith( "shutDown" ) )
+ }
+ else if ( message.startsWith( "put" ) )
+ {
+ processPut( message );
+ }
+ if ( message.startsWith( "removem" ) )
+ {
+ String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if ( numS == null )
{
- CompositeCacheManager.getInstance().shutDown();
- //cache_control.dispose();
- notDone = false;
- //System.exit( -1 );
- return;
- }
- /////////////////////////////////////////////////////////////////////
- // get multiple from a region
- else if ( message.startsWith( "getm" ) )
- {
- int num = 0;
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- try
- {
- num = Integer.parseInt( t.trim() );
- }
- catch ( NumberFormatException nfe )
- {
- p( t + "not a number" );
- }
- }
- else if ( tcnt == 3 )
- {
- show = new Boolean( t ).booleanValue();
- }
- }
-
- if ( tcnt < 2 )
- {
- p( "usage: get numbertoget show values[true|false]" );
- }
- else
- {
- getMultiple( num, show );
- }
+ p( "usage: removem numbertoremove" );
}
- else if ( message.startsWith( "getg" ) )
+ else
{
- String key = null;
- String group = null;
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- key = t.trim();
- }
- else if ( tcnt == 3 )
- {
- group = t.trim();
- }
- else if ( tcnt == 4 )
- {
- show = new Boolean( t ).booleanValue();
- }
- }
-
- if ( tcnt < 2 )
- {
- p( "usage: get key show values[true|false]" );
- }
- else
- {
- long n_start = System.currentTimeMillis();
- try
- {
- Object obj = cache_control.getFromGroup( key, group );
- if ( show && obj != null )
- {
- p( obj.toString() );
- }
- }
- catch ( Exception e )
- {
- log.error( e );
- }
- long n_end = System.currentTimeMillis();
- p( "---got " + key + " from group " + group + " in " + String.valueOf( n_end - n_start )
- + " millis ---" );
- }
+ removeMultiple( num );
}
- else if ( message.startsWith( "getag" ) )
+ }
+ else if ( message.startsWith( "removeall" ) )
+ {
+ cache_control.clear();
+ p( "removed all" );
+ }
+ else if ( message.startsWith( "remove" ) )
+ {
+ String key = message.substring( message.indexOf( " " ) + 1, message.length() );
+ cache_control.remove( key );
+ p( "removed " + key );
+ }
+ else if ( message.startsWith( "deattr" ) )
+ {
+ IElementAttributes ae = cache_control.getDefaultElementAttributes();
+ p( "Default IElementAttributes " + ae );
+ }
+ else if ( message.startsWith( "cloneattr" ) )
+ {
+ String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
+ int num = Integer.parseInt( numS.trim() );
+ if ( numS == null )
{
- // get auto from group
-
- int num = 0;
- String group = null;
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- num = Integer.parseInt( t.trim() );
- }
- else if ( tcnt == 3 )
- {
- group = t.trim();
- }
- else if ( tcnt == 4 )
- {
- show = new Boolean( t ).booleanValue();
- }
- }
-
- if ( tcnt < 2 )
- {
- p( "usage: get key show values[true|false]" );
- }
- else
+ p( "usage: put numbertoput" );
+ }
+ else
+ {
+ IElementAttributes attrp = new ElementAttributes();
+ long n_start = System.currentTimeMillis();
+ for ( int n = 0; n < num; n++ )
{
- long n_start = System.currentTimeMillis();
- try
- {
- for ( int a = 0; a < num; a++ )
- {
- Object obj = cache_control.getFromGroup( "keygr" + a, group );
- if ( show && obj != null )
- {
- p( obj.toString() );
- }
- }
- }
- catch ( Exception e )
- {
- log.error( e );
- }
- long n_end = System.currentTimeMillis();
- p( "---got " + num + " from group " + group + " in " + String.valueOf( n_end - n_start )
- + " millis ---" );
+ attrp.copy();
}
+ long n_end = System.currentTimeMillis();
+ p( "---cloned attr " + num + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
}
- else if ( message.startsWith( "get" ) )
+ }
+ else if ( message.startsWith( "switch" ) )
+ {
+ String name = message.substring( message.indexOf( " " ) + 1, message.length() );
+
+ setRegion( name );
+ p( "switched to cache = " + name );
+ p( cache_control.toString() );
+ }
+ else if ( message.startsWith( "stats" ) )
+ {
+ p( cache_control.getStats() );
+ }
+ else if ( message.startsWith( "gc" ) )
+ {
+ System.gc();
+ p( "Called system.gc()" );
+ }
+ else if ( message.startsWith( "random" ) )
+ {
+ if ( message.startsWith( "random" ) )
{
- // plain old get
+ processRandom( message );
+ }
+ }
+ }
+ }
+ catch ( Exception e )
+ {
+ p( e.toString() );
+ e.printStackTrace( System.out );
+ }
+ }
- String key = null;
- boolean show = true;
+ /**
+ * @param message
+ */
+ private void processGetMultiple( String message )
+ {
+ int num = 0;
+ boolean show = true;
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- key = t.trim();
- }
- else if ( tcnt == 3 )
- {
- show = new Boolean( t ).booleanValue();
- }
- }
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ try
+ {
+ num = Integer.parseInt( t.trim() );
+ }
+ catch ( NumberFormatException nfe )
+ {
+ p( t + "not a number" );
+ }
+ }
+ else if ( tcnt == 3 )
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
- if ( tcnt < 2 )
- {
- p( "usage: get key show values[true|false]" );
- }
- else
- {
- long n_start = System.currentTimeMillis();
- try
- {
- Object obj = cache_control.get( key );
- if ( show && obj != null )
- {
- p( obj.toString() );
- }
- }
- catch ( Exception e )
- {
- log.error( e );
- }
- long n_end = System.currentTimeMillis();
- p( "---got " + key + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
- }
- }
- else if ( message.startsWith( "putg" ) )
- {
- String group = null;
- String key = null;
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- key = t.trim();
- }
- else if ( tcnt == 3 )
- {
- group = t.trim();
- }
- }
+ if ( tcnt < 2 )
+ {
+ p( "usage: get numbertoget show values[true|false]" );
+ }
+ else
+ {
+ getMultiple( num, show );
+ }
+ }
- if ( tcnt < 3 )
- {
- p( "usage: putg key group" );
- }
- else
- {
- long n_start = System.currentTimeMillis();
- cache_control.putInGroup( key, group,
- "data from putg ----asdfasfas-asfasfas-asfas in group " + group );
- long n_end = System.currentTimeMillis();
- p( "---put " + key + " in group " + group + " in " + String.valueOf( n_end - n_start )
- + " millis ---" );
- }
- }
- // put automatically
- else if ( message.startsWith( "putag" ) )
- {
+ /**
+ * @param message
+ */
+ private void processGetGroup( String message )
+ {
+ String key = null;
+ String group = null;
+ boolean show = true;
- String group = null;
- int num = 0;
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- num = Integer.parseInt( t.trim() );
- }
- else if ( tcnt == 3 )
- {
- group = t.trim();
- }
- }
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ key = t.trim();
+ }
+ else if ( tcnt == 3 )
+ {
+ group = t.trim();
+ }
+ else if ( tcnt == 4 )
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
- if ( tcnt < 3 )
- {
- p( "usage: putag num group" );
- }
- else
- {
- long n_start = System.currentTimeMillis();
- for ( int a = 0; a < num; a++ )
- {
- cache_control.putInGroup( "keygr" + a, group, "data " + a
- + " from putag ----asdfasfas-asfasfas-asfas in group " + group );
- }
- long n_end = System.currentTimeMillis();
- p( "---put " + num + " in group " + group + " in " + String.valueOf( n_end - n_start )
- + " millis ---" );
- }
- }
- else if ( message.startsWith( "putm" ) )
- {
- String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
- int num = Integer.parseInt( numS.trim() );
- if ( numS == null )
- {
- p( "usage: putm numbertoput" );
- }
- else
- {
- putMultiple( num );
- }
- }
- else if ( message.startsWith( "pute" ) )
- {
- String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
- int num = Integer.parseInt( numS.trim() );
- if ( numS == null )
- {
- p( "usage: putme numbertoput" );
- }
- else
- {
- long n_start = System.currentTimeMillis();
- for ( int n = 0; n < num; n++ )
- {
- IElementAttributes attrp = cache_control.getDefaultElementAttributes();
- ElementEventHandlerMockImpl hand = new ElementEventHandlerMockImpl();
- attrp.addElementEventHandler( hand );
- cache_control.put( "key" + n, "data" + n + " put from ta = junk", attrp );
- }
- long n_end = System.currentTimeMillis();
- p( "---put " + num + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
- }
- }
- else if ( message.startsWith( "put" ) )
- {
- String key = null;
- String val = null;
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- key = t.trim();
- }
- else if ( tcnt == 3 )
- {
- val = t.trim();
- }
- }
+ if ( tcnt < 2 )
+ {
+ p( "usage: get key show values[true|false]" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ Object obj = cache_control.getFromGroup( key, group );
+ if ( show && obj != null )
+ {
+ p( obj.toString() );
+ }
+ }
+ catch ( Exception e )
+ {
+ log.error( e );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---got " + key + " from group " + group + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ }
- if ( tcnt < 3 )
- {
- p( "usage: put key val" );
- }
- else
- {
+ /**
+ * @param message
+ */
+ private void processGetAutoGroup( String message )
+ {
+ // get auto from group
- long n_start = System.currentTimeMillis();
- cache_control.put( key, val );
- long n_end = System.currentTimeMillis();
- p( "---put " + key + " | " + val + " in " + String.valueOf( n_end - n_start )
- + " millis ---" );
- }
- }
- if ( message.startsWith( "removem" ) )
- {
- String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
- int num = Integer.parseInt( numS.trim() );
- if ( numS == null )
- {
- p( "usage: removem numbertoremove" );
- }
- else
- {
- removeMultiple( num );
- }
- }
- else if ( message.startsWith( "removeall" ) )
- {
- cache_control.clear();
- p( "removed all" );
- }
- else if ( message.startsWith( "remove" ) )
- {
- String key = message.substring( message.indexOf( " " ) + 1, message.length() );
- cache_control.remove( key );
- p( "removed " + key );
- }
- else if ( message.startsWith( "deattr" ) )
- {
- IElementAttributes ae = cache_control.getDefaultElementAttributes();
- p( "Default IElementAttributes " + ae );
- }
- else if ( message.startsWith( "cloneattr" ) )
- {
- String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
- int num = Integer.parseInt( numS.trim() );
- if ( numS == null )
- {
- p( "usage: put numbertoput" );
- }
- else
- {
- IElementAttributes attrp = new ElementAttributes();
- long n_start = System.currentTimeMillis();
- for ( int n = 0; n < num; n++ )
- {
- attrp.copy();
- }
- long n_end = System.currentTimeMillis();
- p( "---cloned attr " + num + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
- }
- }
- else if ( message.startsWith( "switch" ) )
- {
- String name = message.substring( message.indexOf( " " ) + 1, message.length() );
+ int num = 0;
+ String group = null;
+ boolean show = true;
- setRegion( name );
- p( "switched to cache = " + name );
- p( cache_control.toString() );
- }
- else if ( message.startsWith( "stats" ) )
- {
- p( cache_control.getStats() );
- }
- else if ( message.startsWith( "gc" ) )
- {
- System.gc();
- p( "Called system.gc()" );
- }
- else if ( message.startsWith( "random" ) )
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ num = Integer.parseInt( t.trim() );
+ }
+ else if ( tcnt == 3 )
+ {
+ group = t.trim();
+ }
+ else if ( tcnt == 4 )
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if ( tcnt < 2 )
+ {
+ p( "usage: get key show values[true|false]" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ for ( int a = 0; a < num; a++ )
+ {
+ Object obj = cache_control.getFromGroup( "keygr" + a, group );
+ if ( show && obj != null )
{
- if ( message.startsWith( "random" ) )
- {
- String rangeS = "";
- String numOpsS = "";
- boolean show = true;
-
- StringTokenizer toke = new StringTokenizer( message );
- int tcnt = 0;
- while ( toke.hasMoreElements() )
- {
- tcnt++;
- String t = (String) toke.nextElement();
- if ( tcnt == 2 )
- {
- rangeS = t.trim();
- }
- else if ( tcnt == 3 )
- {
- numOpsS = t.trim();
- }
- else if ( tcnt == 4 )
- {
- show = new Boolean( t ).booleanValue();
- }
- }
-
- String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
-
- int range = 0;
- int numOps = 0;
- try
- {
- range = Integer.parseInt( rangeS.trim() );
- numOps = Integer.parseInt( numOpsS.trim() );
- }
- catch ( Exception e )
- {
- p( "usage: random range numOps show" );
- p( "ex. random 100 1000 false" );
- }
- if ( numS == null )
- {
- p( "usage: random range numOps show" );
- p( "ex. random 100 1000 false" );
- }
- else
- {
- random( range, numOps, show );
- }
- }
+ p( obj.toString() );
}
}
}
catch ( Exception e )
{
- p( e.toString() );
- e.printStackTrace( System.out );
+ log.error( e );
}
+ long n_end = System.currentTimeMillis();
+ p( "---got " + num + " from group " + group + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ }
+
+ /**
+ * @param message
+ * @throws CacheException
+ */
+ private void processPutGroup( String message )
+ throws CacheException
+ {
+ String group = null;
+ String key = null;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ key = t.trim();
+ }
+ else if ( tcnt == 3 )
+ {
+ group = t.trim();
+ }
+ }
+
+ if ( tcnt < 3 )
+ {
+ p( "usage: putg key group" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ cache_control.putInGroup( key, group, "data from putg ----asdfasfas-asfasfas-asfas in group " + group );
+ long n_end = System.currentTimeMillis();
+ p( "---put " + key + " in group " + group + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ }
+
+ /**
+ * @param message
+ * @throws CacheException
+ */
+ private void processPutAutoGroup( String message )
+ throws CacheException
+ {
+ String group = null;
+ int num = 0;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ num = Integer.parseInt( t.trim() );
+ }
+ else if ( tcnt == 3 )
+ {
+ group = t.trim();
+ }
+ }
+
+ if ( tcnt < 3 )
+ {
+ p( "usage: putag num group" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ for ( int a = 0; a < num; a++ )
+ {
+ cache_control.putInGroup( "keygr" + a, group, "data " + a
+ + " from putag ----asdfasfas-asfasfas-asfas in group " + group );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---put " + num + " in group " + group + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ }
+
+ /**
+ * @param message
+ * @throws CacheException
+ */
+ private void processPut( String message )
+ throws CacheException
+ {
+ String key = null;
+ String val = null;
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ key = t.trim();
+ }
+ else if ( tcnt == 3 )
+ {
+ val = t.trim();
+ }
+ }
+
+ if ( tcnt < 3 )
+ {
+ p( "usage: put key val" );
+ }
+ else
+ {
+
+ long n_start = System.currentTimeMillis();
+ cache_control.put( key, val );
+ long n_end = System.currentTimeMillis();
+ p( "---put " + key + " | " + val + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ }
+
+ /**
+ * @param message
+ */
+ private void processRandom( String message )
+ {
+ String rangeS = "";
+ String numOpsS = "";
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ rangeS = t.trim();
+ }
+ else if ( tcnt == 3 )
+ {
+ numOpsS = t.trim();
+ }
+ else if ( tcnt == 4 )
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ String numS = message.substring( message.indexOf( " " ) + 1, message.length() );
+
+ int range = 0;
+ int numOps = 0;
+ try
+ {
+ range = Integer.parseInt( rangeS.trim() );
+ numOps = Integer.parseInt( numOpsS.trim() );
}
catch ( Exception e )
{
- p( e.toString() );
- e.printStackTrace( System.out );
+ p( "usage: random range numOps show" );
+ p( "ex. random 100 1000 false" );
+ }
+ if ( numS == null )
+ {
+ p( "usage: random range numOps show" );
+ p( "ex. random 100 1000 false" );
+ }
+ else
+ {
+ random( range, numOps, show );
+ }
+ }
+
+ /**
+ * @param message
+ */
+ private void processGet( String message )
+ {
+ // plain old get
+
+ String key = null;
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ key = t.trim();
+ }
+ else if ( tcnt == 3 )
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if ( tcnt < 2 )
+ {
+ p( "usage: get key show values[true|false]" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ Object obj = cache_control.get( key );
+ if ( show && obj != null )
+ {
+ p( obj.toString() );
+ }
+ }
+ catch ( Exception e )
+ {
+ log.error( e );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---got " + key + " in " + String.valueOf( n_end - n_start ) + " millis ---" );
+ }
+ }
+
+ /**
+ * @param message
+ */
+ private void processGetMatching( String message )
+ {
+ // plain old get
+
+ String pattern = null;
+ boolean show = true;
+
+ StringTokenizer toke = new StringTokenizer( message );
+ int tcnt = 0;
+ while ( toke.hasMoreElements() )
+ {
+ tcnt++;
+ String t = (String) toke.nextElement();
+ if ( tcnt == 2 )
+ {
+ pattern = t.trim();
+ }
+ else if ( tcnt == 3 )
+ {
+ show = new Boolean( t ).booleanValue();
+ }
+ }
+
+ if ( tcnt < 2 )
+ {
+ p( "usage: getMatching key show values[true|false]" );
+ }
+ else
+ {
+ long n_start = System.currentTimeMillis();
+ try
+ {
+ Map results = cache_control.getMatching( pattern );
+ if ( show && results != null )
+ {
+ p( results.toString() );
+ }
+ }
+ catch ( Exception e )
+ {
+ log.error( e );
+ }
+ long n_end = System.currentTimeMillis();
+ p( "---gotMatching [" + pattern + "] in " + String.valueOf( n_end - n_start ) + " millis ---" );
}
}
/**
* Test harness.
- *
- * @param args
- * The command line arguments
+ * @param args The command line arguments
*/
public static void main( String[] args )
{
@@ -620,11 +725,8 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * Gets multiple items from the cache with keys of the form key1, key2, key3
- * up to key[num].
- *
- * @param num
- * int
+ * Gets multiple items from the cache with keys of the form key1, key2, key3 up to key[num].
+ * @param num int
*/
public void getMultiple( int num )
{
@@ -659,9 +761,7 @@
/**
* Puts multiple items into the cache.
- *
- * @param num
- * int
+ * @param num int
*/
public void putMultiple( int num )
{
@@ -683,9 +783,7 @@
/**
* Removes multiple items from the cache.
- *
- * @param num
- * int
+ * @param num int
*/
public void removeMultiple( int num )
{
@@ -706,14 +804,10 @@
}
/**
- * The random method performs numOps number of operations. The operations
- * will be a mix of puts, gets, and removes. The key range will be from 0 to
- * range.
- *
- * @param range
- * int The end of the key range.
- * @param numOps
- * int The number of operations to perform
+ * The random method performs numOps number of operations. The operations will be a mix of puts,
+ * gets, and removes. The key range will be from 0 to range.
+ * @param range int The end of the key range.
+ * @param numOps int The number of operations to perform
*/
public void random( int range, int numOps )
{
@@ -778,9 +872,7 @@
/**
* Sets the region to be used by test methods.
- *
- * @param name
- * String -- Name of region
+ * @param name String -- Name of region
*/
public void setRegion( String name )
{
@@ -798,12 +890,9 @@
/////////////////////////////////////////////////////////////////////////////
/**
- * The tester will print to the console if isSysOut is true, else it will
- * log. It is false by default. When run via the main method, isSysOut will
- * be set to true
- *
- * @param s
- * String to print or log
+ * The tester will print to the console if isSysOut is true, else it will log. It is false by
+ * default. When run via the main method, isSysOut will be set to true
+ * @param s String to print or log
*/
public static void p( String s )
{
@@ -832,6 +921,7 @@
p( "type 'removeall' to remove all items in a region" );
p( "type 'remove key' to remove" );
p( "type 'removem num' to remove a number automatically" );
+ p( "type 'getMatching pattern show' to getMatching" );
p( "type 'get key show' to get" );
p( "type 'getg key group show' to get" );
p( "type 'getag num group show' to get automatically from a group" );
@@ -851,7 +941,6 @@
/**
* Gets the attributeNames attribute of the TestCacheAccess class
- *
* @param groupName
*/
public void getAttributeNames( String groupName )
@@ -863,5 +952,4 @@
p( "=" + (String) iter.next() );
}
}
-
-} // end class
+}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/MockAuxiliaryCache.java Fri Nov 14 14:50:12 2008
@@ -28,8 +28,6 @@
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.behavior.IElementSerializer;
-import org.apache.jcs.engine.logging.behavior.ICacheEventLogger;
import org.apache.jcs.engine.stats.behavior.IStats;
/**
@@ -38,7 +36,7 @@
* @author Aaron Smuts
*/
public class MockAuxiliaryCache
- implements AuxiliaryCache
+ extends AbstractAuxiliaryCache
{
/** Don't change */
private static final long serialVersionUID = 1L;
@@ -49,15 +47,9 @@
/** Can setup status */
public int status = CacheConstants.STATUS_ALIVE;
- /** The event logger */
- public ICacheEventLogger cacheEventLogger;
-
- /** IElementSerializer elementSerializer */
- public IElementSerializer elementSerializer;
-
/** Times getMatching was Called */
public int getMatchingCallCount = 0;
-
+
/**
* @param ce
* @throws IOException
@@ -92,7 +84,7 @@
getMatchingCallCount++;
return new HashMap();
}
-
+
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
@@ -146,13 +138,12 @@
return 0;
}
- /*
- * (non-Javadoc)
- * @see org.apache.jcs.auxiliary.AuxiliaryCache#getStatus()
+ /**
+ * @return int
+ *
*/
public int getStatus()
{
- // TODO Auto-generated method stub
return status;
}
@@ -162,7 +153,6 @@
*/
public String getCacheName()
{
- // TODO Auto-generated method stub
return null;
}
@@ -173,7 +163,6 @@
public Set getGroupKeys( String group )
throws IOException
{
- // TODO Auto-generated method stub
return null;
}
@@ -183,7 +172,6 @@
*/
public IStats getStatistics()
{
- // TODO Auto-generated method stub
return null;
}
@@ -193,7 +181,6 @@
*/
public String getStats()
{
- // TODO Auto-generated method stub
return null;
}
@@ -214,19 +201,9 @@
return null;
}
- /**
- * @param cacheEventLogger
- */
- public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
- {
- this.cacheEventLogger = cacheEventLogger;
- }
-
- /**
- * @param elementSerializer
- */
- public void setElementSerializer( IElementSerializer elementSerializer )
+ /** @return null */
+ public String getEventLoggingExtraInfo()
{
- this.elementSerializer = elementSerializer;
+ return null;
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheUnitTest.java Fri Nov 14 14:50:12 2008
@@ -39,8 +39,8 @@
// VERIFY
assertEquals( "Wrong number returned", 10, matchingResults.size() );
- System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
- System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
+ //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
+ //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
}
/**
@@ -71,7 +71,7 @@
// VERIFY
assertEquals( "Wrong number returned", 10, matchingResults.size() );
- System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
- System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
+ //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
+ //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptorUnitTest.java Fri Nov 14 14:50:12 2008
@@ -29,7 +29,6 @@
public class BlockDiskElementDescriptorUnitTest
extends TestCase
{
-
/**
* Verify that the memory used per element is reasonable.
* <p>
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java Fri Nov 14 14:50:12 2008
@@ -89,8 +89,7 @@
assertNotNull( "element " + i + ":key is missing", element );
assertEquals( "value key:" + i, "data:" + i, element.getVal() );
}
-
- System.out.println( disk.getStats() );
+ //System.out.println( disk.getStats() );
}
/**
@@ -743,8 +742,8 @@
// VERIFY
assertEquals( "Wrong number returned", 10, matchingResults.size() );
- System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
- System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
+ //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
+ //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
}
/**
@@ -775,7 +774,7 @@
// VERIFY
assertEquals( "Wrong number returned", 10, matchingResults.size() );
- System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
- System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
+ //System.out.println( "matchingResults.keySet() " + matchingResults.keySet() );
+ //System.out.println( "\nAFTER TEST \n" + diskCache.getStats() );
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheDefragPerformanceTest.java Fri Nov 14 14:50:12 2008
@@ -36,14 +36,19 @@
/** For readability */
private static final String LOG_DIVIDER = "---------------------------";
+ /** total to test with */
private static final int TOTAL_ELEMENTS = 30000;
+ /** time to wait */
private static final long SLEEP_TIME_DISK = 8000;
+ /** how often to log */
private static final int LOG_INCREMENT = 5000;
+ /** for getting memory usage */
private static Runtime rt = Runtime.getRuntime();
+ /** for displaying memory usage */
private static DecimalFormat format = new DecimalFormat( "#,###" );
/**
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPConcurrentRandomTestUtil.java Fri Nov 14 14:50:12 2008
@@ -28,12 +28,12 @@
import org.apache.jcs.engine.behavior.ICacheElement;
/**
- * @author asmuts
+ * @author Aaron Smuts
*/
public class LateralTCPConcurrentRandomTestUtil
extends TestCase
{
-
+ /** Should we write out. */
private static boolean isSysOut = false;
//private static boolean isSysOut = true;
@@ -190,12 +190,5 @@
{
System.out.println( s );
}
- else
- {
- //if ( log.isInfoEnabled() )
- //{
- // log.info( s );
- //}
- }
}
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/LateralTCPFilterRemoveHashCodeUnitTest.java Fri Nov 14 14:50:12 2008
@@ -28,7 +28,7 @@
import org.apache.jcs.engine.behavior.ICacheElement;
/**
- * @author asmuts
+ * @author Aaron Smuts
*/
public class LateralTCPFilterRemoveHashCodeUnitTest
extends TestCase
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/TestTCPLateralUnitTest.java Fri Nov 14 14:50:12 2008
@@ -19,6 +19,8 @@
* under the License.
*/
+import java.util.Map;
+
import junit.framework.TestCase;
import org.apache.jcs.JCS;
@@ -33,14 +35,12 @@
/**
* Basic unit tests for the sending and receiving portions of the lateral cache.
- *
+ * <p>
* @author Aaron Smuts
- *
*/
public class TestTCPLateralUnitTest
extends TestCase
{
-
/**
* Test setup
*/
@@ -50,16 +50,16 @@
}
/**
- * Make sure we can send a bunch to the listener. This would be better if we
- * could plugin a Mock CacheManger. The listener will instantiate on on its
- * own. We have to configure one before that.
+ * Make sure we can send a bunch to the listener. This would be better if we could plugin a Mock
+ * CacheManger. The listener will instantiate it on its own. We have to configure one before
+ * that.
* <p>
* @throws Exception
*/
public void testSimpleSend()
throws Exception
{
-
+ // SETUP
// force initialization
JCS.getInstance( "test" );
@@ -76,6 +76,7 @@
// send to the listener
LateralTCPSender lur = new LateralTCPSender( lac );
+ // DO WORK
int numMes = 10;
for ( int i = 0; i < numMes; i++ )
{
@@ -89,35 +90,24 @@
SleepUtil.sleepAtLeast( numMes * 3 );
+ // VERIFY
System.out.println( "PutCount = " + listener.getPutCnt() );
assertEquals( "Should have received " + numMes + " by now.", numMes, listener.getPutCnt() );
-
}
/**
- *
* @throws Exception
*/
public void testReceive()
throws Exception
{
+ // VERIFY
TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
lattr.setTcpListenerPort( 1101 );
lattr.setTransmissionTypeName( "TCP" );
MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
System.out.println( "mock cache = " + cacheMgr.getCache( "test" ) );
- // force initialization
- //LateralTCPCacheFactory fact = new LateralTCPCacheFactory();
- //.getInstance( lattr, cacheMgr );
- //LateralCacheNoWait nwait1 = (LateralCacheNoWait)lcMgr1.getCache(
- // "test" );
- //AuxiliaryCache nowait1 = fact.createCache( lattr, cacheMgr );
-
- //nowait1.update( );
-
- // start the listener
- //LateralTCPListener listener = (LateralTCPListener)
LateralTCPListener.getInstance( lattr, cacheMgr );
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
@@ -128,6 +118,7 @@
LateralTCPService service = new LateralTCPService( lattr2 );
service.setListenerId( 123456 );
+ // DO WORK
int cnt = 100;
for ( int i = 0; i < cnt; i++ )
{
@@ -137,18 +128,20 @@
SleepUtil.sleepAtLeast( 1000 );
+ // VERIFY
System.out.println( "cache. getPutCount = " + cacheMgr.getCache().getUpdateCount() );
-
assertEquals( "Didn't get the correct number", cnt, cacheMgr.getCache().getUpdateCount() );
}
/**
* Send objects with the same key but different values.
+ * <p>
* @throws Exception
*/
public void testSameKeyDifferentObject()
throws Exception
{
+ // SETUP
// setup a listener
TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
lattr.setTcpListenerPort( 1103 );
@@ -168,6 +161,7 @@
LateralTCPService service = new LateralTCPService( lattr2 );
service.setListenerId( 123456 );
+ // DO WORK
ICacheElement element = new CacheElement( "test", "key", "value1" );
service.update( element );
@@ -176,16 +170,17 @@
ICacheElement element2 = new CacheElement( "test", "key", "value2" );
service.update( element2 );
- SleepUtil.sleepAtLeast( 1000 );
+ SleepUtil.sleepAtLeast( 1000 );
+ // VERIFY
ICacheElement cacheElement = cacheMgr.getCache().get( "key" );
System.out.println( "cacheElement = " + cacheElement );
assertEquals( "Didn't get the correct object", element2.getVal(), cacheElement.getVal() );
}
-
/**
* Send objects with the same key but different values.
+ * <p>
* @throws Exception
*/
public void testSameKeyObjectDifferentValueObject()
@@ -203,13 +198,14 @@
LateralTCPListener.getInstance( lattr, cacheMgr );
TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
- lattr2.setTcpListenerPort( 1106);
+ lattr2.setTcpListenerPort( 1106 );
lattr2.setTransmissionTypeName( "TCP" );
lattr2.setTcpServer( "localhost:1105" );
LateralTCPService service = new LateralTCPService( lattr2 );
service.setListenerId( 123456 );
+ // DO WORK
String key = "key";
ICacheElement element = new CacheElement( "test", key, "value1" );
service.update( element );
@@ -221,19 +217,22 @@
SleepUtil.sleepAtLeast( 1000 );
+ // VERIFY
ICacheElement cacheElement = cacheMgr.getCache().get( "key" );
System.out.println( "cacheElement = " + cacheElement );
assertEquals( "Didn't get the correct object", element2.getVal(), cacheElement.getVal() );
}
/**
- * Create a listener. Add an element to the listeners cache. Setup a service. Try to get from the service.
+ * Create a listener. Add an element to the listeners cache. Setup a service. Try to get from
+ * the service.
* <p>
* @throws Exception
*/
- public void testSendAndReceived()
+ public void testGet_SendAndReceived()
throws Exception
{
+ // SETUP
// setup a listener
TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
lattr.setTcpListenerPort( 1107 );
@@ -242,7 +241,6 @@
// get the listener started
// give it our mock cache manager
- //LateralTCPListener listener = (LateralTCPListener)
LateralTCPListener.getInstance( lattr, cacheMgr );
// add the item to the listeners cache
@@ -257,13 +255,63 @@
LateralTCPService service = new LateralTCPService( lattr2 );
service.setListenerId( 123456 );
- SleepUtil.sleepAtLeast( 300 );
+ SleepUtil.sleepAtLeast( 300 );
// DO WORK
ICacheElement result = service.get( "test", "key" );
+ // VERIFY
System.out.println( "testSendAndReceived, result = " + result );
assertNotNull( "Result should not be null.", result );
assertEquals( "Didn't get the correct object", element.getVal(), result.getVal() );
}
+
+ /**
+ * Create a listener. Add an element to the listeners cache. Setup a service. Try to get from
+ * the service.
+ * <p>
+ * @throws Exception
+ */
+ public void testGetMatching_WithData()
+ throws Exception
+ {
+ // SETUP
+ // setup a listener
+ TCPLateralCacheAttributes lattr = new TCPLateralCacheAttributes();
+ lattr.setTcpListenerPort( 1108 );
+ MockCompositeCacheManager cacheMgr = new MockCompositeCacheManager();
+ System.out.println( "mock cache = " + cacheMgr.getCache( "test" ) );
+
+ // get the listener started
+ // give it our mock cache manager
+ LateralTCPListener.getInstance( lattr, cacheMgr );
+
+ String keyprefix1 = "MyPrefix1";
+ int numToInsertPrefix1 = 10;
+ // insert with prefix1
+ for ( int i = 0; i < numToInsertPrefix1; i++ )
+ {
+ // add the item to the listeners cache
+ ICacheElement element = new CacheElement( "test", keyprefix1 + String.valueOf( i ), new Integer( i ) );
+ cacheMgr.getCache().update( element );
+ }
+
+ // setup a service to talk to the listener started above.
+ TCPLateralCacheAttributes lattr2 = new TCPLateralCacheAttributes();
+ lattr2.setTcpListenerPort( 1108 );
+ lattr2.setTcpServer( "localhost:1108" );
+
+ LateralTCPService service = new LateralTCPService( lattr2 );
+ service.setListenerId( 123456 );
+
+ SleepUtil.sleepAtLeast( 300 );
+
+ // DO WORK
+ Map result = service.getMatching( "test", keyprefix1 + ".+" );
+
+ // VERIFY
+ System.out.println( "testSendAndReceived, result = " + result );
+ assertNotNull( "Result should not be null.", result );
+ assertEquals( "Wrong number returned 1:", numToInsertPrefix1, result.size() );
+ }
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/lateral/socket/tcp/discovery/MockLateralCache.java?rev=714178&r1=714177&r2=714178&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 Nov 14 14:50:12 2008
@@ -47,113 +47,82 @@
/**
* Nothing.
+ * @param ce
+ * @throws IOException
*/
protected void processUpdate( ICacheElement ce )
throws IOException
{
- // TODO Auto-generated method stub
-
+ // nothing
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#get(java.io.Serializable)
+ /**
+ * @param key
+ * @return ICacheElement
+ * @throws IOException
*/
protected ICacheElement processGet( Serializable key )
throws IOException
{
- // TODO Auto-generated method stub
return null;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#remove(java.io.Serializable)
+ /**
+ * @param key
+ * @return false
+ * @throws IOException
*/
protected boolean processRemove( Serializable key )
throws IOException
{
- // TODO Auto-generated method stub
return false;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#removeAll()
+ /**
+ * @throws IOException
*/
public void processRemoveAll()
throws IOException
{
- // TODO Auto-generated method stub
-
+ //nothing
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#dispose()
+ /**
+ * @throws IOException
*/
public void processDispose()
throws IOException
{
- // TODO Auto-generated method stub
-
+ // nothing
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#getSize()
- */
+ /** @return 0 */
public int getSize()
{
- // TODO Auto-generated method stub
return 0;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#getStatus()
- */
+ /** @return 0 */
public int getStatus()
{
- // TODO Auto-generated method stub
return 0;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#getStats()
- */
+ /** @return String */
public String getStats()
{
- // TODO Auto-generated method stub
return null;
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICache#getCacheName()
- */
+ /** @return String */
public String getCacheName()
{
return super.getCacheName();
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.jcs.engine.behavior.ICacheType#getCacheType()
- */
+ /** @return type */
public int getCacheType()
{
return super.getCacheType();
}
-
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/MockRemoteCacheClient.java Fri Nov 14 14:50:12 2008
@@ -29,6 +29,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.jcs.auxiliary.AbstractAuxiliaryCache;
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheClient;
import org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheListener;
@@ -45,6 +46,7 @@
* @author Aaron Smuts
*/
public class MockRemoteCacheClient
+ extends AbstractAuxiliaryCache
implements IRemoteCacheClient
{
/** For serialization. Don't change. */
@@ -241,16 +243,6 @@
return 0;
}
- public void setCacheEventLogger( ICacheEventLogger cacheEventLogger )
- {
- // TODO Auto-generated method stub
- }
-
- public void setElementSerializer( IElementSerializer elementSerializer )
- {
- // TODO Auto-generated method stub
- }
-
/**
* @param pattern
* @return Map
@@ -261,4 +253,14 @@
{
return new HashMap();
}
+
+ /**
+ * Nothing important
+ * <p>
+ * @return null
+ */
+ public String getEventLoggingExtraInfo()
+ {
+ return null;
+ }
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/TestRemoteCache.java?rev=714178&r1=714177&r2=714178&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 Fri Nov 14 14:50:12 2008
@@ -33,17 +33,16 @@
import org.apache.jcs.engine.control.MockElementSerializer;
/**
- * @author asmuts
+ * @author Aaron SMuts
*/
public class TestRemoteCache
extends TestCase
{
-
+ /** The logger */
private final static Log log = LogFactory.getLog( TestRemoteCache.class );
/**
- *
- *
+ * Start the cache.
*/
public TestRemoteCache()
{
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/remote/server/RemoteCacheServerFactoryUnitTest.java Fri Nov 14 14:50:12 2008
@@ -12,6 +12,36 @@
extends TestCase
{
/** verify that we get the timeout value */
+ public void testConfigureRemoteCacheServerAttributes_eventQueueType()
+ {
+ // SETUP
+ String eventQueueType = "my.special.type";
+ Properties props = new Properties();
+ props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".EventQueueType", eventQueueType );
+
+ // DO WORK
+ RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
+
+ // VERIFY
+ assertEquals( "Wrong EventQueueType", eventQueueType, result.getEventQueueType() );
+ }
+
+ /** verify that we get the timeout value */
+ public void testConfigureRemoteCacheServerAttributes_eventQueuePoolName()
+ {
+ // SETUP
+ String eventQueuePoolName = "specialName";
+ Properties props = new Properties();
+ props.put( IRemoteCacheConstants.CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX + ".EventQueuePoolName", eventQueuePoolName );
+
+ // DO WORK
+ RemoteCacheServerAttributes result = RemoteCacheServerFactory.configureRemoteCacheServerAttributes( props );
+
+ // VERIFY
+ assertEquals( "Wrong eventQueuePoolName", eventQueuePoolName, result.getEventQueuePoolName() );
+ }
+
+ /** verify that we get the timeout value */
public void testConfigureRemoteCacheServerAttributes_timeoutPresent()
{
// SETUP
@@ -24,7 +54,7 @@
// VERIFY
assertEquals( "Wrong timeout", timeout, result.getRmiSocketFactoryTimeoutMillis() );
- }
+ }
/** verify that we get the timeout value */
public void testConfigureRemoteCacheServerAttributes_timeoutNotPresent()
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheConfiguratorUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheConfiguratorUnitTest.java?rev=714178&r1=714177&r2=714178&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheConfiguratorUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheConfiguratorUnitTest.java Fri Nov 14 14:50:12 2008
@@ -49,7 +49,7 @@
// VERIFY
assertNotNull( "Should have an auxcache.", result );
- assertNotNull( "Should have an event logger.", result.cacheEventLogger );
+ assertNotNull( "Should have an event logger.", result.getCacheEventLogger() );
}
/**