You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2011/05/25 15:10:29 UTC

svn commit: r1127513 - in /incubator/jena/Experimental/TxTDB/trunk: src-dev/tx/ src-dev/tx/base/ src-dev/tx/journal/ src/test/java/com/hp/hpl/jena/tdb/base/file/

Author: andy
Date: Wed May 25 13:10:28 2011
New Revision: 1127513

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

Added:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IOBytes.java   (contents, props changed)
      - copied, changed from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/IOBytes.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestIteratorSlotted.java   (with props)
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java   (contents, props changed)
      - copied, changed from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Journal.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/JournalEntry.java   (contents, props changed)
      - copied, changed from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/JournalEntry.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/TestJournal.java   (contents, props changed)
      - copied, changed from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestJournal.java
Removed:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Journal.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestJournal.java
Modified:
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/BlockMgrJournal.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IteratorSlotted.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/BlockRef.java
    incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/FileRef.java
    incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractTestChannel.java

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/BlockMgrJournal.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/BlockMgrJournal.java?rev=1127513&r1=1127512&r2=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/BlockMgrJournal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/BlockMgrJournal.java Wed May 25 13:10:28 2011
@@ -15,6 +15,7 @@ import java.util.Set ;
 
 import org.openjena.atlas.logging.Log ;
 
+import tx.journal.Journal ;
 import tx.transaction.Transaction ;
 
 import com.hp.hpl.jena.tdb.base.block.Block ;
