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 2009/05/22 22:01:27 UTC
svn commit: r777688 - in /jakarta/jcs/trunk/src:
java/org/apache/jcs/auxiliary/disk/block/
java/org/apache/jcs/utils/serialization/
test/org/apache/jcs/auxiliary/disk/block/
Author: asmuts
Date: Fri May 22 20:01:27 2009
New Revision: 777688
URL: http://svn.apache.org/viewvc?rev=777688&view=rev
Log:
Checking in tests that expose a block disk cache bug. They are temporarily skipped.
Modified:
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java
jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java
jakarta/jcs/trunk/src/test/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheUnitTest.java
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java?rev=777688&r1=777687&r2=777688&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDisk.java Fri May 22 20:01:27 2009
@@ -112,6 +112,33 @@
}
this.blockSizeBytes = blockSizeBytes;
}
+
+ /**
+ * Creates the file and set the block size in bytes.
+ * <p>
+ * @param file
+ * @param blockSizeBytes
+ * @param elementSerializer
+ * @throws FileNotFoundException
+ */
+ public BlockDisk( File file, int blockSizeBytes, IElementSerializer elementSerializer )
+ throws FileNotFoundException
+ {
+ this.filepath = file.getAbsolutePath();
+ raf = new RandomAccessFile( filepath, "rw" );
+
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Constructing BlockDisk, blockSizeBytes [" + blockSizeBytes + "]" );
+ }
+ this.blockSizeBytes = blockSizeBytes;
+
+ if ( log.isInfoEnabled() )
+ {
+ log.info( "Used default block size [" + DEFAULT_BLOCK_SIZE_BYTES + "]" );
+ }
+ this.elementSerializer = elementSerializer;
+ }
/**
* This writes an object to disk and returns the blocks it was stored in.
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java?rev=777688&r1=777687&r2=777688&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java Fri May 22 20:01:27 2009
@@ -94,7 +94,7 @@
{
this( cacheAttributes, null );
}
-
+
/**
* Constructs the BlockDisk after setting up the root directory.
* <p>
@@ -105,7 +105,7 @@
{
super( cacheAttributes );
setElementSerializer( elementSerializer );
-
+
this.blockDiskCacheAttributes = cacheAttributes;
this.logCacheName = "Region [" + getCacheName() + "] ";
@@ -253,13 +253,13 @@
{
storageLock.readLock().release();
}
-
+
Set matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
-
+
Iterator keyIterator = matchingKeys.iterator();
while ( keyIterator.hasNext() )
{
- String key = (String)keyIterator.next();
+ String key = (String) keyIterator.next();
ICacheElement element = processGet( key );
if ( element != null )
{
@@ -273,7 +273,7 @@
}
return elements;
}
-
+
/**
* Returns the number of keys.
* <p>
@@ -288,14 +288,12 @@
/**
* Gets the ICacheElement for the key if it is in the cache. The program flow is as follows:
* <ol>
- * <li>Make sure the disk cache is alive.</li>
- * <li>Get a read lock.</li>
- * <li>See if the key is in the key store.</li>
- * <li>If we found a key, ask the BlockDisk for the object at the blocks..</li>
- * <li>Release the lock.</li>
+ * <li>Make sure the disk cache is alive.</li> <li>Get a read lock.</li> <li>See if the key is
+ * in the key store.</li> <li>If we found a key, ask the BlockDisk for the object at the
+ * blocks..</li> <li>Release the lock.</li>
* </ol>
* (non-Javadoc)
- * @param key
+ * @param key
* @return ICacheElement
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doGet(java.io.Serializable)
*/
@@ -348,15 +346,13 @@
/**
* Writes an element to disk. The program flow is as follows:
* <ol>
- * <li>Aquire write lock.</li>
- * <li>See id an item exists for this key.</li>
- * <li>If an itme already exists, add its blocks to the remove list.</li>
- * <li>Have the Block disk write the item.</li>
- * <li>Create a descriptor and add it to the key map.</li>
- * <li>Release the write lock.</li>
+ * <li>Aquire write lock.</li> <li>See id an item exists for this key.</li> <li>If an itme
+ * already exists, add its blocks to the remove list.</li> <li>Have the Block disk write the
+ * item.</li> <li>Create a descriptor and add it to the key map.</li> <li>Release the write
+ * lock.</li>
* </ol>
* (non-Javadoc)
- * @param element
+ * @param element
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doUpdate(org.apache.jcs.engine.behavior.ICacheElement)
*/
protected void processUpdate( ICacheElement element )
@@ -413,7 +409,7 @@
* implementation always result in a disk orphan.
* <p>
* (non-Javadoc)
- * @param key
+ * @param key
* @return true if removed anything
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doRemove(java.io.Serializable)
*/
@@ -766,7 +762,7 @@
return stats;
}
-
+
/**
* This is used by the event logging.
* <p>
@@ -775,5 +771,5 @@
protected String getDiskLocation()
{
return dataFile.getFilePath();
- }
+ }
}
Modified: jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java
URL: http://svn.apache.org/viewvc/jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java?rev=777688&r1=777687&r2=777688&view=diff
==============================================================================
--- jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java (original)
+++ jakarta/jcs/trunk/src/java/org/apache/jcs/utils/serialization/StandardSerializer.java Fri May 22 20:01:27 2009
@@ -47,7 +47,7 @@
public byte[] serialize( Serializable obj )
throws IOException
{
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
try
{
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=777688&r1=777687&r2=777688&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 May 22 20:01:27 2009
@@ -84,10 +84,9 @@
* <p>
* @throws Exception
*/
- public void SKIPtestChunk_BigString()
+ public void testChunk_BigString()
throws Exception
{
-
String string = "This is my big string ABCDEFGH";
StringBuffer sb = new StringBuffer();
sb.append( string );
@@ -101,13 +100,17 @@
byte[] data = elementSerializer.serialize( string );
File file = new File( "target/test-sandbox/BlockDiskCacheUnitTest/testChunk_BigString.data" );
- BlockDisk blockDisk = new BlockDisk( file, elementSerializer );
- int numBlocksNeeded = blockDisk.calculateTheNumberOfBlocksNeeded( data );
+ BlockDisk blockDisk = new BlockDisk( file, 200, elementSerializer );
+ int numBlocksNeeded = blockDisk.calculateTheNumberOfBlocksNeeded( data );
+ System.out.println( numBlocksNeeded );
+
// get the individual sub arrays.
byte[][] chunks = blockDisk.getBlockChunks( data, numBlocksNeeded );
+ byte[] resultData = new byte[0];
+
for ( short i = 0; i < chunks.length; i++ )
{
byte[] chunk = chunks[i];
@@ -117,10 +120,10 @@
// copy the chunk into the new array
System.arraycopy( chunk, 0, newTotal, data.length, chunk.length );
// swap the new and old.
- data = newTotal;
+ resultData = newTotal;
}
- Serializable result = (Serializable) elementSerializer.deSerialize( data );
+ Serializable result = (Serializable) elementSerializer.deSerialize( resultData );
System.out.println( result );
assertEquals( "wrong string after retrieval", string, result );
}
@@ -130,7 +133,7 @@
* <p>
* @throws Exception
*/
- public void SKIPtestPutGet_BigString()
+ public void SKIP_testPutGet_BigString()
throws Exception
{
String string = "This is my big string ABCDEFGH";
@@ -147,7 +150,7 @@
BlockDiskCacheAttributes cattr = new BlockDiskCacheAttributes();
cattr.setCacheName( cacheName );
cattr.setMaxKeySize( 100 );
- cattr.setBlockSizeBytes( 300 );
+ cattr.setBlockSizeBytes( 200 );
cattr.setDiskPath( "target/test-sandbox/BlockDiskCacheUnitTest" );
BlockDiskCache diskCache = new BlockDiskCache( cattr );
@@ -171,7 +174,7 @@
* <p>
* @throws Exception
*/
- public void SKIPtestUTF8String()
+ public void SKIP_testUTF8String()
throws Exception
{
String string = "Iñtërnâtiônàlizætiøn";
@@ -261,7 +264,7 @@
* <p>
* @throws Exception
*/
- public void SKIPtestUTF8StringAndBytes()
+ public void SKIP_testUTF8StringAndBytes()
throws Exception
{
X before = new X();
---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jcs-dev-help@jakarta.apache.org