commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1671552 [2/2] - in /commons/proper/jcs/trunk: commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/ commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/behavior/ commons-jcs-core/src/main/java/org/apache/co...
Date Mon, 06 Apr 2015 15:28:11 GMT
Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
Mon Apr  6 15:28:10 2015
@@ -40,9 +40,10 @@ import java.util.Set;
  * <p>
  * @author Aaron Smuts
  */
-public class IndexDiskCacheUnitTest
+public abstract class IndexDiskCacheUnitTest
     extends TestCase
 {
+	public abstract IndexedDiskCacheAttributes getCacheAttributes();
     /**
      * Simply verify that we can put items in the disk cache and retrieve them.
      * @throws IOException
@@ -50,7 +51,7 @@ public class IndexDiskCacheUnitTest
     public void testSimplePutAndGet()
         throws IOException
     {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testSimplePutAndGet" );
         cattr.setMaxKeySize( 1000 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -99,7 +100,7 @@ public class IndexDiskCacheUnitTest
     public void testRemoveItems()
         throws IOException
     {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRemoveItems" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -131,80 +132,7 @@ public class IndexDiskCacheUnitTest
      * <p>
      * @throws IOException
      */
-    public void testRecycleBin()
-        throws IOException
-    {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
-        cattr.setCacheName( "testRemoveItems" );
-        cattr.setMaxRecycleBinSize( 2 );
-        cattr.setOptimizeAtRemoveCount( 7 );
-        cattr.setMaxKeySize( 5 );
-        cattr.setMaxPurgatorySize( 0 );
-        cattr.setDiskPath( "target/test-sandbox/BreakIndexTest" );
-        IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>(
cattr );
-
-        String[] test = { "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhhh",
"iiiiiiiiii" };
-        String[] expect = { null, "bb", "ccc", null, null, "ffffff", null, "hhhhhhhhh", "iiiiiiiiii"
};
-
-        //System.out.println( "------------------------- testRecycleBin " );
-
-        for ( int i = 0; i < 6; i++ )
-        {
-            ICacheElement<String, String> element = new CacheElement<String, String>(
"testRecycleBin", "key:" + test[i], test[i] );
-            //System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
-            disk.processUpdate( element );
-        }
-
-        for ( int i = 3; i < 5; i++ )
-        {
-            //System.out.println( "About to remove " + "key:" + test[i] + " i = " + i );
-            disk.remove( "key:" + test[i] );
-        }
-
-        // there was a bug where 7 would try to be put in the empty slot left by 4's removal,
but it
-        // will not fit.
-        for ( int i = 7; i < 9; i++ )
-        {
-            ICacheElement<String, String> element = new CacheElement<String, String>(
"testRecycleBin", "key:" + test[i], test[i] );
-            //System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
-            disk.processUpdate( element );
-        }
-
-        try
-        {
-            for ( int i = 0; i < 9; i++ )
-            {
-                ICacheElement<String, String> element = disk.get( "key:" + test[i]
);
-                if ( element != null )
-                {
-                    //System.out.println( "element = " + element.getVal() );
-                }
-                else
-                {
-                    //System.out.println( "null --" + "key:" + test[i] );
-                }
-
-                String expectedValue = expect[i];
-                if ( expectedValue == null )
-                {
-                    assertNull( "Expected a null element", element );
-                }
-                else
-                {
-                    assertNotNull( "The element for key [" + "key:" + test[i] + "] should
not be null. i = " + i,
-                                   element );
-                    assertEquals( "Elements contents do not match expected", element.getVal(),
expectedValue );
-                }
-            }
-        }
-        catch ( Exception e )
-        {
-            e.printStackTrace();
-            fail( "Should not get an exception: " + e.toString() );
-        }
-
-        disk.removeAll();
-    }
+  
 
     /**
      * Verify that the overlap check returns true when there are no overlaps.
@@ -212,7 +140,7 @@ public class IndexDiskCacheUnitTest
     public void testCheckForDedOverlaps_noOverlap()
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testCheckForDedOverlaps_noOverlap" );
         cattr.setDiskPath( "target/test-sandbox/UnitTest" );
         IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>(
cattr );
@@ -240,7 +168,7 @@ public class IndexDiskCacheUnitTest
     public void testCheckForDedOverlaps_overlaps()
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testCheckForDedOverlaps_overlaps" );
         cattr.setDiskPath( "target/test-sandbox/UnitTest" );
         IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>(
cattr );
@@ -273,7 +201,7 @@ public class IndexDiskCacheUnitTest
         throws IOException, InterruptedException
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testFileSize" );
         cattr.setDiskPath( "target/test-sandbox/UnitTest" );
         IndexedDiskCache<Integer, DiskTestObject> disk = new IndexedDiskCache<Integer,
DiskTestObject>( cattr );
@@ -312,7 +240,7 @@ public class IndexDiskCacheUnitTest
         // SETUP
         int numberToInsert = 20;
 
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRecyleBinSize" );
         cattr.setDiskPath( "target/test-sandbox/UnitTest" );
         cattr.setMaxRecycleBinSize( numberToInsert );
@@ -321,7 +249,7 @@ public class IndexDiskCacheUnitTest
         cattr.setMaxPurgatorySize( numberToInsert );
         IndexedDiskCache<Integer, DiskTestObject> disk = new IndexedDiskCache<Integer,
DiskTestObject>( cattr );
 
-        int bytes = 24;
+        int bytes = 1;
         ICacheElement<Integer, DiskTestObject>[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects(
numberToInsert, bytes, cattr
             .getCacheName() );
 
@@ -358,7 +286,7 @@ public class IndexDiskCacheUnitTest
         // SETUP
         int numberToInsert = 20;
 
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRecyleBinUsage" );
         cattr.setDiskPath( "target/test-sandbox/UnitTest" );
         cattr.setMaxRecycleBinSize( numberToInsert );
@@ -368,7 +296,7 @@ public class IndexDiskCacheUnitTest
         IndexedDiskCache<Integer, DiskTestObject> disk = new IndexedDiskCache<Integer,
DiskTestObject>( cattr );
 
         // we will reuse these
-        int bytes = 24;
+        int bytes = 1;
         ICacheElement<Integer, DiskTestObject>[] elements = DiskTestObjectUtil.createCacheElementsWithTestObjects(
numberToInsert, bytes, cattr
             .getCacheName() );
 
@@ -415,7 +343,7 @@ public class IndexDiskCacheUnitTest
         throws IOException, InterruptedException
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testBytesFreeSize" );
         cattr.setDiskPath( "target/test-sandbox/UnitTest" );
         IndexedDiskCache<Integer, DiskTestObject> disk = new IndexedDiskCache<Integer,
DiskTestObject>( cattr );
@@ -468,7 +396,7 @@ public class IndexDiskCacheUnitTest
     public void testRemove_PartialKey()
         throws IOException
     {
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRemove_PartialKey" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -513,7 +441,7 @@ public class IndexDiskCacheUnitTest
         throws IOException
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRemove_Group" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -583,7 +511,7 @@ public class IndexDiskCacheUnitTest
         throws Exception
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testUpdate_EventLogging_simple" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTestCEL" );
@@ -614,7 +542,7 @@ public class IndexDiskCacheUnitTest
         throws Exception
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testGet_EventLogging_simple" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTestCEL" );
@@ -641,7 +569,7 @@ public class IndexDiskCacheUnitTest
         throws Exception
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testGetMultiple_EventLogging_simple" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTestCEL" );
@@ -672,7 +600,7 @@ public class IndexDiskCacheUnitTest
         throws Exception
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRemoveAll_EventLogging_simple" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTestCEL" );
@@ -699,7 +627,7 @@ public class IndexDiskCacheUnitTest
         throws Exception
     {
         // SETUP
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( "testRemoveAll_EventLogging_simple" );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTestCEL" );
@@ -729,7 +657,7 @@ public class IndexDiskCacheUnitTest
         int items = 200;
 
         String cacheName = "testPutGetMatching_SmallWait";
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -762,7 +690,7 @@ public class IndexDiskCacheUnitTest
         int items = 200;
 
         String cacheName = "testPutGetMatching_NoWait";
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -803,7 +731,7 @@ public class IndexDiskCacheUnitTest
 
         String cacheName = "testUTF8String";
 
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -846,7 +774,7 @@ public class IndexDiskCacheUnitTest
 
         String cacheName = "testUTF8ByteArray";
 
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -877,7 +805,7 @@ public class IndexDiskCacheUnitTest
     {
         // SETUP
         String cacheName = "testProcessUpdate_Simple";
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -907,7 +835,7 @@ public class IndexDiskCacheUnitTest
     {
         // SETUP
         String cacheName = "testProcessUpdate_SameKeySameSize";
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -944,7 +872,7 @@ public class IndexDiskCacheUnitTest
     {
         // SETUP
         String cacheName = "testProcessUpdate_SameKeySmallerSize";
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
@@ -982,7 +910,7 @@ public class IndexDiskCacheUnitTest
     {
         // SETUP
         String cacheName = "testProcessUpdate_SameKeyBiggerSize";
-        IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        IndexedDiskCacheAttributes cattr = getCacheAttributes();
         cattr.setCacheName( cacheName );
         cattr.setMaxKeySize( 100 );
         cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );

Added: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestCount.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestCount.java?rev=1671552&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestCount.java
(added)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestCount.java
Mon Apr  6 15:28:10 2015
@@ -0,0 +1,91 @@
+package org.apache.commons.jcs.auxiliary.disk.indexed;
+
+import java.io.IOException;
+
+import org.apache.commons.jcs.auxiliary.disk.behavior.IDiskCacheAttributes.DiskLimitType;
+import org.apache.commons.jcs.engine.CacheElement;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
+public class IndexDiskCacheUnitTestCount extends IndexDiskCacheUnitTest {
+
+	@Override
+	public IndexedDiskCacheAttributes getCacheAttributes() {
+		IndexedDiskCacheAttributes ret = new IndexedDiskCacheAttributes();
+		ret.setDiskLimitType(DiskLimitType.COUNT);
+		return ret;
+	}
+	  public void testRecycleBin()
+		        throws IOException
+		    {
+		        IndexedDiskCacheAttributes cattr = getCacheAttributes();
+		        cattr.setCacheName( "testRemoveItems" );
+		        cattr.setMaxRecycleBinSize( 2 );
+		        cattr.setOptimizeAtRemoveCount( 7 );
+		        cattr.setMaxKeySize( 5 );
+		        cattr.setMaxPurgatorySize( 0 );
+		        cattr.setDiskPath( "target/test-sandbox/BreakIndexTest" );
+		        IndexedDiskCache<String, String> disk = new IndexedDiskCache<String, String>(
cattr );
+
+		        String[] test = { "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhhh",
"iiiiiiiiii" };
+		        String[] expect = { null, "bb", "ccc", null, null, "ffffff", null, "hhhhhhhhh",
"iiiiiiiiii" };
+
+		        //System.out.println( "------------------------- testRecycleBin " );
+
+		        for ( int i = 0; i < 6; i++ )
+		        {
+		            ICacheElement<String, String> element = new CacheElement<String, String>(
"testRecycleBin", "key:" + test[i], test[i] );
+		            //System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+		            disk.processUpdate( element );
+		        }
+
+		        for ( int i = 3; i < 5; i++ )
+		        {
+		            //System.out.println( "About to remove " + "key:" + test[i] + " i = " + i );
+		            disk.remove( "key:" + test[i] );
+		        }
+
+		        // there was a bug where 7 would try to be put in the empty slot left by 4's removal,
but it
+		        // will not fit.
+		        for ( int i = 7; i < 9; i++ )
+		        {
+		            ICacheElement<String, String> element = new CacheElement<String, String>(
"testRecycleBin", "key:" + test[i], test[i] );
+		            //System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+		            disk.processUpdate( element );
+		        }
+
+		        try
+		        {
+		            for ( int i = 0; i < 9; i++ )
+		            {
+		                ICacheElement<String, String> element = disk.get( "key:" + test[i]
);
+		                if ( element != null )
+		                {
+		                    //System.out.println( "element = " + element.getVal() );
+		                }
+		                else
+		                {
+		                    //System.out.println( "null --" + "key:" + test[i] );
+		                }
+
+		                String expectedValue = expect[i];
+		                if ( expectedValue == null )
+		                {
+		                    assertNull( "Expected a null element", element );
+		                }
+		                else
+		                {
+		                    assertNotNull( "The element for key [" + "key:" + test[i] + "] should
not be null. i = " + i,
+		                                   element );
+		                    assertEquals( "Elements contents do not match expected", element.getVal(),
expectedValue );
+		                }
+		            }
+		        }
+		        catch ( Exception e )
+		        {
+		            e.printStackTrace();
+		            fail( "Should not get an exception: " + e.toString() );
+		        }
+
+		        disk.removeAll();
+		    }
+}

Propchange: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestCount.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestSize.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestSize.java?rev=1671552&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestSize.java
(added)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestSize.java
Mon Apr  6 15:28:10 2015
@@ -0,0 +1,92 @@
+package org.apache.commons.jcs.auxiliary.disk.indexed;
+
+import java.io.IOException;
+
+import org.apache.commons.jcs.auxiliary.disk.DiskTestObject;
+import org.apache.commons.jcs.auxiliary.disk.behavior.IDiskCacheAttributes.DiskLimitType;
+import org.apache.commons.jcs.engine.CacheElement;
+import org.apache.commons.jcs.engine.behavior.ICacheElement;
+
+public class IndexDiskCacheUnitTestSize extends IndexDiskCacheUnitTest {
+
+	@Override
+	public IndexedDiskCacheAttributes getCacheAttributes() {
+		IndexedDiskCacheAttributes ret = new IndexedDiskCacheAttributes();
+		ret.setDiskLimitType(DiskLimitType.SIZE);
+		return ret;
+	}
+	  public void testRecycleBin()
+		        throws IOException
+		    {
+		        IndexedDiskCacheAttributes cattr = getCacheAttributes();
+		        cattr.setCacheName( "testRemoveItems" );
+		        cattr.setMaxRecycleBinSize( 2 );
+		        cattr.setOptimizeAtRemoveCount( 7 );
+		        cattr.setMaxKeySize( 8); // 1kb DiskTestObject takes 1420 bytes, so 5*1420 = 7100,
so to keep 5 ojbects, we need max key size of 8
+		        cattr.setMaxPurgatorySize( 0 );
+		        cattr.setDiskPath( "target/test-sandbox/BreakIndexTest" );
+		        IndexedDiskCache<String, DiskTestObject> disk = new IndexedDiskCache<String,
DiskTestObject>( cattr );
+
+		        String[] test = { "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhhh",
"iiiiiiiiii" };
+		        String[] expect = { null, "bb", "ccc", null, null, "ffffff", null, "hhhhhhhhh",
"iiiiiiiiii" };
+		        DiskTestObject value = DiskTestObjectUtil.createCacheElementsWithTestObjects( 1,
1, cattr .getCacheName())[0].getVal();
+		        //System.out.println( "------------------------- testRecycleBin " );
+
+		        for ( int i = 0; i < 6; i++ )
+		        {
+		            ICacheElement<String, DiskTestObject> element = new CacheElement<String,
DiskTestObject>( "testRecycleBin", "key:" + test[i], value);
+		            //System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+		            disk.processUpdate( element );
+		        }
+
+		        for ( int i = 3; i < 5; i++ )
+		        {
+		            //System.out.println( "About to remove " + "key:" + test[i] + " i = " + i );
+		            disk.remove( "key:" + test[i] );
+		        }
+
+		        // there was a bug where 7 would try to be put in the empty slot left by 4's removal,
but it
+		        // will not fit.
+		        for ( int i = 7; i < 9; i++ )
+		        {
+		            ICacheElement<String, DiskTestObject> element = new CacheElement<String,
DiskTestObject>( "testRecycleBin", "key:" + test[i], value);
+		            //System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+		            disk.processUpdate( element );
+		        }
+
+		        try
+		        {
+		            for ( int i = 0; i < 9; i++ )
+		            {
+		                ICacheElement<String, DiskTestObject> element = disk.get( "key:"
+ test[i] );
+		                if ( element != null )
+		                {
+		                    //System.out.println( "element = " + element.getVal() );
+		                }
+		                else
+		                {
+		                    //System.out.println( "null --" + "key:" + test[i] );
+		                }
+
+		                String expectedValue = expect[i];
+		                if ( expectedValue == null )
+		                {
+		                    assertNull( "Expected a null element", element );
+		                }
+		                else
+		                {
+		                    assertNotNull( "The element for key [" + "key:" + test[i] + "] should
not be null. i = " + i,
+		                                   element );
+		                    assertEquals( "Elements contents do not match expected", element.getVal(),
value );
+		                }
+		            }
+		        }
+		        catch ( Exception e )
+		        {
+		            e.printStackTrace();
+		            fail( "Should not get an exception: " + e.toString() );
+		        }
+
+		        disk.removeAll();
+		    }
+}

Propchange: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTestSize.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
Mon Apr  6 15:28:10 2015
@@ -113,7 +113,7 @@ public class IndexedDiskCacheSameRegionC
             public void runTest()
                 throws Exception
             {
-                this.runTestForRegion( "indexedRegion4", 0, 5200 );
+                this.runTestForRegion( "indexedRegion4", 0, 5100 );
             }
         } );
 

Added: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/LRUMapSizeVsCount.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/LRUMapSizeVsCount.java?rev=1671552&view=auto
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/LRUMapSizeVsCount.java
(added)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/LRUMapSizeVsCount.java
Mon Apr  6 15:28:10 2015
@@ -0,0 +1,246 @@
+package org.apache.commons.jcs.auxiliary.disk.indexed;
+
+/*
+ * 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.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.commons.jcs.JCSvsHashtablePerformanceTest;
+import org.apache.commons.jcs.TestLogConfigurationUtil;
+import org.apache.commons.jcs.auxiliary.disk.AbstractDiskCache;
+import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCache;
+import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes;
+import org.apache.commons.jcs.auxiliary.disk.indexed.IndexedDiskElementDescriptor;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+import java.util.Map;
+
+/**
+ * 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.
+ * <p>
+ * @author aaronsm
+ *
+ */
+public class LRUMapSizeVsCount
+    extends TestCase
+{
+    /** The put put ration after the test */
+    double ratioPut = 0;
+
+    /** The ratio after the test */
+    double ratioGet = 0;
+
+    /** put size / count  ratio */
+    float targetPut = 1.2f;
+
+    /** get size / count ratio */
+    float targetGet = 1.2f;
+
+    /** Time to loop */
+    int loops = 20;
+
+    /** items to put and get per loop */
+    int tries = 100000;
+
+    /**
+     * @param testName
+     */
+    public LRUMapSizeVsCount( String testName )
+    {
+        super( testName );
+    }
+
+    /**
+     * A unit test suite for JUnit
+     * <p>
+     * @return The test suite
+     */
+    public static Test suite()
+    {
+        return new TestSuite( LRUMapSizeVsCount.class );
+    }
+
+    /**
+     * A unit test for JUnit
+     *
+     * @throws Exception
+     *                Description of the Exception
+     */
+    public void testSimpleLoad()
+        throws Exception
+    {
+        doWork();
+        assertTrue( this.ratioPut < targetPut );
+        assertTrue( this.ratioGet < targetGet );
+    }
+
+    /**
+     *
+     */
+    public void doWork()
+    {
+        long start = 0;
+        long end = 0;
+        long time = 0;
+        float tPer = 0;
+
+        long putTotalCount = 0;
+        long getTotalCount = 0;
+        long putTotalSize = 0;
+        long getTotalSize = 0;
+        
+        long minTimeSizePut = Long.MAX_VALUE;
+        long minTimeSizeGet = Long.MAX_VALUE;
+        long minTimeCountPut = Long.MAX_VALUE;
+        long minTimeCountGet = Long.MAX_VALUE;
+
+        String cacheName = "LRUMap";
+        String cache2Name = "";
+
+        try
+        {
+        	IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+        	cattr.setName("junit");
+        	cattr.setCacheName("junit");
+        	cattr.setDiskPath(".");
+        	IndexedDiskCache<String, String> idc = new IndexedDiskCache<String, String>(cattr);
+
+			Map<String, IndexedDiskElementDescriptor> cacheCount = idc.new LRUMapCountLimited(
tries );
+			Map<String, IndexedDiskElementDescriptor> cacheSize = idc.new LRUMapSizeLimited(
tries/1024/2 );
+
+            for ( int j = 0; j < loops; j++ )
+            {
+                cacheName = "LRU Count           ";
+                start = System.currentTimeMillis();
+                for ( int i = 0; i < tries; i++ )
+                {
+                    cacheCount.put( "key:" + i,  new IndexedDiskElementDescriptor(i, i) );
+                }
+                end = System.currentTimeMillis();
+                time = end - start;
+                putTotalCount += time;
+                minTimeCountPut = Math.min(time, minTimeCountPut);
+                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
+                System.out.println( cacheName + " put time for " + tries + " = " + time +
"; millis per = " + tPer );
+
+                start = System.currentTimeMillis();
+                for ( int i = 0; i < tries; i++ )
+                {
+                    cacheCount.get( "key:" + i );
+                }
+                end = System.currentTimeMillis();
+                time = end - start;
+                getTotalCount += time;
+                minTimeCountGet = Math.min(minTimeCountGet, time);
+                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
+                System.out.println( cacheName + " get time for " + tries + " = " + time +
"; millis per = " + tPer );
+
+                ///////////////////////////////////////////////////////////////
+                cache2Name = "LRU Size            ";
+                //or LRUMapJCS
+                //cache2Name = "Hashtable";
+                //Hashtable cache2 = new Hashtable();
+                start = System.currentTimeMillis();
+                for ( int i = 0; i < tries; i++ )
+                {
+                    cacheSize.put( "key:" + i, new IndexedDiskElementDescriptor(i, i) );
+                }
+                end = System.currentTimeMillis();
+                time = end - start;
+                putTotalSize += time;
+                minTimeSizePut = Math.min(minTimeSizePut, time);
+                
+                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
+                System.out.println( cache2Name + " put time for " + tries + " = " + time
+ "; millis per = " + tPer );
+
+                start = System.currentTimeMillis();
+                for ( int i = 0; i < tries; i++ )
+                {
+                    cacheSize.get( "key:" + i );
+                }
+                end = System.currentTimeMillis();
+                time = end - start;
+                getTotalSize += time;
+                minTimeSizeGet = Math.min(minTimeSizeGet, time);
+                
+                tPer = Float.intBitsToFloat( (int) time ) / Float.intBitsToFloat( tries );
+                System.out.println( cache2Name + " get time for " + tries + " = " + time
+ "; millis per = " + tPer );
+
+                System.out.println( "\n" );
+            }
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace( System.out );
+            System.out.println( e );
+        }
+
+        long putAvCount = putTotalCount / loops;
+        long getAvCount = getTotalCount / loops;
+        long putAvSize = putTotalSize / loops;
+        long getAvSize = getTotalSize / loops;
+
+        System.out.println( "Finished " + loops + " loops of " + tries + " gets and puts"
);
+
+        System.out.println( "\n" );
+        System.out.println( "Put average for " + cacheName +  " = " + putAvCount );
+        System.out.println( "Put average for " + cache2Name + " = " + putAvSize );
+        ratioPut = (putAvSize *1.0) / putAvCount;
+        System.out.println( cache2Name.trim() + " puts took " + ratioPut + " times the "
+ cacheName.trim() + ", the goal is <" + targetPut
+            + "x" );
+        
+        System.out.println( "\n" );
+        System.out.println( "Put minimum for " + cacheName +  " = " + minTimeCountPut );
+        System.out.println( "Put minimum for " + cache2Name + " = " + minTimeSizePut );
+        ratioPut = (minTimeSizePut * 1.0) / minTimeCountPut;
+        System.out.println( cache2Name.trim() + " puts took " + ratioPut + " times the "
+ cacheName.trim() + ", the goal is <" + targetPut
+            + "x" );
+
+        System.out.println( "\n" );
+        System.out.println( "Get average for " + cacheName + " = " + getAvCount );
+        System.out.println( "Get average for " + cache2Name + " = " + getAvSize );
+        ratioGet = Float.intBitsToFloat( (int) getAvCount ) / Float.intBitsToFloat( (int)
getAvSize );
+        ratioGet = (getAvSize * 1.0) / getAvCount;
+        System.out.println( cache2Name.trim() + " gets took " + ratioGet + " times the "
+ cacheName.trim() + ", the goal is <" + targetGet
+            + "x" );
+        
+        System.out.println( "\n" );
+        System.out.println( "Get minimum for " + cacheName +  " = " + minTimeCountGet );
+        System.out.println( "Get minimum for " + cache2Name + " = " + minTimeSizeGet );
+        ratioPut = (minTimeSizeGet * 1.0) / minTimeCountGet;
+        System.out.println( cache2Name.trim() + " puts took " + ratioPut + " times the "
+ cacheName.trim() + ", the goal is <" + targetGet
+            + "x" );
+
+    }
+
+    /**
+     * @param args
+     */
+    public static void main( String args[] )
+    {
+    	LRUMapSizeVsCount test = new LRUMapSizeVsCount( "command" );
+        test.doWork();
+    }
+
+}

Propchange: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/indexed/LRUMapSizeVsCount.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/JCSvsCommonsLRUMapPerformanceTest.java
Mon Apr  6 15:28:10 2015
@@ -50,7 +50,7 @@ public class JCSvsCommonsLRUMapPerforman
     int loops = 20;
 
     /** number to test with */
-    int tries = 50000;
+    int tries = 100000;
 
     /**
      * @param testName

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapPerformanceTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapPerformanceTest.java?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapPerformanceTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/struct/LRUMapPerformanceTest.java
Mon Apr  6 15:28:10 2015
@@ -52,7 +52,7 @@ public class LRUMapPerformanceTest
     int loops = 20;
 
     /** items to put and get per loop */
-    int tries = 50000;
+    int tries = 100000;
 
     /**
      * @param testName

Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Mon Apr  6 15:28:10 2015
@@ -20,6 +20,9 @@
 	</properties>
 	<body>
         <release version="2.0" date="unreleased" description="JDK 1.6 based major release">
+            <action issue="JCS-147" dev="tv" type="add" due-to="Wiktor Niesiobedzki">
+                Provide file size limitation for Block Disk Cache and Indexed Disk Cache
+            </action>
             <action issue="JCS-96" dev="tv" type="fix" due-to="Gregory Fernandez">
                 Incomplete shutdown of RemoteCacheServer
             </action>

Modified: commons/proper/jcs/trunk/xdocs/BlockDiskCache.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/xdocs/BlockDiskCache.xml?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/xdocs/BlockDiskCache.xml (original)
+++ commons/proper/jcs/trunk/xdocs/BlockDiskCache.xml Mon Apr  6 15:28:10 2015
@@ -42,6 +42,20 @@
 				be optimized. Once the maximum number of keys is
 				reached, blocks will be reused.
 			</p>
+			
+			<section name="Size limitation">
+				<p>
+					There are two ways to limit the cache size: using element
+					count and element size. When using element count, in disk
+					store there will be at most MaxKeySize elements (not disk 
+					blocks). When using element size, there will be at most
+					KeySize kB of elements stored in the data file. As the Block 
+					Disk Cache doesn't need optimization, the data file 
+					will be not longer than specified. The limit does not
+					cover the key file size. The mode is chosen using DiskLimitType. 
+					Allowed values are: COUNT and SIZE.
+				</p>
+			</section>
 
 			<subsection name="Example cache.ccf">
 				<source>

Modified: commons/proper/jcs/trunk/xdocs/IndexedDiskAuxCache.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/xdocs/IndexedDiskAuxCache.xml?rev=1671552&r1=1671551&r2=1671552&view=diff
==============================================================================
--- commons/proper/jcs/trunk/xdocs/IndexedDiskAuxCache.xml (original)
+++ commons/proper/jcs/trunk/xdocs/IndexedDiskAuxCache.xml Mon Apr  6 15:28:10 2015
@@ -73,7 +73,7 @@
 					is retrieved from purgatory it will no longer be
 					written to disk, since the cache hub will move it
 					back to memory. Using purgatory insures that there
-					is no wait for disk writes, unecessary disk writes
+					is no wait for disk writes, unnecessary disk writes
 					are avoided for borderline items, and the items are
 					always available.
 				</p>
@@ -89,6 +89,20 @@
 					mechanism.
 				</p>
 			</subsection>
+			
+			<subsection name="Size limitation">
+				<p>
+					There are two ways to limit the cache size: using element
+					count and element size. When using element count, in disk
+					store there will be at most MaxKeySize elements. When using
+					element size, there will be at most KeySize kB of elements
+					stored in the data file. The file can be bigger due to 
+					fragmentation. The limit does not cover the size of key file
+					so the total space occupied by the cache might be a bit bigger.
+					The mode is chosen using DiskLimitType. Allowed values are: 
+					COUNT and SIZE.
+				</p>
+			</subsection>
 
 			<subsection name="Configuration">
 				<p>
@@ -227,6 +241,7 @@ jcs.auxiliary.DC.attributes.MaxKeySize=1
 jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
 jcs.auxiliary.DC.attributes.OptimizeOnShutdown=true
 jcs.auxiliary.DC.attributes.MaxRecycleBinSize=7500
+jcs.auxiliary.DC.attributes.DiskLimitType=COUNT
         ]]>
 				</source>
 			</subsection>



Mime
View raw message