@@ -23,9 +24,9 @@ import com.hp.hpl.jena.tdb.base.block.Bl
 public class BlockMgrJournal implements BlockMgr
 {
     
-    final private BlockMgr blockMgr ; // read-only except during journal checkpoint.
-    final private Journal journal ;
-    final private Transaction transaction ;
+    private BlockMgr blockMgr ; // read-only except during journal checkpoint.
+    private Journal journal ;
+    private Transaction transaction ;
     
     final private Set<Integer> readBlocks = new HashSet<Integer>() ;
     final private Set<Integer> iteratorBlocks = new HashSet<Integer>() ;
@@ -35,13 +36,21 @@ public class BlockMgrJournal implements 
     
     public BlockMgrJournal(Transaction txn, BlockMgr underlyingBlockMgr, Journal journal)
     {
-        this.blockMgr = underlyingBlockMgr ;
-        this.journal = journal ;
-        this.transaction = txn ;
+        reset(txn, underlyingBlockMgr, journal) ;
     }
 
     public Iterator<Block> updatedBlocks()  { return writeBlocks.values().iterator() ; }
     public Iterator<Block> freedBlocks()    { return freedBlocks.values().iterator() ; }
+
+    /** Set, or reset, this BlockMgr.
+     *  Enables it to be reused when already part of a datastructure. 
+     */
+    public void reset(Transaction txn, BlockMgr underlyingBlockMgr, Journal journal)
+    {
+        this.blockMgr = underlyingBlockMgr ;
+        this.journal = journal ;
+        this.transaction = txn ;
+    }
     
     @Override
     public Block allocate(int blockSize)

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=1127513&r1=1127512&r2=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java Wed May 25 13:10:28 2011
@@ -4,6 +4,11 @@ package tx;
 public class DevTx
 {
     // BlockMgrJournal
+    // FileRefs : builtin names<->numbers
+    
+    // NodeTable over Journal.
+    // One transaction dataset - reuse.  Pool?
+    // Record BlockMgrs, BlockMgrTx.reset
     
     // Channel+Adler32
     

Copied: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IOBytes.java (from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/IOBytes.java)
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IOBytes.java?p2=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IOBytes.java&p1=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/IOBytes.java&r1=1127410&r2=1127513&rev=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/IOBytes.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IOBytes.java Wed May 25 13:10:28 2011
@@ -4,7 +4,7 @@
  * [See end of file]
  */
 
-package tx.blockstream;
+package tx;
 
 import java.io.IOException ;
 import java.io.InputStream ;

Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IOBytes.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IteratorSlotted.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IteratorSlotted.java?rev=1127513&r1=1127512&r2=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IteratorSlotted.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/IteratorSlotted.java Wed May 25 13:10:28 2011
@@ -12,12 +12,16 @@ import java.util.NoSuchElementException 
 import com.hp.hpl.jena.sparql.util.Utils ;
 
 /** An Iterator with a one slot lookahead. */  
-abstract class IteratorSlotted<T> implements Iterator<T>
+public abstract class IteratorSlotted<T> implements Iterator<T>
 {
     // Could move in the async abort.
     private boolean finished = false ;
-    private T slot = null ; 
+    private boolean slotIsSet = false ;
+    private T NULL = null ;
+    private T slot = NULL ; 
 
+    private boolean slotIsSet() { return slot != NULL ; } 
+    
     protected IteratorSlotted() { }
 
     // -------- The contract with the subclasses 
@@ -29,7 +33,7 @@ abstract class IteratorSlotted<T> implem
     
     /** Can return true here then null from moveToNext() to indicate end. */ 
     protected abstract boolean hasMore() ;
-    // altter add a flag to say if null is a legal value.
+    // alter add a flag to say if null is a legal value.
     
     /** Close the iterator. */
     protected void closeIterator() { }
@@ -44,8 +48,8 @@ abstract class IteratorSlotted<T> implem
     {
         if ( finished )
             return false ;
-        if ( slot != null )
-            return false ;
+        if ( slotIsSet() )
+            return true ;
 
         boolean r = hasMore() ;
         if ( ! r )
@@ -55,7 +59,9 @@ abstract class IteratorSlotted<T> implem
         }
         
         slot = moveToNext() ;
-        if ( slot == null )
+        slotIsSet = true ;
+        
+        if ( ! slotIsSet() )
         {
             close() ;
             return false ;
@@ -70,16 +76,17 @@ abstract class IteratorSlotted<T> implem
         if ( ! hasNext() ) throw new NoSuchElementException(Utils.className(this)) ;
         
         T obj = slot ;
-        slot = moveToNext() ;
+        slot = null ;
         return obj ;
     }
-    
+
+    /** Look at the next element - returns null when there is no element */
     public final T peek()
     {
+        hasNext() ;
         return slot ;
     }
     
-    
     @Override
     public final void remove()
     {
@@ -91,6 +98,8 @@ abstract class IteratorSlotted<T> implem
         if ( finished )
             return ;
         closeIterator() ;
+        slotIsSet = false ;
+        slot = NULL ;
         finished = true ;
     }
 }

Added: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestIteratorSlotted.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestIteratorSlotted.java?rev=1127513&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestIteratorSlotted.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestIteratorSlotted.java Wed May 25 13:10:28 2011
@@ -0,0 +1,99 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package tx;
+
+import java.util.Arrays ;
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+
+public class TestIteratorSlotted extends BaseTest
+{
+    static class IterStr extends IteratorSlotted<String>
+    {
+        private List<String> array ;
+        private Iterator<String> iter ;
+
+        IterStr(String...array)
+        { 
+            this.array = Arrays.asList(array) ;
+            iter = this.array.iterator() ;
+        }
+        
+        @Override
+        protected String moveToNext()
+        {
+            return iter.next() ;
+        }
+
+        @Override
+        protected boolean hasMore()
+        {
+            return iter.hasNext() ;
+        }
+        
+    }
+    
+    @Test public void iter_01()
+    {
+        IterStr iter = new IterStr() ;
+        assertFalse(iter.hasNext()) ;
+    }
+    
+    @Test public void iter_02()
+    {
+        IterStr iter = new IterStr("A") ;
+        assertTrue(iter.hasNext()) ;
+        assertEquals("A", iter.peek()) ;
+        assertEquals("A", iter.peek()) ;
+        assertEquals("A", iter.next()) ;
+        assertFalse(iter.hasNext()) ;
+        assertNull(iter.peek()) ;
+    }
+    
+    @Test public void iter_03()
+    {
+        IterStr iter = new IterStr("A", "B") ;
+        assertTrue(iter.hasNext()) ;
+        assertEquals("A", iter.peek()) ;
+        assertEquals("A", iter.next()) ;
+        assertEquals("B", iter.peek()) ;
+        assertEquals("B", iter.next()) ;
+        assertFalse(iter.hasNext()) ;
+    }
+    
+    
+}
+
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
\ No newline at end of file

Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestIteratorSlotted.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/BlockRef.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/BlockRef.java?rev=1127513&r1=1127512&r2=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/BlockRef.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/BlockRef.java Wed May 25 13:10:28 2011
@@ -28,6 +28,8 @@ public class BlockRef
     
     public FileRef getFile()        { return file ; }
 
+    public int getFileId()          { return getFile().getId() ; }
+
     public int getBlockId()         { return blockId ; }
 
     @Override

Modified: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/FileRef.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/FileRef.java?rev=1127513&r1=1127512&r2=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/FileRef.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/base/FileRef.java Wed May 25 13:10:28 2011
@@ -6,33 +6,114 @@
 
 package tx.base;
 
+import java.util.HashMap ;
+import java.util.Map ;
+
+import org.openjena.atlas.lib.FileOps ;
+import org.openjena.atlas.lib.Tuple ;
+import org.openjena.atlas.logging.Log ;
+
+import com.hp.hpl.jena.tdb.TDBException ;
+import com.hp.hpl.jena.tdb.sys.Names ;
+
 final
 public class FileRef
 {
     // Symbol<T> ?
     private final String filename ;
+    private final int id ;
+
+    // --------
+    // May to/from names to a short id.
+    // THIS MUST BE PERSISTENT
+    static Map<String, Integer> name2id = new HashMap<String, Integer>() ;
+    static Map<Integer, FileRef> id2name = new HashMap<Integer, FileRef>() ;
+    
+    
+    static {
+        int count = 0 ;
+        for ( String name : Names.tripleIndexes )
+            bTree(name) ;
+        for ( String name : Names.quadIndexes )
+            bTree(name) ;
+        // Not the name of the index.
+//        for ( String name : Names.prefixIndexes )
+//            bTree(name) ;
+        
+        bTree(Names.prefixId2Node) ;
+        bTree(Names.prefixNode2Id) ;
+        file(Names.indexId2Node+".dat") ;
+    }
+
+    private static void bTree(String name)
+    {
+        file(name+".idn") ;
+        file(name+".dat") ;
+    }
+    
+    /** Public - for testing */
+    public static void file(String name)
+    {
+        int count = name2id.size() ;
+        name2id.put(name, count) ;
+        id2name.put(count, new FileRef(name, count)) ;
+    }
+    // --------
+
+    static public FileRef create(String filename)
+    {
+        Tuple<String> x = FileOps.splitDirBaseExt(filename) ;
+        String key = x.get(1) ;
+        if ( ! name2id.containsKey(key) )
+        {
+            Log.warn(FileRef.class, "File name not registered: "+filename) ;
+            file(key) ;
+        }
+            
+        return new FileRef(key, name2id.get(key)) ;
+    }
+    
+    public static FileRef get(int fileId)
+    {
+        FileRef f = id2name.get(fileId) ;
+        if ( f == null )
+        {
+            Log.fatal(FileRef.class, "No FileRef registered for id: "+fileId) ;
+            throw new TDBException("No FileRef registered for id: "+fileId) ;
+        }
+        return f ;
+    }
 
-    static public FileRef create(String symbolStr) { return new FileRef(symbolStr) ; }
-    static public FileRef create(FileRef other) { return new FileRef(other) ; }
+    //    static public FileRef create(FileRef other)
+//    { 
+//        return new FileRef(other) ;
+//    }
     
-    private FileRef(String filename)
+    private FileRef(String filename, int id)
     {
         // Canonicalise filename.
         if ( filename == null )
             throw new IllegalArgumentException("Null for a FileRef filename") ;
         this.filename = filename.intern() ;
+        this.id = id ;
     }
     
-    private FileRef(FileRef other)  { this.filename = other.filename ; }
+    //private FileRef(FileRef other)  { this.filename = other.filename ; this.id = other.id ; }
     
     public String getFilename() { return filename ; }
     
     @Override
+    public String toString()    { return "file:"+filename ; }
+
+    public int getId()          { return id ; }
+
+    @Override
     public int hashCode()
     {
-        final int prime = 37 ;
+        final int prime = 31 ;
         int result = 1 ;
         result = prime * result + ((filename == null) ? 0 : filename.hashCode()) ;
+        result = prime * result + id ;
         return result ;
     }
     
@@ -48,11 +129,9 @@ public class FileRef
             if (other.filename != null) return false ;
         } else
             if (!filename.equals(other.filename)) return false ;
+        if (id != other.id) return false ;
         return true ;
     }
-    
-    @Override
-    public String toString()  { return "file:"+filename ; }
 }
 
 /*

Copied: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java (from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Journal.java)
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java?p2=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java&p1=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Journal.java&r1=1127410&r2=1127513&rev=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/Journal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java Wed May 25 13:10:28 2011
@@ -4,39 +4,41 @@
  * [See end of file]
  */
 
