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/30 22:29:31 UTC
svn commit: r1129351 - in /incubator/jena/Experimental/TxTDB/trunk:
src-dev/tx/ src/main/java/com/hp/hpl/jena/tdb/base/objectfile/
Author: andy
Date: Mon May 30 20:29:30 2011
New Revision: 1129351
URL: http://svn.apache.org/viewvc?rev=1129351&view=rev
Log: (empty)
Added:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestObjectFileTrans.java (with props)
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java (with props)
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransMem.java (with props)
Modified:
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/DevTx.java
incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java
incubator/jena/Experimental/TxTDB/trunk/src/main/java/com/hp/hpl/jena/tdb/base/objectfile/ObjectFileStorage.java
Added: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestObjectFileTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestObjectFileTrans.java?rev=1129351&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestObjectFileTrans.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/AbstractTestObjectFileTrans.java Mon May 30 20:29:30 2011
@@ -0,0 +1,127 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package tx;
+
+import java.nio.ByteBuffer ;
+import java.util.Iterator ;
+
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+import org.openjena.atlas.junit.BaseTest ;
+import org.openjena.atlas.lib.Pair ;
+import org.openjena.atlas.lib.StrUtils ;
+
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+
+public abstract class AbstractTestObjectFileTrans extends BaseTest
+{
+ abstract ObjectFile createFile(String basename) ;
+ abstract void deleteFile(String basename) ;
+
+ @Before
+ public void setup()
+ {
+ file1 = createFile("base") ;
+ file2 = createFile("log") ;
+ }
+
+ @After
+ public void teardown()
+ {
+ deleteFile("base") ;
+ deleteFile("log") ;
+ }
+
+ static void write(ObjectFile file, String str)
+ {
+ byte b[] = StrUtils.asUTF8bytes(str) ;
+ ByteBuffer bb = ByteBuffer.wrap(b) ;
+ file.write(bb) ;
+ }
+
+ private static void contains(ObjectFile f, String... contents)
+ {
+ Iterator<Pair<Long, ByteBuffer>> iter = f.all() ;
+ for ( String s : contents )
+ {
+ assertTrue(iter.hasNext()) ;
+ Pair<Long, ByteBuffer> p = iter.next() ;
+ String s2 = StrUtils.fromUTF8bytes(p.cdr().array()) ;
+ assertEquals(s, s2) ;
+ }
+
+ assertFalse(iter.hasNext()) ;
+ }
+
+ ObjectFile file1 ;
+ ObjectFile file2 ;
+ ObjectFileTrans file ;
+
+ private void init() { file = new ObjectFileTrans(null, file1, file2) ; }
+
+ static void fill(ObjectFile file, String... contents)
+ {
+ for ( String s : contents )
+ write(file, s) ;
+ }
+
+ @Test public void objFileTrans_01()
+ {
+ init() ;
+ contains(file) ;
+ }
+
+ @Test public void objFileTrans_02()
+ {
+ fill(file1, "ABC") ;
+ init() ;
+
+ contains(file1, "ABC") ;
+ contains(file2) ;
+ file.commit() ;
+ contains(file1, "ABC") ;
+ }
+
+ @Test public void objFileTrans_03()
+ {
+ fill(file1, "ABC") ;
+ init() ;
+ write(file2, "X") ;
+ file.commit() ;
+ contains(file1, "ABC", "X") ;
+ }
+
+
+}
+
+/*
+ * (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/AbstractTestObjectFileTrans.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1129351&r1=1129350&r2=1129351&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:29:30 2011
@@ -3,12 +3,8 @@ package tx;
public class DevTx
{
- // check test cases.
-
- // ObjectFile
- // ObjectFile over BufferChannel -- "storeage"
- // Hide current mem-based one.
- // Append only with replay.
+ // TestObjectFileTrans
+ // 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/ObjectFileTrans.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java?rev=1129351&r1=1129350&r2=1129351&view=diff
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java (original)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/ObjectFileTrans.java Mon May 30 20:29:30 2011
@@ -11,10 +11,11 @@ import java.util.Iterator ;
import org.openjena.atlas.iterator.Iter ;
import org.openjena.atlas.lib.Pair ;
-import org.openjena.atlas.logging.Log ;
+import org.openjena.atlas.lib.StrUtils ;
import tx.journal.Journal ;
import com.hp.hpl.jena.tdb.base.block.Block ;
+import com.hp.hpl.jena.tdb.base.file.FileException ;
import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
public class ObjectFileTrans implements ObjectFile, Transactional
@@ -81,9 +82,12 @@ public class ObjectFileTrans implements
for ( ; iter.hasNext() ; )
{
Pair<Long, ByteBuffer> p = iter.next() ;
+ String s = StrUtils.fromUTF8bytes(p.getRight().array()) ;
+
long x = base.write(p.getRight()) ;
+
if ( p.getLeft()+startAlloc != x )
- Log.fatal(this, "Expected id of "+p.getLeft()+startAlloc+", got an id of "+x) ;
+ throw new FileException("Expected id of "+(p.getLeft()+startAlloc)+", got an id of "+x) ;
}
}
Added: 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=1129351&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransDisk.java Mon May 30 20:29:30 2011
@@ -0,0 +1,64 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+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.Location ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+
+public class TestObjectFileTransDisk extends AbstractTestObjectFileTrans
+{
+ @Override
+ ObjectFile createFile(String basename)
+ {
+ String dir = ConfigTest.getTestingDir() ;
+ Location loc = new Location(dir) ;
+ String fn = loc.getPath(basename) ;
+ FileOps.delete(fn) ;
+ return FileFactory.createObjectFileDisk(fn) ;
+ }
+
+
+ @Override
+ void deleteFile(String basename)
+ {
+ String dir = ConfigTest.getTestingDir() ;
+ Location loc = new Location(dir) ;
+ String fn = loc.getPath(basename) ;
+ FileOps.delete(fn) ;
+ }
+}
+
+/*
+ * (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/TestObjectFileTransDisk.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransMem.java
URL: http://svn.apache.org/viewvc/incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransMem.java?rev=1129351&view=auto
==============================================================================
--- incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransMem.java (added)
+++ incubator/jena/Experimental/TxTDB/trunk/src-dev/tx/TestObjectFileTransMem.java Mon May 30 20:29:30 2011
@@ -0,0 +1,51 @@
+/*
+ * (c) Copyright 2011 Epimorphics Ltd.
+ * All rights reserved.
+ * [See end of file]
+ */
+
+package tx;
+
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFile ;
+import com.hp.hpl.jena.tdb.base.objectfile.ObjectFileMem ;
+
+public class TestObjectFileTransMem extends AbstractTestObjectFileTrans
+{
+ @Override
+ ObjectFile createFile(String basename)
+ {
+ return new ObjectFileMem() ;
+ }
+
+ @Override
+ void deleteFile(String basename)
+ {}
+
+}
+
+/*
+ * (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/TestObjectFileTransMem.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1129351&r1=1129350&r2=1129351&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:29:30 2011
@@ -12,13 +12,16 @@ import static com.hp.hpl.jena.tdb.sys.Sy
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 ;
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.FileException ;
+import com.hp.hpl.jena.tdb.sys.SystemTDB ;
/** Variable length ByteBuffer file on disk.
* Buffering for delayed writes.
@@ -85,7 +88,7 @@ public class ObjectFileStorage implement
return x ;
}
- long loc = writeBuffer.position() ;
+ long loc = writeBuffer.position()+filesize ;
writeBuffer.putInt(len) ;
writeBuffer.put(bb) ;
return loc ;
@@ -188,7 +191,7 @@ public class ObjectFileStorage implement
{
if ( inAllocWrite )
throw new FileException("In the middle of an alloc-write") ;
- if ( id < 0 || id > filesize )
+ if ( id < 0 || id > length() )
throw new IllegalArgumentException("reposition: Bad location: "+id) ;
flushOutputBuffer() ;
file.truncate(id) ;
@@ -242,7 +245,7 @@ public class ObjectFileStorage implement
@Override
public long length()
{
- return filesize ;
+ return filesize+writeBuffer.position() ;
}
@Override
@@ -254,9 +257,49 @@ public class ObjectFileStorage implement
@Override
public Iterator<Pair<Long, ByteBuffer>> all()
{
+ flushOutputBuffer() ;
file.position(0) ;
ObjectIterator iter = new ObjectIterator(0, filesize) ;
- return iter ;
+ //return iter ;
+
+ if ( writeBuffer.position() == 0 ) return iter ;
+ return Iter.concat(iter, new BufferIterator(writeBuffer)) ;
+ }
+
+ private class BufferIterator extends IteratorSlotted<Pair<Long, ByteBuffer>> implements Iterator<Pair<Long, ByteBuffer>>
+ {
+ private ByteBuffer buffer ;
+ private int posn ;
+
+ public BufferIterator(ByteBuffer buffer)
+ {
+ this.buffer = buffer ;
+ this.posn = 0 ;
+ }
+
+ @Override
+ protected Pair<Long, ByteBuffer> moveToNext()
+ {
+ if ( posn >= buffer.limit() )
+ return null ;
+
+ int x = buffer.getInt(posn) ;
+ posn += SystemTDB.SizeOfInt ;
+ ByteBuffer bb = ByteBuffer.allocate(x) ;
+ int p = buffer.position() ;
+ buffer.position(posn) ;
+ buffer.get(bb.array()) ;
+ buffer.position(p);
+ posn += x ;
+ return new Pair<Long, ByteBuffer>((long)x, bb) ;
+ }
+
+ @Override
+ protected boolean hasMore()
+ {
+ return posn < buffer.limit();
+ }
+
}
private class ObjectIterator implements Iterator<Pair<Long, ByteBuffer>>