jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r1129364 - in /incubator/jena/Experimental/TxTDB/trunk: src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/base/file/ src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ src/test/java/com/hp/hpl/jena/tdb/base/objectfile/
Date Mon, 30 May 2011 20:59:38 GMT
Author: andy
Date: Mon May 30 20:59:37 2011
New Revision: 1129364

URL: http://svn.apache.org/viewvc?rev=1129364&view=rev
Log: (empty)

Added:
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileBuffering.java
  (contents, props changed)
      - copied, changed from r1128951, incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDiskBuffering.java
Removed:
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDiskBuffering.java
Modified:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BufferChannelMem.java
    incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TS_ObjectFile.java
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDisk.java

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java?rev=1129364&r1=1129363&r2=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java Mon May 30 20:59:37 2011
@@ -3,8 +3,11 @@ package tx;
 
 public class DevTx
 {
-    // TestObjectFileTrans
-    // More TestObjectFile tests - write - flush, write some more.
+    // TestObjectFileTrans -- more tests.
+    // TestObjectFileBuffering --> make abstract
+    
+    
+    //    More TestObjectFile tests - write - flush, write some more.
     
     // One transaction dataset - reuse.  Pool?
     //   Create the one transaction dadaset when the datasetgraph itself is created

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java?rev=1129364&r1=1129363&r2=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java Mon May
30 20:59:37 2011
@@ -9,9 +9,11 @@ package tx;
 import org.openjena.atlas.lib.FileOps ;
 
 import com.hp.hpl.jena.tdb.ConfigTest ;
-import com.hp.hpl.jena.tdb.base.file.FileFactory ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannelFile ;
 import com.hp.hpl.jena.tdb.base.file.Location ;
 import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileStorage ;
 
 public class TestObjectFileTransDisk extends AbstractTestObjectFileTrans
 {
@@ -21,8 +23,9 @@ public class TestObjectFileTransDisk ext
         String dir = ConfigTest.getTestingDir() ;
         Location loc = new Location(dir) ;
         String fn = loc.getPath(basename) ;
-        FileOps.delete(fn) ;
-        return FileFactory.createObjectFileDisk(fn) ;
+        FileOps.deleteSilent(fn) ;
+        BufferChannel chan = new BufferChannelFile(fn) ;
+        return new ObjectFileStorage(chan) ;
     }
 
 

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BufferChannelMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BufferChannelMem.java?rev=1129364&r1=1129363&r2=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BufferChannelMem.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/file/BufferChannelMem.java
Mon May 30 20:59:37 2011
@@ -18,6 +18,12 @@ public class BufferChannelMem implements
     private static int INIT_SIZE = 1024 ;
     private static int INC_SIZE = 1024 ;
     
+    
+    public BufferChannelMem()
+    {
+        this("unnamed") ;
+    }
+    
     public BufferChannelMem(String name)
     {
         bytes = ByteBuffer.allocate(1024) ;
@@ -63,8 +69,8 @@ public class BufferChannelMem implements
     public int read(ByteBuffer buffer, long loc)
     {
         checkIfClosed() ;
-        if ( loc < 0 || loc >= buffer.limit() )
-            throw new StorageException("Out of range: "+loc) ;
+        if ( loc < 0 || loc >= bytes.limit() )
+            throw new StorageException("Out of range: "+loc+" [0,"+buffer.limit()+")") ;
         int x = buffer.position() ;
         bytes.position((int)loc) ;
         int len = read(buffer) ;

Modified: incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java?rev=1129364&r1=1129363&r2=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
Mon May 30 20:59:37 2011
@@ -13,7 +13,6 @@ import java.nio.ByteBuffer ;
 import java.util.Iterator ;
 
 import org.openjena.atlas.iterator.Iter ;
-import org.openjena.atlas.lib.Bytes ;
 import org.openjena.atlas.lib.Pair ;
 import org.openjena.atlas.logging.Log ;
 import tx.IteratorSlotted ;
@@ -47,7 +46,6 @@ public class ObjectFileStorage implement
     
     // Delayed write buffer.
     private final ByteBuffer writeBuffer ;
-    private int bufferSize ;
     
     private final BufferChannel file ;              // Access to storage
     private long filesize ;                         // Size of on-disk. 
@@ -65,9 +63,8 @@ public class ObjectFileStorage implement
     public ObjectFileStorage(BufferChannel file, int bufferSize)
     {
         this.file = file ;
-        this.bufferSize = bufferSize ;
         filesize = file.size() ;
-        writeBuffer = ByteBuffer.allocate(bufferSize) ;
+        writeBuffer = (bufferSize >= 0) ? ByteBuffer.allocate(bufferSize) : null ;
     }
     
     @Override
@@ -76,6 +73,12 @@ public class ObjectFileStorage implement
         if ( inAllocWrite )
             Log.fatal(this, "In the middle of an alloc-write") ;
         inAllocWrite = false ;
+        if ( writeBuffer == null )
+        {
+            long x = rawWrite(bb) ;
+            return x ;
+        }
+        
         int len = bb.limit() - bb.position() ;
         int spaceNeeded = len + SizeOfInt ;
         
@@ -101,10 +104,11 @@ public class ObjectFileStorage implement
         lengthBuffer.putInt(len) ;
         lengthBuffer.flip() ;
         long location = file.position() ; 
-        file.write(lengthBuffer, location) ;
-        long loc2 = location+SizeOfInt ;
-        int x = file.write(bb, loc2) ;
-        filesize = filesize+x ;
+        file.write(lengthBuffer) ;
+        int x = file.write(bb) ;
+        if ( x != len )
+            throw new FileException() ;
+        filesize = filesize+x+SizeOfInt ;
         return location ;
     }
     
@@ -116,13 +120,14 @@ public class ObjectFileStorage implement
         
         // Include space for length.
         int spaceRequired = bytesSpace + SizeOfInt ;
+        
         // Find space.
-        if ( spaceRequired > writeBuffer.remaining() )
+        if (  writeBuffer != null && spaceRequired > writeBuffer.remaining() )
             flushOutputBuffer() ;
         
-        if ( spaceRequired > writeBuffer.remaining() )
+        if ( writeBuffer == null || spaceRequired > writeBuffer.remaining() )
         {
-            // Too big. have flushed buffering.
+            // Too big. Have flushed buffering if buffering.
             inAllocWrite = true ;
             ByteBuffer bb = ByteBuffer.allocate(bytesSpace) ;
             allocBlock = new Block(filesize, bb) ;  
@@ -178,6 +183,7 @@ public class ObjectFileStorage implement
 
     private void flushOutputBuffer()
     {
+        if ( writeBuffer == null ) return ;
         if ( writeBuffer.position() == 0 ) return ;
         long location = filesize ;
         writeBuffer.flip();
@@ -229,7 +235,7 @@ public class ObjectFileStorage implement
         }
         
         // No - it's in the underlying file storage.
-        lengthBuffer.position(0) ;
+        lengthBuffer.clear() ;
         int x = file.read(lengthBuffer, loc) ;
         if ( x != 4 )
             throw new FileException("ObjectFile.read: Failed to read the length : got "+x+"
bytes") ;
@@ -245,6 +251,7 @@ public class ObjectFileStorage implement
     @Override
     public long length()
     {
+        if ( writeBuffer == null ) return filesize ; 
         return filesize+writeBuffer.position() ;
     }
 
@@ -262,7 +269,7 @@ public class ObjectFileStorage implement
         ObjectIterator iter = new ObjectIterator(0, filesize) ;
         //return iter ;
         
-        if ( writeBuffer.position() == 0 ) return iter ;
+        if ( writeBuffer == null || writeBuffer.position() == 0 ) return iter ;
         return Iter.concat(iter, new BufferIterator(writeBuffer)) ;
     }
     
@@ -334,32 +341,6 @@ public class ObjectFileStorage implement
         public void remove()
         { throw new UnsupportedOperationException() ; }
     }
-    
-    // ---- Dump
-    public void dump() { dump(handler) ; }
-
-    public interface DumpHandler { void handle(long fileIdx, String str) ; }  
-    
-    public void dump(DumpHandler handler)
-    {
-        file.position(0) ; 
-        long fileIdx = 0 ;
-        while ( fileIdx < filesize )
-        {
-            ByteBuffer bb = read(fileIdx) ;
-            String str = Bytes.fromByteBuffer(bb) ;
-            handler.handle(fileIdx, str) ;
-            fileIdx = fileIdx + bb.limit() + 4 ;
-        }
-    }
-    
-    static DumpHandler handler = new DumpHandler() {
-        @Override
-        public void handle(long fileIdx, String str)
-        {
-            System.out.printf("0x%08X : %s\n", fileIdx, str) ;
-        }
-    } ;
 }
 
 /*

Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TS_ObjectFile.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TS_ObjectFile.java?rev=1129364&r1=1129363&r2=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TS_ObjectFile.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TS_ObjectFile.java
Mon May 30 20:59:37 2011
@@ -13,7 +13,7 @@ import org.junit.runners.Suite ;
 @Suite.SuiteClasses( {
     TestObjectFileMem.class
     , TestObjectFileDisk.class
-    , TestObjectFileDiskBuffering.class
+    , TestObjectFileBuffering.class
     , TestStringFileMem.class 
     , TestStringFileDisk.class 
 })

Copied: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileBuffering.java
(from r1128951, incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDiskBuffering.java)
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileBuffering.java?p2=incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileBuffering.java&p1=incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDiskBuffering.java&r1=1128951&r2=1129364&rev=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDiskBuffering.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileBuffering.java
Mon May 30 20:59:37 2011
@@ -6,31 +6,23 @@
 
 package com.hp.hpl.jena.tdb.base.objectfile;
 
+import static com.hp.hpl.jena.tdb.base.BufferTestLib.sameValue ;
+import static com.hp.hpl.jena.tdb.base.objectfile.AbstractTestObjectFile.fill ;
+
 import java.nio.ByteBuffer ;
 
-import org.junit.AfterClass ;
 import org.junit.Test ;
 import org.openjena.atlas.junit.BaseTest ;
-import org.openjena.atlas.lib.FileOps ;
 
-import com.hp.hpl.jena.tdb.ConfigTest ;
 import com.hp.hpl.jena.tdb.base.block.Block ;
 import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
-import com.hp.hpl.jena.tdb.base.file.BufferChannelFile ;
-
-import static com.hp.hpl.jena.tdb.base.BufferTestLib.* ;
-import static com.hp.hpl.jena.tdb.base.objectfile.AbstractTestObjectFile.fill ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannelMem ;
 
-public class TestObjectFileDiskBuffering extends BaseTest
+public class TestObjectFileBuffering extends BaseTest
 {
-    static String filename = ConfigTest.getTestingDir()+"/test-objectfile" ;
-
-    @AfterClass public static void cleanup() { FileOps.deleteSilent(filename) ; } 
-    
     protected ObjectFile make(int bufferSize)
     {
-        FileOps.deleteSilent(filename) ;
-        BufferChannel chan = new BufferChannelFile(filename) ;
+        BufferChannel chan = new BufferChannelMem() ;
         return new ObjectFileStorage(chan, bufferSize) ;
     }
 
@@ -90,6 +82,10 @@ public class TestObjectFileDiskBuffering
     @Test public void objectfile_57()       { writePrealloc(12, 6, 10) ; }
     @Test public void objectfile_58()       { write(20, 6, 10, 5) ; }
     @Test public void objectfile_59()       { writePrealloc(20, 6, 10, 5) ; }
+
+    @Test public void objectfile_60()       { write(20, 4, 4, 8) ; }
+    @Test public void objectfile_61()       { writePrealloc(20, 4, 4, 8) ; }
+
 }
 
 /*

Propchange: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileBuffering.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDisk.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDisk.java?rev=1129364&r1=1129363&r2=1129364&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDisk.java
(original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/objectfile/TestObjectFileDisk.java
Mon May 30 20:59:37 2011
@@ -24,7 +24,8 @@ public class TestObjectFileDisk extends 
     {
         FileOps.deleteSilent(filename) ;
         BufferChannel chan = new BufferChannelFile(filename) ;
-        return new ObjectFileStorage(chan) ;
+        // No buffering.
+        return new ObjectFileStorage(chan, -1) ;
     }
 }
 



Mime
View raw message