-package tx;
+package tx.journal;
 
 import static com.hp.hpl.jena.tdb.sys.SystemTDB.SizeOfInt ;
 
 import java.nio.ByteBuffer ;
 import java.util.Iterator ;
 
-import tx.blockstream.JournalEntry ;
+import tx.IteratorSlotted ;
+import tx.base.BlockRef ;
+import tx.base.FileRef ;
 
-import com.hp.hpl.jena.tdb.base.file.BlockAccess ;
 import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
-import com.hp.hpl.jena.tdb.base.file.FileBase ;
 
 /** The Journal is slightly odd - it is append-only for write but random read.
- *  The write performance is more important than read. 
+ *  The write performance is more important than read; reads only happen
+ *  if the journal grows to the point where it needs to free up cache. 
  */
 public class Journal
 {
     // Version 1 : issue might be excessive copying
+    // [TxTDB:TODO] Caching
+    // [TxTDB:TODO] Caching
+    
     // We want random access AND stream efficiency to write.  Opps.
     
     // FileOutputStream calls straight to native code
     
     BufferChannel channel ;
-    BlockAccess access ;
-    
-    private FileBase file ;
     private long position ;
-    ByteBuffer buffer = ByteBuffer.allocate(2*SizeOfInt) ;
+    // Length, type, fileref id, block id
+    ByteBuffer buffer = ByteBuffer.allocate(4*SizeOfInt) ;
     
-    public Journal(String filename)
+    public Journal(BufferChannel channel)
     {
-        file = new FileBase(filename) ;
+        this.channel = channel ;
         position = 0 ;
     }
     
@@ -52,14 +54,21 @@ public class Journal
         // length, type, buffer bytes [0,limit())
         
         // Length include length
-        long len = SizeOfInt + SizeOfInt + entry.getByteBuffer().limit() ;
+        long len = 4*SizeOfInt + entry.getByteBuffer().limit() ;
         int type = entry.getType() ;
+        int fileId = entry.getBlockRef().getFileId() ;
+        int blockId = entry.getBlockRef().getBlockId() ;
+        
         // Write length, write type
-        buffer.reset() ;
-        buffer.putInt((int)len, 0) ;
-        buffer.putInt(type, SizeOfInt) ;
+        buffer.clear() ;
+        buffer.putInt((int)len) ;
+        buffer.putInt(type) ;
+        buffer.putInt(fileId) ;
+        buffer.putInt(blockId) ;
+        buffer.rewind() ;
         channel.write(buffer) ;
         
+        entry.getByteBuffer().rewind() ;
         // Write bytes
         channel.write(entry.getByteBuffer()) ;
         
@@ -82,14 +91,21 @@ public class Journal
     private JournalEntry read()
     {
         // [TxTDB:TODO] Make robust against partial read.
-        buffer.reset() ;
+        buffer.clear() ;
         channel.read(buffer) ;
-        int len = buffer.getInt(0) ;
-        len = len - SizeOfInt + SizeOfInt ;
-        int type = buffer.getInt(SizeOfInt) ;
+        buffer.rewind() ;
+        int len = buffer.getInt() ;
+        int type = buffer.getInt() ;
+        int fileId = buffer.getInt() ;
+        int blockId = buffer.getInt() ;
+        FileRef fileRef = FileRef.get(fileId) ;
+        BlockRef blockRef = BlockRef.create(fileRef, blockId) ;
+        
+        len = len - 4*SizeOfInt ;
+        
         ByteBuffer bb = ByteBuffer.allocate(len) ;
         channel.read(bb) ;
-        return new JournalEntry(type, null, bb) ;
+        return new JournalEntry(type, blockRef, bb) ;
     } 
 
     /** Iterator of entries from current point in Journal, going forward. Must be JournalEntry aligned at start. */
@@ -104,7 +120,7 @@ public class Journal
         // See QueryIteratorBase
         public IteratorEntries() 
         {
-            endPoint = channel.length() ;
+            endPoint = channel.size() ;
         }
         
         @Override
@@ -153,7 +169,7 @@ public class Journal
     public Iterator<JournalEntry> entries()
     {
         channel.position(0) ;
-        return new IteratorEntries() {} ;
+        return new IteratorEntries() ;
     }
     
 }

Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/Journal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/JournalEntry.java (from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/JournalEntry.java)
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/JournalEntry.java?p2=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/JournalEntry.java&p1=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/JournalEntry.java&r1=1127410&r2=1127513&rev=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/blockstream/JournalEntry.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/JournalEntry.java Wed May 25 13:10:28 2011
@@ -4,10 +4,12 @@
  * [See end of file]
  */
 
