[prev in list] [next in list] [prev in thread] [next in thread]
List: turbine-jcs-dev
Subject: svn commit: r788075 - in /jakarta/jcs/trunk:
From: asmuts () apache ! org
Date: 2009-06-24 16:35:16
Message-ID: 20090624163516.CC8202388872 () eris ! apache ! org
[Download RAW message or body]
Author: asmuts
Date: Wed Jun 24 16:35:16 2009
New Revision: 788075
URL: http://svn.apache.org/viewvc?rev=788075&view=rev
Log:
Fixed JCS-60: Larger size replacements will now go into the recycle bin in the \
Indexed Disk Cache.
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexDiskCacheUnitTest.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
jakarta/jcs/trunk/xdocs/changes.xml
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=788075&r1=788074&r2=788075&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java \
(original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java \
Wed Jun 24 16:35:16 2009 @@ -528,7 +528,7 @@
ded.len = data.length;
}
else
- {
+ {
// we need this to compare in the recycle bin
ded = new IndexedDiskElementDescriptor( dataFile.length(), \
data.length );
@@ -561,6 +561,12 @@
log.debug( logCacheName + "added to queued put list." + \
queuedPutList.size() ); }
}
+
+ // add the old slot to the recycle bin
+ if ( old != null )
+ {
+ addToRecycleBin( old );
+ }
}
dataFile.write( ded, data );
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=788075&r1=788074&r2=788075&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 \
Wed Jun 24 16:35:16 2009 @@ -128,6 +128,7 @@
/**
* Verify that we don't override the largest item.
+ * <p>
* @throws IOException
*/
public void testRecycleBin()
@@ -145,18 +146,18 @@
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 " );
+ //System.out.println( "------------------------- testRecycleBin " );
for ( int i = 0; i < 6; i++ )
{
ICacheElement element = new CacheElement( "testRecycleBin", "key:" + \
test[i], test[i] );
- System.out.println( "About to add " + "key:" + test[i] + " i = " + 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 \
); + //System.out.println( "About to remove " + "key:" + test[i] + " i = " \
+ i ); disk.remove( "key:" + test[i] );
}
@@ -165,7 +166,7 @@
for ( int i = 7; i < 9; i++ )
{
ICacheElement element = new CacheElement( "testRecycleBin", "key:" + \
test[i], test[i] );
- System.out.println( "About to add " + "key:" + test[i] + " i = " + i );
+ //System.out.println( "About to add " + "key:" + test[i] + " i = " + i \
); disk.processUpdate( element );
}
@@ -176,11 +177,11 @@
ICacheElement element = disk.get( "key:" + test[i] );
if ( element != null )
{
- System.out.println( "element = " + element.getVal() );
+ //System.out.println( "element = " + element.getVal() );
}
else
{
- System.out.println( "null --" + "key:" + test[i] );
+ //System.out.println( "null --" + "key:" + test[i] );
}
String expectedValue = expect[i];
@@ -264,6 +265,7 @@
/**
* Verify that the file size is as expected.
+ * <p>
* @throws IOException
* @throws InterruptedException
*/
@@ -293,7 +295,7 @@
long expectedSize = DiskTestObjectUtil.totalSize( elements, numberToInsert \
); long resultSize = disk.getDataFileSize();
- System.out.println( "testFileSize stats " + disk.getStats() );
+ //System.out.println( "testFileSize stats " + disk.getStats() );
assertEquals( "Wrong file size", expectedSize, resultSize );
}
@@ -344,8 +346,8 @@
}
/**
- * Verify that items of the same size use recyle bin spots. Setup the receyle \
bin by removing
- * some items. Add some of the same size. Verify that the recyle count is the \
number added. + * Verify that items of the same size use recycle bin spots. Setup \
the recycle bin by removing + * some items. Add some of the same size. Verify \
that the recycle count is the number added.
* <p>
* @throws IOException
* @throws InterruptedException
@@ -442,7 +444,7 @@
long expectedSize = DiskTestObjectUtil.totalSize( elements, numberToRemove \
); long resultSize = disk.getBytesFree();
- System.out.println( "testBytesFreeSize stats " + disk.getStats() );
+ //System.out.println( "testBytesFreeSize stats " + disk.getStats() );
assertEquals( "Wrong bytes free size" + disk.getStats(), expectedSize, \
resultSize );
@@ -863,4 +865,147 @@
assertEquals( "wrong bytes after retrieval", string, new String( after, UTF8 \
) ); }
+ /**
+ * Verify the item makes it to disk.
+ * <p>
+ * @throws IOException
+ */
+ public void testProcessUpdate_Simple()
+ throws IOException
+ {
+ // SETUP
+ String cacheName = "testProcessUpdate_Simple";
+ IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+ cattr.setCacheName( cacheName );
+ cattr.setMaxKeySize( 100 );
+ cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+ IndexedDiskCache diskCache = new IndexedDiskCache( cattr );
+
+ String key = "myKey";
+ String value = "myValue";
+ ICacheElement ce = new CacheElement( cacheName, key, value );
+
+ // DO WORK
+ diskCache.processUpdate( ce );
+ ICacheElement result = diskCache.processGet( key );
+
+ // VERIFY
+ assertNotNull( "Should have a result", result );
+ long fileSize = diskCache.getDataFileSize();
+ assertTrue( "File should be greater than 0", fileSize > 0 );
+ }
+
+ /**
+ * Verify the item makes it to disk.
+ * <p>
+ * @throws IOException
+ */
+ public void testProcessUpdate_SameKeySameSize()
+ throws IOException
+ {
+ // SETUP
+ String cacheName = "testProcessUpdate_SameKeySameSize";
+ IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+ cattr.setCacheName( cacheName );
+ cattr.setMaxKeySize( 100 );
+ cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+ IndexedDiskCache diskCache = new IndexedDiskCache( cattr );
+
+ String key = "myKey";
+ String value = "myValue";
+ ICacheElement ce1 = new CacheElement( cacheName, key, value );
+
+ // DO WORK
+ diskCache.processUpdate( ce1 );
+ long fileSize1 = diskCache.getDataFileSize();
+
+ // DO WORK
+ ICacheElement ce2 = new CacheElement( cacheName, key, value );
+ diskCache.processUpdate( ce2 );
+ ICacheElement result = diskCache.processGet( key );
+
+ // VERIFY
+ assertNotNull( "Should have a result", result );
+ long fileSize2 = diskCache.getDataFileSize();
+ assertEquals( "File should be the same", fileSize1, fileSize2 );
+ int binSize = diskCache.getRecyleBinSize();
+ assertEquals( "Should be nothing in the bin.", 0, binSize );
+ }
+
+ /**
+ * Verify the item makes it to disk.
+ * <p>
+ * @throws IOException
+ */
+ public void testProcessUpdate_SameKeySmallerSize()
+ throws IOException
+ {
+ // SETUP
+ String cacheName = "testProcessUpdate_SameKeySmallerSize";
+ IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+ cattr.setCacheName( cacheName );
+ cattr.setMaxKeySize( 100 );
+ cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+ IndexedDiskCache diskCache = new IndexedDiskCache( cattr );
+
+ String key = "myKey";
+ String value = "myValue";
+ String value2 = "myValu";
+ ICacheElement ce1 = new CacheElement( cacheName, key, value );
+
+ // DO WORK
+ diskCache.processUpdate( ce1 );
+ long fileSize1 = diskCache.getDataFileSize();
+
+ // DO WORK
+ ICacheElement ce2 = new CacheElement( cacheName, key, value2 );
+ diskCache.processUpdate( ce2 );
+ ICacheElement result = diskCache.processGet( key );
+
+ // VERIFY
+ assertNotNull( "Should have a result", result );
+ long fileSize2 = diskCache.getDataFileSize();
+ assertEquals( "File should be the same", fileSize1, fileSize2 );
+ int binSize = diskCache.getRecyleBinSize();
+ assertEquals( "Should be nothing in the bin.", 0, binSize );
+ }
+
+
+ /**
+ * Verify that the old slot gets in the recycle bin.
+ * <p>
+ * @throws IOException
+ */
+ public void testProcessUpdate_SameKeyBiggerSize()
+ throws IOException
+ {
+ // SETUP
+ String cacheName = "testProcessUpdate_SameKeyBiggerSize";
+ IndexedDiskCacheAttributes cattr = new IndexedDiskCacheAttributes();
+ cattr.setCacheName( cacheName );
+ cattr.setMaxKeySize( 100 );
+ cattr.setDiskPath( "target/test-sandbox/IndexDiskCacheUnitTest" );
+ IndexedDiskCache diskCache = new IndexedDiskCache( cattr );
+
+ String key = "myKey";
+ String value = "myValue";
+ String value2 = "myValue2";
+ ICacheElement ce1 = new CacheElement( cacheName, key, value );
+
+ // DO WORK
+ diskCache.processUpdate( ce1 );
+ long fileSize1 = diskCache.getDataFileSize();
+
+ // DO WORK
+ ICacheElement ce2 = new CacheElement( cacheName, key, value2 );
+ diskCache.processUpdate( ce2 );
+ ICacheElement result = diskCache.processGet( key );
+
+ // VERIFY
+ assertNotNull( "Should have a result", result );
+ long fileSize2 = diskCache.getDataFileSize();
+ assertTrue( "File should be greater.", fileSize1 < fileSize2 );
+ int binSize = diskCache.getRecyleBinSize();
+ assertEquals( "Should be one in the bin.", 1, binSize );
+ }
}
Modified: jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/ \
disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java?rev=788075&r1=788074&r2=788075&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java \
(original)
+++ jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheSameRegionConcurrentUnitTest.java \
Wed Jun 24 16:35:16 2009 @@ -169,9 +169,10 @@
for ( int i = start; i <= end; i++ )
{
- String value = (String) jcs.get( i + ":key" );
+ String key = i + ":key";
+ String value = (String) jcs.get( key );
- assertEquals( region + " data " + i, value );
+ assertEquals( "Wrong value for key [" + key + "]", region + " data " + \
i, value ); }
// Test that getElements returns all the expected values
Modified: jakarta/jcs/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/xdocs/changes.xml?rev=788075&r1=788074&r2=788075&view=diff
==============================================================================
--- jakarta/jcs/trunk/xdocs/changes.xml (original)
+++ jakarta/jcs/trunk/xdocs/changes.xml Wed Jun 24 16:35:16 2009
@@ -19,14 +19,16 @@
<author email="asmuts@apache.org">Aaron Smuts</author>
</properties>
<body>
- <release version="1.4-dev" date="in SVN">
+ <release version="forthcoming" date="in SVN">
+ <action dev="asmuts" type="fix" issue="JCS-60">Slots for same key
+ updates now get added to the recycle bin.</action>
</release>
<release version="1.3.3.2" date="2009-06-11" description="tempbuild">
<action dev="asmuts" type="update">Added a compressing serializer.
</action>
<action dev="asmuts" type="update">Added an LHMLRUMemoryCache.
</action>
- </release>
+ </release>
<release version="1.3.3.1" date="2009-05-22" description="tempbuild">
<action dev="asmuts" type="update">Added a clearDiskOnStartup
configuration option for the IndexedDisk Cache. False by default.
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic