commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1728860 - in /commons/proper/jcs/trunk: commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/ commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/ src/changes/
Date Sat, 06 Feb 2016 17:56:22 GMT
Author: tv
Date: Sat Feb  6 17:56:22 2016
New Revision: 1728860

URL: http://svn.apache.org/viewvc?rev=1728860&view=rev
Log:
JCS-159 Fix: BlockDiskCache overwrites data after loading from disk

Modified:
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDisk.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
    commons/proper/jcs/trunk/src/changes/changes.xml

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDisk.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDisk.java?rev=1728860&r1=1728859&r2=1728860&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDisk.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDisk.java
Sat Feb  6 17:56:22 2016
@@ -21,7 +21,6 @@ package org.apache.commons.jcs.auxiliary
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.io.Serializable;
@@ -86,10 +85,10 @@ public class BlockDisk
      * <p>
      * @param file
      * @param elementSerializer
-     * @throws FileNotFoundException
+     * @throws IOException
      */
     public BlockDisk( File file, IElementSerializer elementSerializer )
-        throws FileNotFoundException
+        throws IOException
     {
         this( file, DEFAULT_BLOCK_SIZE_BYTES, elementSerializer );
     }
@@ -99,10 +98,10 @@ public class BlockDisk
      * <p>
      * @param file
      * @param blockSizeBytes
-     * @throws FileNotFoundException
+     * @throws IOException
      */
     public BlockDisk( File file, int blockSizeBytes )
-        throws FileNotFoundException
+        throws IOException
     {
         this( file, blockSizeBytes, new StandardSerializer() );
     }
@@ -113,14 +112,15 @@ public class BlockDisk
      * @param file
      * @param blockSizeBytes
      * @param elementSerializer
-     * @throws FileNotFoundException
+     * @throws IOException
      */
     public BlockDisk( File file, int blockSizeBytes, IElementSerializer elementSerializer
)
-        throws FileNotFoundException
+        throws IOException
     {
         this.filepath = file.getAbsolutePath();
         RandomAccessFile raf = new RandomAccessFile( filepath, "rw" );
         this.fc = raf.getChannel();
+        this.numberOfBlocks.set((int) Math.ceil(1f * this.fc.size() / blockSizeBytes));
 
         if ( log.isInfoEnabled() )
         {

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java?rev=1728860&r1=1728859&r2=1728860&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCacheUnitTestAbstract.java
Sat Feb  6 17:56:22 2016
@@ -327,6 +327,32 @@ public abstract class BlockDiskCacheUnit
             oneLoadFromDisk();
         }
     }
+    
+    public void testAppendToDisk() throws Exception 
+    {
+        String cacheName = "testAppendToDisk";
+        BlockDiskCacheAttributes cattr = getCacheAttributes();
+        cattr.setCacheName(cacheName);
+        cattr.setMaxKeySize(100);
+        cattr.setBlockSizeBytes(500);
+        cattr.setDiskPath("target/test-sandbox/BlockDiskCacheUnitTest");
+        BlockDiskCache<String, X> diskCache = new BlockDiskCache<String, X>(cattr);
+        diskCache.removeAll();
+        X value1 = new X();
+        value1.string = "1234567890";
+        X value2 = new X();
+        value2.string = "0987654321";
+        diskCache.update(new CacheElement<String, X>(cacheName, "1", value1));
+        diskCache.dispose();
+        diskCache = new BlockDiskCache<String, X>(cattr);
+        diskCache.update(new CacheElement<String, X>(cacheName, "2", value2));
+        diskCache.dispose();
+        diskCache = new BlockDiskCache<String, X>(cattr);
+        assertTrue(diskCache.verifyDisk());
+        assertEquals(2, diskCache.getKeySet().size());
+        assertEquals(value1.string, diskCache.get("1").getVal().string);
+        assertEquals(value2.string, diskCache.get("2").getVal().string);
+    }
 
     public void oneLoadFromDisk() throws Exception
     {

Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1728860&r1=1728859&r2=1728860&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Sat Feb  6 17:56:22 2016
@@ -20,6 +20,9 @@
 	</properties>
 	<body>
         <release version="2.0" date="unreleased" description="JDK 1.6 based major release">
+            <action issue="JCS-159" dev="tv" type="fix" due-to="Wiktor Niesiobedzki">
+                Fix: BlockDiskCache overwrites data after loading from disk
+            </action>
             <action dev="tv" type="fix" due-to="Mat Jaggard">
                 Fix Javadoc for Java 8
             </action>



Mime
View raw message