-package tx.blockstream;
+package tx.journal;
 
 import java.nio.ByteBuffer ;
 
+import org.openjena.atlas.logging.Log ;
+
 import tx.base.BlockRef ;
 
 public class JournalEntry
@@ -24,13 +26,20 @@ public class JournalEntry
     
     public JournalEntry(int type, BlockRef blockRef, ByteBuffer bytes)
     {
+        if ( type == 0 )
+            Log.warn(this, "Journal entry with type = 0") ;
+        if ( blockRef == null )
+            Log.warn(this, "Journal entry with blockRef = null") ;
+        if ( bytes == null )
+            Log.warn(this, "Journal entry with bytes = null") ;
+        
         this.type = type ;
         this.fileReference = blockRef ;
         this.byteBuffer = bytes ;
     }
 
     public int getType()                { return type ; }
-    public BlockRef getFileRef()        { return fileReference ; }
+    public BlockRef getBlockRef()       { return fileReference ; }
     public ByteBuffer getByteBuffer()   { return byteBuffer ; }
 }
 

Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/JournalEntry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/TestJournal.java (from r1127410, incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestJournal.java)
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/TestJournal.java?p2=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/TestJournal.java&p1=incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestJournal.java&r1=1127410&r2=1127513&rev=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestJournal.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/TestJournal.java Wed May 25 13:10:28 2011
@@ -4,14 +4,128 @@
  * [See end of file]
  */
 
