You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2008/10/24 23:56:07 UTC

svn commit: r707758 [2/2] - in /jakarta/jcs/trunk/src: java/org/apache/jcs/access/ java/org/apache/jcs/access/behavior/ java/org/apache/jcs/auxiliary/ java/org/apache/jcs/auxiliary/disk/ java/org/apache/jcs/auxiliary/disk/block/ java/org/apache/jcs/aux...

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/CompositeCacheUnitTest.java Fri Oct 24 14:56:06 2008
@@ -20,6 +20,7 @@
  */
 
 import java.io.IOException;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
@@ -119,4 +120,120 @@
         MockMemoryCache memoryCache = (MockMemoryCache) cache.getMemoryCache();
         assertEquals( "Wrong number freed.", 0, memoryCache.lastNumberOfFreedElements );
     }
+
+    /**
+     * Verify we can get some matching elements..
+     * <p>
+     * @throws IOException
+     */
+    public void testGetMatching_Normal()
+        throws IOException
+    {
+        // SETUP
+        int maxMemorySize = 1000;
+        String keyprefix1 = "MyPrefix1";
+        String keyprefix2 = "MyPrefix2";
+        String cacheName = "testGetMatching_Normal";
+        String memoryCacheClassName = "org.apache.jcs.engine.memory.lru.LRUMemoryCache";
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setMemoryCacheName( memoryCacheClassName );
+        cattr.setMaxObjects( maxMemorySize );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( cacheName, cattr, attr );
+
+        MockAuxiliaryCache diskMock = new MockAuxiliaryCache();
+        diskMock.cacheType = ICache.DISK_CACHE;
+        AuxiliaryCache[] aux = new AuxiliaryCache[] { diskMock };
+        cache.setAuxCaches( aux );
+
+        // DO WORK
+        int numToInsertPrefix1 = 10;
+        // insert with prefix1
+        for ( int i = 0; i < numToInsertPrefix1; i++ )
+        {
+            ICacheElement element = new CacheElement( cacheName, keyprefix1 + String.valueOf( i ), new Integer( i ) );
+            cache.update( element, false );
+        }
+
+        int numToInsertPrefix2 = 50;
+        // insert with prefix1
+        for ( int i = 0; i < numToInsertPrefix2; i++ )
+        {
+            ICacheElement element = new CacheElement( cacheName, keyprefix2 + String.valueOf( i ), new Integer( i ) );
+            cache.update( element, false );
+        }
+
+        Map result1 = cache.getMatching( keyprefix1 + "\\S+" );
+        Map result2 = cache.getMatching( keyprefix2 + "\\S+" );
+
+        // VERIFY
+        assertEquals( "Wrong number returned 1:", numToInsertPrefix1, result1.size() );
+        assertEquals( "Wrong number returned 2:", numToInsertPrefix2, result2.size() );
+    }
+    
+    /**
+     * Verify we try a disk aux on a getMatching call.
+     * <p>
+     * @throws IOException
+     */
+    public void testGetMatching_NotOnDisk()
+        throws IOException
+    {
+        // SETUP
+        int maxMemorySize = 0;
+        String cacheName = "testGetMatching_NotOnDisk";
+        String memoryCacheClassName = "org.apache.jcs.engine.memory.lru.LRUMemoryCache";
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setMemoryCacheName( memoryCacheClassName );
+        cattr.setMaxObjects( maxMemorySize );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( cacheName, cattr, attr );
+
+        MockAuxiliaryCache diskMock = new MockAuxiliaryCache();
+        diskMock.cacheType = ICache.DISK_CACHE;
+        AuxiliaryCache[] aux = new AuxiliaryCache[] { diskMock };
+        cache.setAuxCaches( aux );
+
+        // DO WORK
+        cache.getMatching( "junk" );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls", 1, diskMock.getMatchingCallCount );
+    }
+    
+    /**
+     * Verify we try a remote  aux on a getMatching call.
+     * <p>
+     * @throws IOException
+     */
+    public void testGetMatching_NotOnRemote()
+        throws IOException
+    {
+        // SETUP
+        int maxMemorySize = 0;
+        String cacheName = "testGetMatching_NotOnDisk";
+        String memoryCacheClassName = "org.apache.jcs.engine.memory.lru.LRUMemoryCache";
+        ICompositeCacheAttributes cattr = new CompositeCacheAttributes();
+        cattr.setMemoryCacheName( memoryCacheClassName );
+        cattr.setMaxObjects( maxMemorySize );
+
+        IElementAttributes attr = new ElementAttributes();
+
+        CompositeCache cache = new CompositeCache( cacheName, cattr, attr );
+
+        MockAuxiliaryCache diskMock = new MockAuxiliaryCache();
+        diskMock.cacheType = ICache.REMOTE_CACHE;
+        AuxiliaryCache[] aux = new AuxiliaryCache[] { diskMock };
+        cache.setAuxCaches( aux );
+
+        // DO WORK
+        cache.getMatching( "junk" );
+
+        // VERIFY
+        assertEquals( "Wrong number of calls", 1, diskMock.getMatchingCallCount );
+    }
 }

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/ElementEventHandlerMockImpl.java Fri Oct 24 14:56:06 2008
@@ -21,50 +21,42 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-
 import org.apache.jcs.engine.control.event.behavior.IElementEvent;
 import org.apache.jcs.engine.control.event.behavior.IElementEventConstants;
 import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
 
 /**
- *
  * @author aaronsm
- *
  */
 public class ElementEventHandlerMockImpl
     implements IElementEventHandler
 {
-
-    /**
-     * Times called.
-     */
+    /** Times called. */
     private int callCount = 0;
 
+    /** The logger */
     private final static Log log = LogFactory.getLog( ElementEventHandlerMockImpl.class );
 
-    // ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE
+    /** ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE */
     private int spoolCount = 0;
 
-    // ELEMENT_EVENT_SPOOLED_NOT_ALLOWED
+    /** ELEMENT_EVENT_SPOOLED_NOT_ALLOWED */
     private int spoolNotAllowedCount = 0;
 
-    // ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE
+    /** ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE */
     private int spoolNoDiskCount = 0;
 
-    // ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND
+    /** ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND */
     private int exceededMaxLifeBackgroundCount = 0;
 
-    // ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND
+    /** ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND */
     private int exceededIdleTimeBackgroundCount = 0;
 
-    /*
-     * (non-Javadoc)
-     *
-     * @see org.apache.jcs.engine.control.event.behavior.IElementEventHandler#handleElementEvent(org.apache.jcs.engine.control.event.behavior.IElementEvent)
+    /**
+     * @param event
      */
     public synchronized void handleElementEvent( IElementEvent event )
     {
-
         setCallCount( getCallCount() + 1 );
 
         if ( log.isDebugEnabled() )
@@ -96,8 +88,7 @@
     }
 
     /**
-     * @param spoolCount
-     *            The spoolCount to set.
+     * @param spoolCount The spoolCount to set.
      */
     public void setSpoolCount( int spoolCount )
     {
@@ -113,8 +104,7 @@
     }
 
     /**
-     * @param spoolNotAllowedCount
-     *            The spoolNotAllowedCount to set.
+     * @param spoolNotAllowedCount The spoolNotAllowedCount to set.
      */
     public void setSpoolNotAllowedCount( int spoolNotAllowedCount )
     {
@@ -130,8 +120,7 @@
     }
 
     /**
-     * @param spoolNoDiskCount
-     *            The spoolNoDiskCount to set.
+     * @param spoolNoDiskCount The spoolNoDiskCount to set.
      */
     public void setSpoolNoDiskCount( int spoolNoDiskCount )
     {

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/control/event/SimpleEventHandlingUnitTest.java Fri Oct 24 14:56:06 2008
@@ -19,9 +19,7 @@
  * under the License.
  */
 
-import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestSuite;
 
 import org.apache.jcs.JCS;
 import org.apache.jcs.engine.behavior.IElementAttributes;
@@ -30,55 +28,16 @@
 import org.apache.jcs.engine.control.event.behavior.IElementEventHandler;
 
 /**
- * This test suite verifies that the basic ElementEvent are called as they
- * should be.
- *
- *
- * @version $Id: TestSimpleEventHandling.java,v 1.1 2005/02/01 00:01:59 asmuts
- *          Exp $
+ * This test suite verifies that the basic ElementEvent are called as they should be.
  */
 public class SimpleEventHandlingUnitTest
     extends TestCase
 {
-
+    /** Items to test with */
     private static int items = 20000;
 
     /**
-     * Constructor for test case.
-     *
-     * @param testName
-     *            Description of the Parameter
-     */
-    public SimpleEventHandlingUnitTest( String testName )
-    {
-        super( testName );
-    }
-
-    /**
-     * Run at command line.
-     *
-     * @param args
-     *            Description of the Parameter
-     */
-    public static void main( String args[] )
-    {
-        String[] testCaseName = { SimpleEventHandlingUnitTest.class.getName() };
-        junit.textui.TestRunner.main( testCaseName );
-    }
-
-    /**
-     * A unit test suite for JUnit
-     *
-     * @return The test suite
-     */
-    public static Test suite()
-    {
-        return new TestSuite( SimpleEventHandlingUnitTest.class );
-    }
-
-    /**
      * Test setup with expected configuration parameters.
-     *
      */
     public void setUp()
     {
@@ -87,14 +46,13 @@
 
     /**
      * Verify that the spooled event is called as expected.
-     *
-     *
-     * @exception Exception
-     *                Description of the Exception
+     * <p>
+     * @exception Exception Description of the Exception
      */
     public void testSpoolEvent()
         throws Exception
     {
+        // SETUP
         MyEventHandler meh = new MyEventHandler();
 
         JCS jcs = JCS.getInstance( "WithDisk" );
@@ -103,6 +61,7 @@
         attributes.addElementEventHandler( meh );
         jcs.setDefaultElementAttributes( attributes );
 
+        // DO WORK
         // put them in
         for ( int i = 0; i <= items; i++ )
         {
@@ -112,15 +71,15 @@
         // wait a bit for it to finish
         Thread.sleep( items / 20 );
 
+        // VERIFY
         // test to see if the count is right
         assertTrue( "The number of ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE events [" + meh.getSpoolCount()
             + "] does not equal the number expected [" + items + "]", meh.getSpoolCount() >= items );
-
     }
 
     /**
      * Test overflow with no disk configured for the region.
-     *
+     * <p>
      * @throws Exception
      */
     public void testSpoolNoDiskEvent()
@@ -152,7 +111,6 @@
 
     /**
      * Test the ELEMENT_EVENT_SPOOLED_NOT_ALLOWED event.
-     *
      * @throws Exception
      */
     public void testSpoolNotAllowedEvent()
@@ -181,10 +139,8 @@
 
     }
 
-
     /**
      * Test the ELEMENT_EVENT_SPOOLED_NOT_ALLOWED event.
-     *
      * @throws Exception
      */
     public void testSpoolNotAllowedEventOnItem()
@@ -214,26 +170,24 @@
             + "] does not equal the number expected.", meh.getSpoolNotAllowedCount() >= items );
 
     }
+
     /**
      * Simple event counter used to verify test results.
-     *
-     * @author aaronsm
-     *
      */
     public class MyEventHandler
         implements IElementEventHandler
     {
-
+        /** times spool called */
         private int spoolCount = 0;
 
+        /** times spool not allowed */
         private int spoolNotAllowedCount = 0;
 
+        /** times spool without disk */
         private int spoolNoDiskCount = 0;
 
-        /*
-         * (non-Javadoc)
-         *
-         * @see org.apache.jcs.engine.control.event.behavior.IElementEventHandler#handleElementEvent(org.apache.jcs.engine.control.event.behavior.IElementEvent)
+        /**
+         * @param event
          */
         public synchronized void handleElementEvent( IElementEvent event )
         {
@@ -257,8 +211,7 @@
         }
 
         /**
-         * @param spoolCount
-         *            The spoolCount to set.
+         * @param spoolCount The spoolCount to set.
          */
         protected void setSpoolCount( int spoolCount )
         {
@@ -274,8 +227,7 @@
         }
 
         /**
-         * @param spoolNotAllowedCount
-         *            The spoolNotAllowedCount to set.
+         * @param spoolNotAllowedCount The spoolNotAllowedCount to set.
          */
         protected void setSpoolNotAllowedCount( int spoolNotAllowedCount )
         {
@@ -291,8 +243,7 @@
         }
 
         /**
-         * @param spoolNoDiskCount
-         *            The spoolNoDiskCount to set.
+         * @param spoolNoDiskCount The spoolNoDiskCount to set.
          */
         protected void setSpoolNoDiskCount( int spoolNoDiskCount )
         {

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/engine/memory/MockMemoryCache.java Fri Oct 24 14:56:06 2008
@@ -40,18 +40,16 @@
 public class MockMemoryCache
     implements MemoryCache
 {
+    /** Config */
     private ICompositeCacheAttributes cacheAttr;
 
+    /** Internal map */
     private HashMap map = new HashMap();
 
-    /**
-     * The number of times waterfall was called.
-     */
+    /** The number of times waterfall was called.   */
     public int waterfallCallCount = 0;
 
-    /**
-     * The number passed to the last call of free elements.
-     */
+    /** The number passed to the last call of free elements.   */
     public int lastNumberOfFreedElements = 0;
 
     public void initialize( CompositeCache cache )

Added: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/match/KeyMatcherUtilUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/match/KeyMatcherUtilUnitTest.java?rev=707758&view=auto
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/match/KeyMatcherUtilUnitTest.java (added)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/match/KeyMatcherUtilUnitTest.java Fri Oct 24 14:56:06 2008
@@ -0,0 +1,95 @@
+package org.apache.jcs.utils.match;
+
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+/** Unit tests for the key matcher. */
+public class KeyMatcherUtilUnitTest
+    extends TestCase
+{
+    /**
+     * Verify that the matching method works.
+     */
+    public void testGetMatchingKeysFromArray_AllMatch()
+    {
+        // SETUP
+        int numToInsertPrefix1 = 10;
+        int araySize = numToInsertPrefix1;
+        Object[] keyArray = new Object[araySize];
+
+        String keyprefix1 = "MyPrefixC";
+
+        // insert with prefix1
+        for ( int i = 0; i < numToInsertPrefix1; i++ )
+        {
+            keyArray[i] = keyprefix1 + String.valueOf( i );
+        }
+
+        // DO WORK
+        Set result1 = KeyMatcherUtil.getMatchingKeysFromArray( keyprefix1 + ".", keyArray );
+
+        // VERIFY
+        assertEquals( "Wrong number returned 1: " + result1, numToInsertPrefix1, result1.size() );
+    }
+
+    /**
+     * Verify that the matching method works.
+     */
+    public void testGetMatchingKeysFromArray_AllMatchFirstNull()
+    {
+        // SETUP
+        int numToInsertPrefix1 = 10;
+        int araySize = numToInsertPrefix1 + 1;
+        Object[] keyArray = new Object[araySize];
+
+        String keyprefix1 = "MyPrefixC";
+
+        // insert with prefix1
+        for ( int i = 1; i < numToInsertPrefix1 + 1; i++ )
+        {
+            keyArray[i] = keyprefix1 + String.valueOf( i );
+        }
+
+        // DO WORK
+        Set result1 = KeyMatcherUtil.getMatchingKeysFromArray( keyprefix1 + "\\S+", keyArray );
+
+        // VERIFY
+        assertEquals( "Wrong number returned 1: " + result1, numToInsertPrefix1, result1.size() );
+    }
+
+    /**
+     * Verify that the matching method works.
+     */
+    public void testGetMathcingKeysFromArray_TwoTypes()
+    {
+        // SETUP
+        int numToInsertPrefix1 = 10;
+        int numToInsertPrefix2 = 50;
+        int araySize = numToInsertPrefix1 + numToInsertPrefix2;
+        Object[] keyArray = new Object[araySize];
+
+        String keyprefix1 = "MyPrefixA";
+        String keyprefix2 = "MyPrefixB";
+
+        // insert with prefix1
+        for ( int i = 0; i < numToInsertPrefix1; i++ )
+        {
+            keyArray[i] = keyprefix1 + String.valueOf( i );
+        }
+
+        // insert with prefix2
+        for ( int i = numToInsertPrefix1; i < numToInsertPrefix2 + numToInsertPrefix1; i++ )
+        {
+            keyArray[i] = keyprefix2 + String.valueOf( i );
+        }
+
+        // DO WORK
+        Set result1 = KeyMatcherUtil.getMatchingKeysFromArray( keyprefix1 + ".+", keyArray );
+        Set result2 = KeyMatcherUtil.getMatchingKeysFromArray( keyprefix2 + ".+", keyArray );
+
+        // VERIFY
+        assertEquals( "Wrong number returned 1: " + result1, numToInsertPrefix1, result1.size() );
+        assertEquals( "Wrong number returned 2: " + result2, numToInsertPrefix2, result2.size() );
+    }
+}

Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java?rev=707758&r1=707757&r2=707758&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java (original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java Fri Oct 24 14:56:06 2008
@@ -28,27 +28,28 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.jcs.JCSvsHashtablePerformanceTest;
-import org.apache.jcs.utils.struct.LRUMap;
 
 /**
  * This ensures that the jcs version of the LRU map is as fast as the commons
  * version. It has been testing at .6 to .7 times the commons LRU.
  *
- * @author aaronsm
- *
  */
 public class JCSvsCommonsLRUMapPerformanceTest
     extends TestCase
 {
-
+    /** jcs / commons */
     float ratioPut = 0;
 
+    /** jcs / commons */
     float ratioGet = 0;
 
+    /** goal */
     float target = 1.0f;
 
+    /** loops */
     int loops = 20;
 
+    /** number to test with */
     int tries = 50000;
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org