-package tx;
+package tx.journal;
 
+import java.nio.ByteBuffer ;
+import java.util.Iterator ;
+
+import com.hp.hpl.jena.tdb.base.file.BufferChannel ;
+import com.hp.hpl.jena.tdb.base.file.BufferChannelMem ;
+
+import org.junit.Before ;
 import org.junit.Test ;
 import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.atlas.lib.Bytes ;
+import org.openjena.atlas.lib.Lib ;
+import tx.base.BlockRef ;
+import tx.base.FileRef ;
 
 public class TestJournal extends BaseTest
 {
-    @Test public void journal_01() { }
+    static {
+        FileRef.file("xyz") ;
+        FileRef.file("abc") ;
+    }
+    
+    // bb1 and bb2 have the same contents and different contents to bb3.
+    static ByteBuffer bb1 = ByteBuffer.allocate(4) ;
+    static ByteBuffer bb2 = ByteBuffer.allocate(4) ;
+    static ByteBuffer bb3 = ByteBuffer.allocate(4) ;
+    
+    static BlockRef blockref1 = BlockRef.create("xyz", 10) ;
+    static BlockRef blockref2 = BlockRef.create("xyz", 10) ;
+
+    static BlockRef blockref3 = BlockRef.create("xyz", 20) ;
+    static BlockRef blockref4 = BlockRef.create("abc", 10) ;
+    
+    // [TxTDB:TODO] Use these 
+    static JournalEntry je1 = new JournalEntry(10, blockref1, bb1) ;
+    static JournalEntry je2 = new JournalEntry(10, blockref2, bb2) ;
+    static JournalEntry je3 = new JournalEntry(10, blockref3, bb3) ;
+    static JournalEntry je4 = new JournalEntry(20, blockref1, bb1) ;
+    
+    static
+    {
+        Bytes.setInt(0xABCD1234, bb1.array()) ;
+        Bytes.setInt(0xABCD1234, bb2.array()) ;
+        Bytes.setInt(0x11111111, bb3.array()) ;
+    }
+    
+    Journal journal ;
+    @Before public void before()
+    {
+        BufferChannel mem = new BufferChannelMem("journal") ;
+        journal = new Journal(mem) ;
+    }
+    
+    @Test public void journal_01()
+    {
+        assertFalse(journal.entries().hasNext()) ;
+    }
+    
+    @Test public void journal_02()
+    {
+        JournalEntry entry1 = new JournalEntry(99, blockref1, bb1) ;
+        long x = journal.writeJournal(entry1) ;
+        assertEquals(0, x) ;
+        JournalEntry entry9 = journal.readJournal(x) ;
+        assertTrue(equal(entry1, entry9)) ;
+    }
+
+    @Test public void journal_03()
+    {
+        JournalEntry entry1 = new JournalEntry(99, blockref1, bb1) ;
+        JournalEntry entry2 = new JournalEntry(13, blockref1, bb2) ;
+        
+        long x1 = journal.writeJournal(entry1) ;
+        long x2 = journal.writeJournal(entry2) ;
+        assertEquals(0, x1) ;
+        assertNotEquals(0, x2) ;
+        
+        JournalEntry entry1a = journal.readJournal(x1) ;
+        JournalEntry entry2a = journal.readJournal(x2) ;
+        
+        assertNotSame(entry1, entry1a) ;
+        assertNotSame(entry2, entry2a) ;
+        assertTrue(equal(entry1, entry1a)) ;
+        assertTrue(equal(entry2, entry2a)) ;
+        assertFalse(equal(entry1a, entry2a)) ;
+    }
+    
+    @Test public void journal_04()
+    {
+        JournalEntry entry1 = new JournalEntry(99, blockref1, bb1) ;
+        JournalEntry entry2 = new JournalEntry(99, blockref2, bb1) ;
+        
+        long x1 = journal.writeJournal(entry1) ;
+        long x2 = journal.writeJournal(entry2) ;
+        
+        Iterator<JournalEntry> iter = journal.entries() ;
+        JournalEntry entry1a = iter.next();
+        JournalEntry entry2a = iter.next();
+        assertFalse(iter.hasNext()) ;
+        
+    }
+
+    private static boolean equal(JournalEntry entry1, JournalEntry entry2)
+    {
+        if ( entry1.getType() != entry2.getType()) return false ;
+        if ( ! Lib.equal(entry1.getBlockRef(), entry2.getBlockRef()) ) return false ;
+        return sameValue(entry1.getByteBuffer(), entry2.getByteBuffer()) ;
+    }
+    
+    // In ByteBufferLib - remove/migrate
+    public static boolean sameValue(ByteBuffer bb1, ByteBuffer bb2)
+    {
+        if ( bb1.capacity() != bb2.capacity() ) return false ;
+        
+        for ( int i = 0 ; i < bb1.capacity() ; i++ )
+            if ( bb1.get(i) != bb2.get(i) ) return false ;
+        return true ;
+    }
+
+
+    
 }
 
 /*

Propchange: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/journal/TestJournal.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractTestChannel.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractTestChannel.java?rev=1127513&r1=1127512&r2=1127513&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractTestChannel.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src/test/java/com/hp/hpl/jena/tdb/base/file/AbstractTestChannel.java Wed May 25 13:10:28 2011
@@ -21,7 +21,7 @@ public abstract class AbstractTestChanne
     @Test public void storage_01() 
     {
         BufferChannel store = make() ;
-        assertEquals(0, store.length()) ;
+        assertEquals(0, store.size()) ;
     }
     
     protected static ByteBuffer data(int len)
@@ -49,7 +49,7 @@ public abstract class AbstractTestChanne
         BufferChannel store = make() ;
         ByteBuffer b = data(blkSize) ;
         store.write(b) ;
-        long x = store.length() ;
+        long x = store.size() ;
         assertEquals(blkSize, x) ;
     }
 
@@ -74,7 +74,7 @@ public abstract class AbstractTestChanne
         store.write(b2, 0) ;
         store.write(b1, 0) ;
         
-        assertEquals(blkSize, store.length()) ;
+        assertEquals(blkSize, store.size()) ;
         ByteBuffer b9 = ByteBuffer.allocate(5) ;
         int z = store.read(b9) ;
         assertEquals(5, z) ;