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 2017/10/03 19:34:15 UTC
[29/65] [abbrv] jena git commit: JENA-1397: Rename java packages
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTree.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTree.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTree.java
new file mode 100644
index 0000000..497d43e
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTree.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.bplustree.soak;
+
+import org.apache.jena.dboe.base.file.BlockAccessMem;
+import org.apache.jena.dboe.index.test.BaseSoakTest;
+import org.apache.jena.dboe.index.test.IndexTestLib;
+import org.apache.jena.dboe.sys.Sys;
+import org.apache.jena.dboe.sys.SystemIndex;
+import org.apache.jena.dboe.trans.bplustree.BPT;
+import org.apache.jena.dboe.trans.bplustree.BPlusTree;
+import org.apache.jena.dboe.trans.bplustree.BPlusTreeFactory;
+import org.apache.jena.dboe.trans.bplustree.BlockTracker;
+
+public class CmdTestBPlusTree extends BaseSoakTest
+{
+ static public void main(String... argv) {
+ //argv = new String[] {"50", "150", "1000000"} ;
+// System.setProperty("bpt:checking", "false") ;
+// System.setProperty("bpt:duplication", "true") ;
+ new CmdTestBPlusTree(argv).mainRun() ;
+ }
+
+ protected CmdTestBPlusTree(String[] argv) {
+ super(argv) ;
+ }
+
+ @Override
+ protected void before() {
+ SystemIndex.setNullOut(true) ;
+ BlockTracker.collectHistory = false ;
+ // Forced mode
+ if ( true ) {
+ BlockAccessMem.SafeMode = true ;
+ BPT.CheckingNode = trueOrFalse("bpt:checking", false) ;
+ boolean duplication = trueOrFalse("bpt:duplication", false) ;
+ BPT.forcePromoteModes = true ;
+ BPT.promoteDuplicateNodes = duplication ;
+ BPT.promoteDuplicateRecords = duplication ;
+ }
+ if ( false ) {
+ // Transactions.
+ }
+
+ System.out.printf(" BPT.CheckingNode = %s\n", BPT.CheckingNode) ;
+ System.out.printf(" BPT.forcePromoteModes = %s\n", BPT.forcePromoteModes) ;
+ System.out.printf(" BPT.promoteDuplicateNodes = %s\n", BPT.promoteDuplicateRecords) ;
+ System.out.printf(" BPT.promoteDuplicateRecords = %s\n", BPT.promoteDuplicateRecords) ;
+ }
+
+ private boolean trueOrFalse(String property, boolean dftValue) {
+ String s = System.getProperty(property) ;
+ if ( s == null )
+ return dftValue ;
+ if ( s.equalsIgnoreCase("true") || s.equalsIgnoreCase("T") || s.equalsIgnoreCase("1") )
+ return true ;
+ if ( s.equalsIgnoreCase("false") || s.equalsIgnoreCase("F") || s.equalsIgnoreCase("0") )
+ return false ;
+ System.err.println("Not recognized: "+property+"="+s);
+ return dftValue ;
+ }
+
+ @Override
+ protected void after() {}
+
+ @Override
+ protected void runOneTest(int testCount, int order, int size, boolean debug) {
+ runOneTest(testCount, order, size) ;
+ }
+
+ @Override
+ protected void runOneTest(int testCount, int order, int size) {
+// //System.err.println("runOneTest("+order+","+size+")") ;
+ BPlusTree bpt = BPlusTreeFactory.makeMem(order, Sys.SizeOfInt, 0) ;
+ bpt = BPlusTreeFactory.addTracking(bpt) ;
+ bpt.nonTransactional() ;
+ IndexTestLib.randTest(bpt, 5*size, size, true);
+ bpt.close() ;
+
+ // Transaction.
+// BPlusTree bpt = BPlusTreeFactory.makeMem(order, SystemLz.SizeOfInt, 0) ;
+// Journal journal = Journal.create(Location.mem()) ;
+// Transactional holder = TransactionalFactory.create(journal, bpt) ;
+// holder.begin(ReadWrite.WRITE);
+// IndexTestLib.randTest(bpt, 5*size, size, true);
+// holder.commit() ;
+// holder.end() ;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTreeRewriter.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTreeRewriter.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTreeRewriter.java
new file mode 100644
index 0000000..c0ee77a
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/bplustree/soak/CmdTestBPlusTreeRewriter.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.bplustree.soak;
+
+import org.apache.jena.dboe.base.record.RecordFactory;
+import org.apache.jena.dboe.index.test.BaseSoakTest;
+import org.apache.jena.dboe.sys.SystemIndex;
+import org.apache.jena.dboe.trans.bplustree.BPT;
+import org.apache.jena.dboe.trans.bplustree.rewriter.TestBPlusTreeRewriterNonTxn;
+
+public class CmdTestBPlusTreeRewriter extends BaseSoakTest
+{
+ static public void main(String... argv) {
+ new CmdTestBPlusTreeRewriter(argv).mainRun() ;
+ }
+
+ protected CmdTestBPlusTreeRewriter(String[] argv) {
+ super(argv) ;
+ }
+
+ static int KeySize = 4 ;
+ static int ValueSize = 8 ;
+
+ @Override
+ protected void before() {
+ SystemIndex.setNullOut(true) ;
+ // Forced mode
+ if ( false ) {
+ BPT.forcePromoteModes = true ;
+ BPT.promoteDuplicateNodes = true ;
+ BPT.promoteDuplicateRecords = true ;
+ }
+ if ( false ) {
+ // Transactions.
+ }
+ }
+
+ @Override
+ protected void after() { }
+
+ @Override
+ protected void runOneTest(int testCount, int order, int size, boolean debug) {
+ runOneTest(testCount, order, size) ;
+ }
+
+ @Override
+ protected void runOneTest(int testCount, int order, int size) {
+ RecordFactory recordFactory = new RecordFactory(KeySize, ValueSize) ;
+ TestBPlusTreeRewriterNonTxn.runOneTest(order, size, recordFactory, false) ;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TS_TransData.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TS_TransData.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TS_TransData.java
new file mode 100644
index 0000000..4a86339
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TS_TransData.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.data;
+
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+import org.junit.runners.Suite.SuiteClasses ;
+
+@RunWith(Suite.class)
+@SuiteClasses( {
+ TestTransIndexMem.class
+ , TestTransBlob.class
+ , TestTransBlobPersistent.class
+ , TestTransBinaryDataFileGeneral.class
+ , TestTransBinaryDataFile.class
+})
+
+public class TS_TransData { }
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFile.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFile.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFile.java
new file mode 100644
index 0000000..d30f75d
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFile.java
@@ -0,0 +1,221 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.data;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import org.apache.jena.atlas.lib.Bytes ;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.dboe.base.file.*;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.dboe.trans.data.TransBinaryDataFile;
+import org.apache.jena.dboe.transaction.ThreadTxn;
+import org.apache.jena.dboe.transaction.Transactional;
+import org.apache.jena.dboe.transaction.TransactionalFactory;
+import org.apache.jena.dboe.transaction.txn.ComponentId;
+import org.apache.jena.dboe.transaction.txn.journal.Journal;
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+
+public class TestTransBinaryDataFile {
+ private Journal journal ;
+ private BinaryDataFile baseBinData ;
+ private TransBinaryDataFile transBinData ;
+ private Transactional transactional ;
+
+ @Before public void before() {
+ // XXX Builder.
+ journal = Journal.create(Location.mem()) ;
+ baseBinData = new BinaryDataFileMem() ;
+ BufferChannel chan = FileFactory.createBufferChannelMem() ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ transBinData = new TransBinaryDataFile(baseBinData, cid, chan) ;
+ transBinData.open();
+ transactional = TransactionalFactory.createTransactional(journal, transBinData) ;
+ }
+
+ @After public void after() { }
+
+// private static ByteBuffer str2bb(String x) {
+// byte[] d = StrUtils.asUTF8bytes(x) ;
+// ByteBuffer bb = ByteBuffer.wrap(d) ;
+// return bb ;
+// }
+
+ private static long writeOne(Transactional transactional, TransBinaryDataFile transBinaryFile, String data) {
+ return
+ Txn.calculateWrite(transactional, ()->{
+ byte[] bytes = StrUtils.asUTF8bytes(data) ;
+ int len = bytes.length ;
+ byte[] lenBytes = new byte[4] ;
+ Bytes.setInt(len, lenBytes);
+ // To work with strings, we write length,bytes.
+ long x = transBinaryFile.write(lenBytes);
+ transBinaryFile.write(bytes);
+ return x ;
+ }) ;
+ }
+
+ private static String readOne(Transactional transactional, TransBinaryDataFile transBinaryFile, long posn) {
+ return Txn.calculateRead(transactional, ()->{
+ byte[] lenBytes = new byte[4] ;
+ long x = posn ;
+ int got = transBinaryFile.read(x, lenBytes) ;
+ x += got ;
+
+ int len = Bytes.getInt(lenBytes) ;
+ byte[] bytes = new byte[len] ;
+ got = transBinaryFile.read(x, bytes) ;
+ x += got ;
+ return StrUtils.fromUTF8bytes(bytes) ;
+ }) ;
+ }
+
+ @Test public void transObjectFile_str1() {
+ String str = "Hello World" ;
+ long x = writeOne(transactional, transBinData, str) ;
+ String str2 = readOne(transactional, transBinData, x) ;
+ assertEquals(str, str2) ;
+ }
+
+ @Test public void transObjectFile_str2() {
+ String str1 = "" ;
+ String str2 = "$" ;
+ long x1 = writeOne(transactional, transBinData, str1) ;
+ long x2 = writeOne(transactional, transBinData, str2) ;
+ assertNotEquals("("+x1+","+x2+")", x1, x2) ;
+
+ String out2 = readOne(transactional, transBinData, x2) ;
+ String out1 = readOne(transactional, transBinData, x1) ;
+ assertEquals(str1, out1) ;
+ assertEquals(str2, out2) ;
+ }
+
+ static byte[] bytes0 = new byte[0] ;
+ static int len0 = 0 ;
+
+ static byte[] bytes1 = new byte[] {(byte)1,(byte)2,(byte)3} ;
+ static int len1 = bytes1.length ;
+
+ static byte[] bytes2 = StrUtils.asUTF8bytes("TheNext") ;
+ static int len2 = bytes2.length ;
+
+
+ @Test public void transObjectFile_1() {
+ Txn.executeWrite(transactional, ()->{
+ long x = transBinData.write(bytes1) ;
+ assertEquals(0L, x) ;
+ assertEquals(len1, transBinData.length()) ;
+ }) ;
+ }
+
+ @Test public void transObjectFile_2() {
+ Txn.executeWrite(transactional, ()->{
+ long x = transBinData.write(bytes1) ;
+ assertEquals(0L, x) ;
+ assertEquals(len1, transBinData.length()) ;
+ byte[] bytes1a = new byte[len1] ;
+ int len = transBinData.read(0, bytes1a) ;
+ assertEquals(len1, len) ;
+ assertArrayEquals(bytes1, bytes1a);
+ }) ;
+ }
+
+ @Test public void transObjectFile_3() {
+ Txn.executeWrite(transactional, ()->{
+ long x1 = transBinData.write(bytes1) ;
+ long x2 = transBinData.write(bytes2) ;
+ byte[] bytes1a = new byte[len1] ;
+ byte[] bytes2a = new byte[len2] ;
+ int len1a = transBinData.read(0, bytes1a) ;
+ int len2a = transBinData.read(len1a, bytes2a) ;
+ assertEquals(len1, len1a) ;
+ assertArrayEquals(bytes1, bytes1a);
+ assertEquals(len2, len2a) ;
+ assertArrayEquals(bytes2, bytes2a);
+ }) ;
+ }
+
+ @Test public void transObjectFile_4() {
+ Txn.executeWrite(transactional, ()->{
+ long x1 = transBinData.write(bytes1) ;
+ long x2 = transBinData.write(bytes2) ;
+ }) ;
+ Txn.executeRead(transactional, ()->{
+ byte[] bytes1a = new byte[len1] ;
+ byte[] bytes2a = new byte[len2] ;
+ int len1a = transBinData.read(0, bytes1a) ;
+ int len2a = transBinData.read(len1a, bytes2a) ;
+ assertEquals(len1, len1a) ;
+ assertArrayEquals(bytes1, bytes1a);
+ assertEquals(len2, len2a) ;
+ assertArrayEquals(bytes2, bytes2a);
+ }) ;
+ }
+
+ // As above but reverse the read order
+ @Test public void transObjectFile_5() {
+ Txn.executeWrite(transactional, ()->{
+ long x1 = transBinData.write(bytes1) ;
+ long x2 = transBinData.write(bytes2) ;
+ }) ;
+ Txn.executeRead(transactional, ()->{
+ byte[] bytes1a = new byte[len1] ;
+ byte[] bytes2a = new byte[len2] ;
+
+ int len2a = transBinData.read(len1, bytes2a) ;
+ int len1a = transBinData.read(0, bytes1a) ;
+
+ assertEquals(len1, len1a) ;
+ assertArrayEquals(bytes1, bytes1a);
+ assertEquals(len2, len2a) ;
+ assertArrayEquals(bytes2, bytes2a);
+ }) ;
+ }
+
+
+ @Test public void transObjectFile_6() {
+ Txn.executeWrite(transactional, ()->{
+ long x1 = transBinData.write(bytes1) ;
+ long x2 = transBinData.write(bytes2) ;
+ }) ;
+ Txn.executeRead(transactional, ()->{
+ byte[] bytes2a = new byte[len2] ;
+ int len2a = transBinData.read(len1, bytes2a) ;
+ assertEquals(len2, len2a) ;
+ assertArrayEquals(bytes2, bytes2a);
+ }) ;
+ }
+
+ @Test public void transObjectFile_7() {
+ ThreadTxn.threadTxnWriteAbort(transactional, ()->{
+ long x1 = transBinData.write(bytes1) ;
+ }) ;
+
+ Txn.executeRead(transactional, ()->{
+ assertEquals(0L, transBinData.length()) ;
+ }) ;
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFileGeneral.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFileGeneral.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFileGeneral.java
new file mode 100644
index 0000000..2804286
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBinaryDataFileGeneral.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.data;
+
+import org.apache.jena.dboe.base.file.*;
+import org.apache.jena.dboe.trans.data.TransBinaryDataFile;
+import org.apache.jena.dboe.transaction.Transactional;
+import org.apache.jena.dboe.transaction.TransactionalFactory;
+import org.apache.jena.dboe.transaction.txn.ComponentId;
+import org.apache.jena.dboe.transaction.txn.journal.Journal;
+import org.apache.jena.query.ReadWrite ;
+
+public class TestTransBinaryDataFileGeneral extends AbstractTestBinaryDataFile {
+ private Journal journal ;
+ private BinaryDataFile baseBinData ;
+ private TransBinaryDataFile transBinData ;
+ private Transactional transactional ;
+
+ @Override
+ protected BinaryDataFile createBinaryDataFile() {
+ // XXX Builder.
+ journal = Journal.create(Location.mem()) ;
+ baseBinData = new BinaryDataFileMem() ;
+ BufferChannel chan = FileFactory.createBufferChannelMem() ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ transBinData = new TransBinaryDataFile(baseBinData, cid, chan) ;
+ transBinData.open();
+ transactional = TransactionalFactory.createTransactional(journal, transBinData) ;
+ //Non-transactional usage of a disposed file.
+ transactional.begin(ReadWrite.WRITE) ;
+ return transBinData ;
+
+ }
+
+ @Override
+ protected void releaseBinaryDataFile(BinaryDataFile file) {
+ if ( file.isOpen() ) {
+ transactional.commit() ;
+ transactional.end() ;
+ baseBinData.close() ;
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlob.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlob.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlob.java
new file mode 100644
index 0000000..e22929c
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlob.java
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.data;
+
+import java.util.concurrent.atomic.AtomicReference ;
+
+import org.apache.jena.dboe.base.file.BufferChannel;
+import org.apache.jena.dboe.base.file.BufferChannelMem;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.dboe.trans.data.TransBlob;
+import org.apache.jena.dboe.transaction.ThreadTxn;
+import org.apache.jena.dboe.transaction.Transactional;
+import org.apache.jena.dboe.transaction.TransactionalFactory;
+import org.apache.jena.dboe.transaction.txn.ComponentId;
+import org.apache.jena.dboe.transaction.txn.journal.Journal;
+import org.apache.jena.query.ReadWrite ;
+import org.junit.After ;
+import org.junit.Assert ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+public class TestTransBlob extends Assert {
+ private Journal journal ;
+ private TransBlob transBlob ;
+ private Transactional transactional ;
+
+ @Before public void before() {
+ journal = Journal.create(Location.mem()) ;
+
+ BufferChannel chan = BufferChannelMem.create("TestTransBlob") ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ transBlob = new TransBlob(cid, chan) ;
+ transactional = TransactionalFactory.createTransactional(journal, transBlob) ;
+ }
+
+ @After public void after() { }
+
+ public static void write(Transactional transactional, TransBlob transBlob, String data) {
+ Txn.executeWrite(transactional, ()->{
+ transBlob.setString(data);
+ }) ;
+ }
+
+ public static String read(Transactional transactional, TransBlob transBlob) {
+ return Txn.calculateRead(transactional, ()->{
+ return transBlob.getString() ;
+ }) ;
+ }
+
+ void threadRead(String expected) {
+ AtomicReference<String> result = new AtomicReference<>() ;
+ ThreadTxn.threadTxnRead(transactional, ()-> {
+ String s = transBlob.getString() ;
+ result.set(s);
+ }).run();
+ Assert.assertEquals(expected, result.get());
+ }
+
+ // testing with real files in TestTransBlobPersistent
+
+ @Test public void transBlob_1() {
+ String str = "Hello World" ;
+ write(transactional, transBlob, str) ;
+ String str2 = read(transactional, transBlob) ;
+ assertEquals(str, str2) ;
+ String str3 = transBlob.getString() ;
+ assertEquals(str, str3) ;
+
+ }
+
+ // Verify visibility and transactions.
+ @Test public void transBlob_2() {
+ String str1 = "one" ;
+ String str2 = "two" ;
+ write(transactional, transBlob, str1) ;
+ transactional.begin(ReadWrite.WRITE);
+ transBlob.setString(str2);
+
+ // Difefrent therad and transaction.
+ threadRead(str1) ;
+
+ transactional.commit() ;
+ transactional.end() ;
+ threadRead(str2) ;
+ }
+
+ // Verify visibility and transactions.
+ @Test public void transBlob_3() {
+ String str1 = "one" ;
+ String str2 = "two" ;
+ write(transactional, transBlob, str1) ;
+ String s1 = transBlob.getString() ;
+ assertEquals(str1, s1) ;
+ String s2 = read(transactional, transBlob) ;
+ assertEquals(str1, s2) ;
+
+ // Start now.
+ ThreadTxn tt = ThreadTxn.threadTxnRead(transactional, ()-> {
+ String sr = transBlob.getString() ;
+ Assert.assertEquals(str1, sr) ;
+ }) ;
+
+ write(transactional, transBlob, str2) ;
+
+ Txn.executeWrite(transactional, ()->{
+ transBlob.setString(str2) ;
+ String s = transBlob.getString() ;
+ assertEquals(str2, s) ;
+ }) ;
+ // Run later, after W transaction.
+ tt.run();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlobPersistent.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlobPersistent.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlobPersistent.java
new file mode 100644
index 0000000..fe8e3bb
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransBlobPersistent.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.data;
+
+import org.apache.jena.util.FileUtils ;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.dboe.base.file.BufferChannel;
+import org.apache.jena.dboe.base.file.BufferChannelFile;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.dboe.trans.data.TransBlob;
+import org.apache.jena.dboe.transaction.Transactional;
+import org.apache.jena.dboe.transaction.TransactionalFactory;
+import org.apache.jena.dboe.transaction.txn.ComponentId;
+import org.apache.jena.dboe.transaction.txn.journal.Journal;
+import org.junit.* ;
+
+public class TestTransBlobPersistent extends Assert {
+ private final static String DIR = "target/blobtest" ;
+ private final static String JRNL = DIR+"/journal.jrnl" ;
+ private final static String DATA = DIR+"/blob.data" ;
+
+ @BeforeClass public static void beforeClass() {
+ FileOps.ensureDir(DIR);
+ }
+
+ @Before public void before() {
+ FileOps.deleteSilent(JRNL) ;
+ FileOps.deleteSilent(DATA) ;
+ }
+
+ @AfterClass public static void afterClass() {
+ FileOps.deleteSilent(JRNL) ;
+ FileOps.deleteSilent(DATA) ;
+ }
+
+ @Test public void transBlobFile_1() throws Exception {
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ BufferChannel chan = BufferChannelFile.create(DATA) ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ TransBlob transBlob = new TransBlob(cid, chan) ;
+ Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ;
+ String str = "Hello" ;
+
+ TestTransBlob.write(transactional, transBlob, str) ;
+
+ chan.close() ;
+ journal.close() ;
+ String s = FileUtils.readWholeFileAsUTF8(DATA) ;
+ assertEquals(str, s);
+ }
+
+ @Test public void transBlobFile_2() throws Exception {
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ BufferChannel chan = BufferChannelFile.create(DATA) ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ TransBlob transBlob = new TransBlob(cid, chan) ;
+ Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ;
+ String str = "Hello1" ;
+
+ Txn.executeWrite(transactional, ()->{
+ transBlob.setString("one");
+ }) ;
+
+ Txn.executeWrite(transactional, ()->{
+ transBlob.setString("two");
+ }) ;
+
+ chan.close() ;
+ journal.close() ;
+ String s = FileUtils.readWholeFileAsUTF8(DATA) ;
+ assertEquals("two", s);
+ }
+
+ // restart.
+ @Test public void transBlobFile_3() throws Exception {
+ String str = "Hello World" ;
+ // Write out.
+ {
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ BufferChannel chan = BufferChannelFile.create(DATA) ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ TransBlob transBlob = new TransBlob(cid, chan) ;
+ Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ;
+ TestTransBlob.write(transactional, transBlob, str) ;
+ chan.close();
+ journal.close();
+ }
+ // Restart
+ {
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ BufferChannel chan = BufferChannelFile.create(DATA) ;
+ ComponentId cid = ComponentId.allocLocal() ;
+ TransBlob transBlob = new TransBlob(cid, chan) ;
+ Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob) ;
+ String s = TestTransBlob.read(transactional, transBlob) ;
+ assertEquals(str, s);
+ }
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransIndexMem.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransIndexMem.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransIndexMem.java
new file mode 100644
index 0000000..3b48411
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/data/TestTransIndexMem.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.data;
+
+import org.apache.jena.dboe.base.record.RecordFactory;
+import org.apache.jena.dboe.index.Index;
+import org.apache.jena.dboe.index.IndexMap;
+import org.apache.jena.dboe.index.test.AbstractTestIndex;
+
+public class TestTransIndexMem extends AbstractTestIndex
+{
+ @Override
+ protected Index makeIndex(int kLen, int vLen)
+ {
+ RecordFactory rf = new RecordFactory(kLen, vLen) ;
+ return new IndexMap(rf) ;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/recovery/TestRecovery.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/recovery/TestRecovery.java b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/recovery/TestRecovery.java
new file mode 100644
index 0000000..9c5aab7
--- /dev/null
+++ b/jena-db/jena-dboe-trans-data/src/test/java/org/apache/jena/dboe/trans/recovery/TestRecovery.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.dboe.trans.recovery;
+
+import java.nio.ByteBuffer ;
+import java.util.Arrays ;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.dboe.base.file.BufferChannel;
+import org.apache.jena.dboe.base.file.BufferChannelFile;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.migrate.L;
+import org.apache.jena.dboe.trans.data.TransBlob;
+import org.apache.jena.dboe.transaction.txn.ComponentId;
+import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
+import org.apache.jena.dboe.transaction.txn.journal.Journal;
+import org.apache.jena.dboe.transaction.txn.journal.JournalEntry;
+import org.apache.jena.dboe.transaction.txn.journal.JournalEntryType;
+import org.junit.* ;
+
+// We need something to recover io order to test recovery.
+
+public class TestRecovery extends Assert {
+ private final static String DIR = "target/recovery" ;
+ private final static String JRNL = DIR + "/journal.jrnl" ;
+ private final static String DATA = DIR + "/blob.data" ;
+ private final static String DATA1 = DIR + "/blob.data-1" ;
+ private final static String DATA2 = DIR + "/blob.data-2" ;
+
+ @BeforeClass public static void beforeClass() {
+ FileOps.ensureDir(DIR);
+ }
+
+ @Before public void before() {
+ FileOps.deleteSilent(JRNL) ;
+ FileOps.deleteSilent(DATA) ;
+ FileOps.deleteSilent(DATA1) ;
+ FileOps.deleteSilent(DATA2) ;
+ }
+
+ @AfterClass public static void afterClass() {
+ FileOps.deleteSilent(JRNL) ;
+ FileOps.deleteSilent(DATA) ;
+ }
+
+ // Fake journal recovery.
+ @Test public void recoverBlobFile_1() throws Exception {
+ String str = "Hello Journal" ;
+ ComponentId cid = ComponentId.allocLocal() ;
+// ComponentIdRegistry registry = new ComponentIdRegistry() ;
+// registry.register(cid, "Blob", 1) ;
+
+ // Write out a journal.
+ {
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ journal.write(JournalEntryType.REDO, cid, L.stringToByteBuffer(str)) ;
+ journal.writeJournal(JournalEntry.COMMIT) ;
+ journal.close();
+ }
+
+ TransactionCoordinator coord = new TransactionCoordinator(Location.create(DIR)) ;
+ BufferChannel chan = BufferChannelFile.create(DATA) ;
+ TransBlob tBlob = new TransBlob(cid, chan) ;
+ coord.add(tBlob) ;
+ coord.start();
+
+ ByteBuffer blob = tBlob.getBlob() ;
+ assertNotNull(blob);
+ String s = L.byteBufferToString(blob) ;
+ assertEquals(str,s) ;
+ coord.shutdown();
+ }
+
+ @Test public void recoverBlobFile_2() throws Exception {
+ String str1 = "Recovery One" ;
+ String str2 = "Recovery Two" ;
+ ComponentId cid1 = ComponentId.allocLocal() ;
+ ComponentId cid2 = ComponentId.allocLocal() ;
+
+ // Write out a journal for two components.
+ {
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ journal.write(JournalEntryType.REDO, cid1, L.stringToByteBuffer(str1)) ;
+ journal.write(JournalEntryType.REDO, cid2, L.stringToByteBuffer(str2)) ;
+ journal.writeJournal(JournalEntry.COMMIT) ;
+ journal.close();
+ }
+
+ Journal journal = Journal.create(Location.create(DIR)) ;
+ BufferChannel chan = BufferChannelFile.create(DATA) ;
+ TransBlob tBlob1 = new TransBlob(cid1, chan) ;
+ TransBlob tBlob2 = new TransBlob(cid2, chan) ;
+
+ TransactionCoordinator coord = new TransactionCoordinator(journal, Arrays.asList(tBlob1, tBlob2)) ;
+ coord.start();
+
+ ByteBuffer blob1 = tBlob1.getBlob() ;
+ assertNotNull(blob1);
+ String s1 = L.byteBufferToString(blob1) ;
+ assertEquals(str1,s1) ;
+
+ ByteBuffer blob2 = tBlob2.getBlob() ;
+ assertNotNull(blob2);
+ String s2 = L.byteBufferToString(blob2) ;
+ assertEquals(str2,s2) ;
+
+ assertNotEquals(str1,str2) ;
+ coord.shutdown();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/TC_TransData.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/TC_TransData.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/TC_TransData.java
deleted file mode 100644
index 06c6966..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/TC_TransData.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans;
-
-import org.junit.runner.RunWith ;
-import org.junit.runners.Suite ;
-import org.seaborne.dboe.trans.bplustree.TS_TxnBPTree ;
-import org.seaborne.dboe.trans.data.TS_TransData ;
-import org.seaborne.dboe.trans.recovery.TestRecovery ;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( {
- TS_TransData.class
- , TS_TxnBPTree.class
- , TestRecovery.class
-})
-public class TC_TransData {}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/BPlusTreeMaker.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/BPlusTreeMaker.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/BPlusTreeMaker.java
deleted file mode 100644
index 6a33a8b..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/BPlusTreeMaker.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree;
-
-import org.seaborne.dboe.index.Index ;
-import org.seaborne.dboe.index.RangeIndex ;
-import org.seaborne.dboe.trans.bplustree.BPlusTree ;
-import org.seaborne.dboe.index.test.RangeIndexMaker ;
-import org.seaborne.dboe.test.RecordLib ;
-
-public class BPlusTreeMaker implements RangeIndexMaker
-{
- private int order ;
- private int recordOrder ;
- private boolean trackers ;
-
-
- public BPlusTreeMaker(int order, int recordOrder, boolean trackers)
- {
- this.order = order ;
- this.recordOrder = recordOrder ;
- this.trackers = trackers ;
- }
-
- @Override
- public Index makeIndex() { return makeRangeIndex() ; }
-
- @Override
- public RangeIndex makeRangeIndex()
- {
- BPlusTree bpTree = BPlusTreeFactory.makeMem(order, recordOrder, RecordLib.TestRecordLength, 0) ;
- if ( trackers )
- bpTree = BPlusTreeFactory.addTracking(bpTree) ;
- return bpTree ;
- }
-
- @Override
- public String getLabel() { return "B+Tree order = "+order ; }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TS_TxnBPTree.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TS_TxnBPTree.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TS_TxnBPTree.java
deleted file mode 100644
index 52e9a4d..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TS_TxnBPTree.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree;
-
-import org.junit.runner.RunWith ;
-import org.junit.runners.Suite ;
-import org.seaborne.dboe.trans.bplustree.rewriter.TestBPlusTreeRewriterNonTxn ;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( {
-
- // Non-transactional tests -- that is, algorithms and machinary.
- TestBPTreeRecordsNonTxn.class,
- TestBPlusTreeIndexNonTxn.class,
- TestBPlusTreeNonTxn.class,
- TestBPTreeModes.class,
-
- // Transactional tests
- TestBPlusTreeTxn.class,
-
- // Rewriter
- TestBPlusTreeRewriterNonTxn.class
-} )
-
-public class TS_TxnBPTree
-{ }
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeModes.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeModes.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeModes.java
deleted file mode 100644
index b39cad9..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeModes.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree;
-
-import java.util.Arrays ;
-import java.util.Collection ;
-
-import org.junit.After ;
-import org.junit.AfterClass ;
-import org.junit.Before ;
-import org.junit.BeforeClass ;
-import org.junit.runner.RunWith ;
-import org.junit.runners.Parameterized ;
-import org.junit.runners.Parameterized.Parameters ;
-
-/** Run the B+Tree algorithm tests but for each combination of explicit
- * write-in-place / always copy modes.
- */
-@RunWith(Parameterized.class)
-public class TestBPTreeModes extends TestBPlusTreeNonTxn
-{
- @Parameters(name="Node dup={0}, Record dup={1}")
- public static Collection<Object[]> data()
- {
- return Arrays.asList(new Object[][]{
- {true, true},
- {true, false},
- {false, true},
- {false, false}
- }) ;
- }
-
- public TestBPTreeModes(boolean nodeMode, boolean recordsMode) {
-
- BPT.promoteDuplicateNodes = nodeMode ;
- BPT.promoteDuplicateRecords = recordsMode ;
- }
-
- boolean modeAtStartNodes ;
- boolean modeAtStartRecords ;
-
- @BeforeClass public static void setupSuite() {
- BPT.forcePromoteModes = true ;
- }
-
- @AfterClass public static void resetSuite() {
- BPT.forcePromoteModes = false ;
- }
-
- @Before public void setModes() {
- BPT.forcePromoteModes = true ;
- modeAtStartNodes = BPT.promoteDuplicateNodes ;
- modeAtStartRecords = BPT.promoteDuplicateRecords ;
- }
-
-
- @After public void resetModes() {
- BPT.promoteDuplicateNodes = modeAtStartNodes ;
- BPT.promoteDuplicateRecords = modeAtStartRecords ;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeRecordsNonTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeRecordsNonTxn.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeRecordsNonTxn.java
deleted file mode 100644
index 33dcfaf..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPTreeRecordsNonTxn.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree ;
-
-import org.junit.* ;
-import org.seaborne.dboe.base.block.BlockMgr ;
-import org.seaborne.dboe.base.block.BlockMgrFactory ;
-import org.seaborne.dboe.base.buffer.RecordBuffer ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-import org.seaborne.dboe.base.recordbuffer.RecordBufferPage ;
-import org.seaborne.dboe.base.recordbuffer.RecordBufferPageMgr ;
-import org.seaborne.dboe.sys.SystemIndex ;
-import org.seaborne.dboe.test.RecordLib ;
-
-public class TestBPTreeRecordsNonTxn extends Assert {
- static private boolean oldNullOut ;
-
- static private int blockSize ;
- static private RecordFactory recordFactory ;
-
- static private int bufSizeRecord ;
- static private BlockMgr blkMgrRecords ;
- static private RecordBufferPageMgr recordBufferPageMgr ;
-
- @BeforeClass
- public static void beforeClass() {
- oldNullOut = SystemIndex.getNullOut() ;
- SystemIndex.setNullOut(true) ;
-
- blockSize = 4 * 8 ; // Which is 6 int records
- recordFactory = new RecordFactory(4, 0) ;
-
- bufSizeRecord = RecordBufferPage.calcRecordSize(recordFactory, blockSize) ;
- blkMgrRecords = BlockMgrFactory.createMem("BPTreeRecords", blockSize) ;
- recordBufferPageMgr = new RecordBufferPageMgr(recordFactory, blkMgrRecords) ;
-
- BlockMgr blkMgrNodes = BlockMgrFactory.createMem("BPTreeNs", blockSize) ;
-
- // Copy on write.
- BPT.forcePromoteModes = true ;
- BPT.promoteDuplicateRecords = true ;
- }
-
- @AfterClass
- public static void afterClass() {
- SystemIndex.setNullOut(oldNullOut) ;
- BPT.forcePromoteModes = false ;
- }
-
- @Before
- public void before() {
- blkMgrRecords.beginUpdate() ;
- }
-
- @After
- public void after() {
- blkMgrRecords.endUpdate() ;
- }
-
- @Test
- public void bpt_records_1() {
- BPTreeRecords bpr = make() ;
- fill(bpr) ;
- check(bpr) ;
- bpr.release() ;
- }
-
- @Test
- public void bpt_records_2() {
- BPTreeRecords bpr = make() ;
- fill(bpr) ;
- int s = bpr.getCount() ;
- assertTrue(bpr.isFull()) ;
- BPTreePage z = bpr.split() ;
- assertTrue(z instanceof BPTreeRecords) ;
- assertEquals(s, z.getCount() + bpr.getCount()) ;
- check(bpr) ;
- check((BPTreeRecords)z) ;
- bpr.release() ;
- z.release() ;
- }
-
- @Test
- public void bpt_records_3() {
- BPTreeRecords bpr = make() ;
- for ( int i = 0 ; bpr.getCount() < bpr.getMaxSize() ; i++ )
- insert(bpr, (i + 0x20)) ;
- check(bpr) ;
- bpr.release() ;
- }
-
- @Test
- public void bpt_records_4() {
- BPTreeRecords bpr = make() ;
- for ( int i = bpr.getMaxSize() - 1 ; i >= 0 ; i-- )
- insert(bpr, i + 0x20) ;
- check(bpr) ;
- bpr.release() ;
- }
-
- @Test
- public void bpt_records_5() {
- BPTreeRecords bpr = make() ;
- int N = bpr.getMaxSize() ;
-
- for ( int i = bpr.getMaxSize() - 1 ; i >= 0 ; i-- )
- insert(bpr, (i + 0x20)) ;
-
- delete(bpr, (1 + 0x20)) ;
- assertEquals(N - 1, bpr.getCount()) ;
- check(bpr) ;
-
- delete(bpr, (2 + 0x20)) ;
- assertEquals(N - 2, bpr.getCount()) ;
- check(bpr) ;
-
- delete(bpr, bpr.getLowRecord()) ;
- assertEquals(N - 3, bpr.getCount()) ;
- check(bpr) ;
-
- delete(bpr, bpr.getHighRecord()) ;
- assertEquals(N - 4, bpr.getCount()) ;
- check(bpr) ;
-
- bpr.release() ;
- }
-
- @Test
- public void bpt_records_6() {
- BPTreeRecords bpr = make() ;
- fill(bpr) ;
-
- // No match.
- assertNull(search(bpr, RecordLib.intToRecord(0x20))) ;
-
- Record r = RecordLib.intToRecord(0x32) ;
- Record r2 = search(bpr, r) ;
- assertTrue(Record.keyEQ(r, r2)) ;
-
- r = bpr.getLowRecord() ;
- r2 = search(bpr, r) ;
- assertTrue(Record.keyEQ(r, r2)) ;
-
- r = bpr.getHighRecord() ;
- r2 = search(bpr, r) ;
- assertTrue(Record.keyEQ(r, r2)) ;
-
- bpr.release() ;
- }
-
- @Test
- public void bpt_shift_1() {
- BPTreeRecords bpr1 = make() ;
- BPTreeRecords bpr2 = make() ;
-
- insert(bpr1, 10) ;
- Record r = bpr1.shiftRight(bpr2, null) ;
- assertNull(r) ;
- // assertTrue(Record.keyEQ(r, RecordTestLib.intToRecord(10))) ;
- contains(bpr1) ;
- contains(bpr2, 10) ;
-
- bpr1.release() ;
- bpr2.release() ;
-
- }
-
- @Test
- public void bpt_shift_2() {
- BPTreeRecords bpr1 = make() ;
- BPTreeRecords bpr2 = make() ;
-
- insert(bpr1, 10) ;
- Record r = bpr2.shiftLeft(bpr1, null) ;
-
- assertTrue(Record.keyEQ(r, RecordLib.intToRecord(10))) ;
- contains(bpr1) ;
- contains(bpr2, 10) ;
- bpr1.release() ;
- bpr2.release() ;
- }
-
- @Test
- public void bpt_shift_3() {
- BPTreeRecords bpr1 = make() ;
- BPTreeRecords bpr2 = make() ;
-
- insert(bpr1, 10, 20) ;
- insert(bpr2, 99) ;
-
- Record r = bpr1.shiftRight(bpr2, null) ;
-
- assertTrue(r + " != " + RecordLib.intToRecord(10), Record.keyEQ(r, RecordLib.intToRecord(10))) ;
- contains(bpr1, 10) ;
- contains(bpr2, 20, 99) ;
- bpr1.release() ;
- bpr2.release() ;
- }
-
- @Test
- public void bpt_shift_4() {
- BPTreeRecords bpr1 = make() ;
- BPTreeRecords bpr2 = make() ;
-
- insert(bpr1, 10, 20) ;
- insert(bpr2, 5) ;
-
- Record r = bpr2.shiftLeft(bpr1, null) ;
- assertTrue(Record.keyEQ(r, RecordLib.intToRecord(10))) ;
-
- contains(bpr1, 20) ;
- contains(bpr2, 5, 10) ;
- bpr1.release() ;
- bpr2.release() ;
- }
-
- @Test
- public void bpt_merge_1() {
- BPTreeRecords bpr1 = make() ;
- BPTreeRecords bpr2 = make() ;
-
- insert(bpr1, 10, 20) ;
- insert(bpr2, 99) ;
-
- BPTreeRecords bpr3 = (BPTreeRecords)bpr1.merge(bpr2, null) ;
- contains(bpr1, 10, 20, 99) ;
- contains(bpr2) ;
- assertSame(bpr1, bpr3) ;
- bpr1.release() ;
- bpr2.release() ;
- }
-
- @Test
- public void bpt_merge_2() {
- BPTreeRecords bpr1 = make() ;
- BPTreeRecords bpr2 = make() ;
-
- insert(bpr1, 10, 20) ;
- insert(bpr2, 5) ;
-
- BPTreeRecords bpr3 = (BPTreeRecords)bpr2.merge(bpr1, null) ;
- contains(bpr1) ;
- contains(bpr2, 5, 10, 20) ;
- assertSame(bpr2, bpr3) ;
- bpr1.release() ;
- bpr2.release() ;
- }
-
- protected static void check(BPTreeRecords bpr) {
- assertTrue(bpr.getCount() >= 0) ;
- assertTrue(bpr.getCount() <= bpr.getMaxSize()) ;
-
- assertEquals(bpr.getRecordBuffer().getLow(), bpr.getLowRecord()) ;
- assertEquals(bpr.getRecordBuffer().getHigh(), bpr.getHighRecord()) ;
-
- for ( int i = 1 ; i < bpr.getCount() ; i++ ) {
- Record r1 = bpr.getRecordBuffer().get(i - 1) ;
- Record r2 = bpr.getRecordBuffer().get(i) ;
- assertTrue(Record.keyLE(r1, r2)) ;
- }
- }
-
- private static Record search(BPTreeRecords bpr, int x) {
- return search(bpr, RecordLib.intToRecord(x)) ;
- }
-
- private static Record search(BPTreeRecords bpr, Record r) {
- return bpr.internalSearch(null, r) ;
- }
-
- private static void insert(BPTreeRecords bpr, int... values) {
- for ( int value : values ) {
- bpr.internalInsert(null, RecordLib.intToRecord(value)) ;
- }
- }
-
- private static void insert(BPTreeRecords bpr, Record r) {
- bpr.internalInsert(null, r) ;
- }
-
- private static void delete(BPTreeRecords bpr, int... values) {
- for ( int value : values ) {
- delete(bpr, RecordLib.intToRecord(value)) ;
- }
- }
-
- private static void delete(BPTreeRecords bpr, Record r) {
- bpr.internalDelete(null, r) ;
- }
-
- private static void contains(BPTreeRecords bpr, int... values) {
- assertEquals(values.length, bpr.getCount()) ;
- for ( int i = 1 ; i < values.length ; i++ )
- assertTrue(Record.compareByKeyValue(RecordLib.intToRecord(values[i]), bpr.getRecordBuffer().get(i)) == 0) ;
- }
-
- protected static BPTreeRecords make() {
- RecordBufferPage page = recordBufferPageMgr.create() ;
- BPTreeRecordsMgr mgr = new BPTreeRecordsMgr(null, recordFactory, recordBufferPageMgr) ;
- return new BPTreeRecords(mgr, page) ;
- }
-
- protected static void fill(BPTreeRecords bpr) {
- int N = bpr.getRecordBuffer().maxSize() ;
- for ( int i = 0 ; i < N ; i++ ) {
- RecordBuffer rb = bpr.getRecordBuffer() ;
- insert(bpr, (i + 0x30)) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeIndexNonTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeIndexNonTxn.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeIndexNonTxn.java
deleted file mode 100644
index c387925..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeIndexNonTxn.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree ;
-
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.junit.AfterClass ;
-import org.junit.BeforeClass ;
-import org.seaborne.dboe.base.block.BlockMgr ;
-import org.seaborne.dboe.index.test.AbstractTestIndex ;
-import org.seaborne.dboe.sys.SystemIndex ;
-import org.seaborne.dboe.test.RecordLib ;
-
-/** Run the tests in default settings for a tree in "non-transactional" mode */
-public class TestBPlusTreeIndexNonTxn extends AbstractTestIndex {
- static boolean addTracker = true ;
- // Panic.
- static boolean addLogger = false ;
-
- static boolean originalNullOut ;
- @BeforeClass
- static public void beforeClass() {
- BPT.CheckingNode = true ;
- originalNullOut = SystemIndex.getNullOut() ;
- SystemIndex.setNullOut(true) ;
- }
-
- @AfterClass
- static public void afterClass() {
- SystemIndex.setNullOut(originalNullOut) ;
- }
- @Override
- protected BPlusTree makeIndex(int order, int minRecords) {
- BPlusTree bpt = BPlusTreeFactory.makeMem(order, minRecords, RecordLib.TestRecordLength, 0) ;
- if ( addLogger ) {
- // Put it in but disable it so that it can be enabled
- // in the middle of a complex operation.
- LogCtl.disable(BlockMgr.class) ;
- bpt = BPlusTreeFactory.addLogging(bpt) ;
- }
- if ( addTracker )
- bpt = BPlusTreeFactory.addTracking(bpt) ;
- bpt.nonTransactional() ;
- return bpt ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeNonTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeNonTxn.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeNonTxn.java
deleted file mode 100644
index 2c37b4b..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeNonTxn.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree ;
-
-import static org.seaborne.dboe.index.test.IndexTestLib.add ;
-import static org.seaborne.dboe.test.RecordLib.intToRecord ;
-
-import java.util.List ;
-
-import org.apache.jena.atlas.logging.LogCtl ;
-import org.junit.AfterClass ;
-import org.junit.BeforeClass ;
-import org.seaborne.dboe.base.block.BlockMgr ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.index.test.AbstractTestRangeIndex ;
-import org.seaborne.dboe.sys.SystemIndex ;
-import org.seaborne.dboe.test.RecordLib ;
-
-/** Run the tests in default settings for a tree in "non-transactional" mode */
-public class TestBPlusTreeNonTxn extends AbstractTestRangeIndex {
- // See TestBPTreeModes for parameterised tests for the duplication modes.
-
- // Add tracker or not (usually not)
- // The tracker checking can impose more constraints than are needed
- // giving false negatives. Iterator aren't tracked (they may not
- // be consumed; don't release pages properly)
- static boolean addTracker = false ;
- // Panic.
- static boolean addLogger = false ;
-
- static boolean originalNullOut ;
- @BeforeClass
- static public void beforeClass() {
- BPT.CheckingNode = true ;
- originalNullOut = SystemIndex.getNullOut() ;
- SystemIndex.setNullOut(true) ;
- }
-
- @AfterClass
- static public void afterClass() {
- SystemIndex.setNullOut(originalNullOut) ;
- }
-
- protected void testClearX(int N) {
- int[] keys = new int[N] ; // Slice is 1000.
- for ( int i = 0 ; i < keys.length ; i++ )
- keys[i] = i ;
- BPlusTree rIndex = makeRangeIndex(2, 2) ;
- add(rIndex, keys) ;
- rIndex.dump() ;
- if ( N > 0 )
- assertFalse(rIndex.isEmpty()) ;
- List<Record> x = intToRecord(keys, RecordLib.TestRecordLength) ;
- for ( int i = 0 ; i < keys.length ; i++ ) {
- System.out.println(i+": "+x.get(i)) ;
- rIndex.delete(x.get(i)) ;
- }
- assertTrue(rIndex.isEmpty()) ;
- }
-
- @Override
- protected BPlusTree makeRangeIndex(int order, int minRecords) {
- BPlusTree bpt = BPlusTreeFactory.makeMem(order, minRecords, RecordLib.TestRecordLength, 0) ;
- if ( addLogger ) {
- // Put it in but disable it so that it can be enabled
- // in the middle of a complex operation.
- LogCtl.disable(BlockMgr.class) ;
- bpt = BPlusTreeFactory.addLogging(bpt) ;
- }
- if ( addTracker )
- bpt = BPlusTreeFactory.addTracking(bpt) ;
- bpt.nonTransactional() ;
- return bpt ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeTxn.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeTxn.java
deleted file mode 100644
index f244422..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/TestBPlusTreeTxn.java
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree;
-
-import org.apache.jena.query.ReadWrite ;
-import org.junit.Assert ;
-import org.junit.Test ;
-import org.seaborne.dboe.base.file.Location ;
-import org.seaborne.dboe.index.test.IndexTestLib ;
-import org.seaborne.dboe.jenax.Txn ;
-import org.seaborne.dboe.test.RecordLib ;
-import org.seaborne.dboe.transaction.Transactional ;
-import org.seaborne.dboe.transaction.TransactionalFactory ;
-import org.seaborne.dboe.transaction.txn.TransactionalComponent ;
-
-/** Tests of B+Tree and transactions */
-public class TestBPlusTreeTxn extends Assert {
-
- static BPlusTree createBPTree() {
- return BPlusTreeFactory.makeMem(2, 2, RecordLib.TestRecordLength, 0) ;
- }
-
- static Transactional transactional(TransactionalComponent ... components) {
- return transactional(Location.mem(), components) ;
- }
-
- static Transactional transactional(Location location, TransactionalComponent ... components) {
- return TransactionalFactory.createTransactional(location, components) ;
- }
-
- // Commit
- @Test public void bptree_txn_01() {
- BPlusTree bpt = createBPTree() ;
- assertNotNull(bpt.getComponentId()) ;
- int outerRootIdx1 = bpt.getRootId() ;
- Transactional thing = transactional(bpt) ;
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt, 1, 2, 3, 4) ;
- } );
- int outerRootIdx2 = bpt.getRootId() ;
- assertNotEquals("After txn", outerRootIdx1, outerRootIdx2);
- }
-
- // Commit - only the first changes the root.
- @Test public void bptree_txn_02() {
- BPlusTree bpt = createBPTree() ;
- int outerRootIdx1 = bpt.getRootId() ;
- Transactional thing = transactional(bpt) ;
- Txn.executeWrite(thing, () -> {
- int rootIdx1 = bpt.getRootId() ;
- assertEquals("Inside txn (1)", outerRootIdx1, rootIdx1);
- IndexTestLib.add(bpt, 1) ;
- int rootIdx2 = bpt.getRootId() ;
- assertNotEquals("Inside txn (2)", rootIdx1, rootIdx2);
- IndexTestLib.add(bpt, 2, 3, 4) ;
- int rootIdx3 = bpt.getRootId() ;
- assertEquals("Inside txn (3)", rootIdx2, rootIdx3);
- } ) ;
- int outerRootIdx2 = bpt.getRootId() ;
- assertNotEquals("After txn", outerRootIdx1, outerRootIdx2);
- }
-
- // Abort
- @Test public void bptree_txn_03() {
- BPlusTree bpt = createBPTree() ;
- int outerRootIdx1 = bpt.getRootId() ;
- Transactional thing = transactional(bpt) ;
- thing.begin(ReadWrite.WRITE);
- IndexTestLib.add(bpt, 1, 2, 3, 4) ;
- thing.abort() ;
- thing.end() ;
- int outerRootIdx2 = bpt.getRootId() ;
- assertEquals("After txn", outerRootIdx1, outerRootIdx2);
- }
-
- // Two transactions
- @Test public void bptree_txn_04() {
- BPlusTree bpt = createBPTree() ;
- int outerRootIdx1 = bpt.getRootId() ;
- Transactional thing = transactional(bpt) ;
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt, 1, 2, 3, 4) ;
- } );
- int outerRootIdx2 = bpt.getRootId() ;
- assertNotEquals("After txn(1)", outerRootIdx1, outerRootIdx2);
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt, 5, 6) ;
- } );
- int outerRootIdx3 = bpt.getRootId() ;
- assertNotEquals("After txn (2)", outerRootIdx1, outerRootIdx3);
- assertNotEquals("After txn (3)", outerRootIdx2, outerRootIdx3);
- }
-
- // Two transactions, second an insert no-op.
- // Relies on all blocks not being full and so not being
- // split on the way down due to the early split algorithm.
- @Test public void bptree_txn_05() {
- BPlusTree bpt = createBPTree() ;
- int outerRootIdx1 = bpt.getRootId() ;
- Transactional thing = transactional(bpt) ;
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt, 1, 2, 3) ;
- } );
- int outerRootIdx2 = bpt.getRootId() ;
- assertNotEquals("After txn(1)", outerRootIdx1, outerRootIdx2);
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt, 1, 2) ;
- } );
- int outerRootIdx3 = bpt.getRootId() ;
- assertNotEquals("After txn (2)", outerRootIdx1, outerRootIdx3);
- assertEquals("After txn (3)", outerRootIdx2, outerRootIdx3);
- }
-
- // Two transactions, second a delete no-op.
- // Relies on all blocks not being min0size so not rebalanced.
- @Test public void bptree_txn_06() {
- BPlusTree bpt = createBPTree() ;
- int outerRootIdx1 = bpt.getRootId() ;
- Transactional thing = transactional(bpt) ;
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt, 1, 2, 3) ;
- } );
- int outerRootIdx2 = bpt.getRootId() ;
- assertNotEquals("After txn(1)", outerRootIdx1, outerRootIdx2);
- Txn.executeWrite(thing, () -> {
- IndexTestLib.delete(bpt, 5, 6) ;
- } );
- int outerRootIdx3 = bpt.getRootId() ;
- assertNotEquals("After txn (2)", outerRootIdx1, outerRootIdx3);
- assertEquals("After txn (3)", outerRootIdx2, outerRootIdx3);
- }
-
- // Two trees
- @Test public void bptree_txn_10() {
- BPlusTree bpt1 = createBPTree() ;
- BPlusTree bpt2 = createBPTree() ;
- assertNotEquals(bpt1.getComponentId(), bpt2.getComponentId()) ;
-
- Transactional thing = transactional(bpt1, bpt2) ;
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt1, 1, 2, 3) ;
- IndexTestLib.add(bpt2, 4, 5) ;
- } );
- Txn.executeRead(thing, ()->{
- IndexTestLib.testIndexContents(bpt2, 4, 5);
- IndexTestLib.testIndexContents(bpt1, 1, 2, 3);
- } );
- }
-
- @Test public void bptree_txn_11() {
- BPlusTree bpt1 = createBPTree() ;
- BPlusTree bpt2 = createBPTree() ;
- assertNotEquals(bpt1.getComponentId(), bpt2.getComponentId()) ;
-
- Transactional thing = transactional(bpt1, bpt2) ;
-
- // Commit 1
- Txn.executeWrite(thing, () -> {
- IndexTestLib.add(bpt1, 2, 1) ;
- IndexTestLib.add(bpt2, 3, 4, 5) ;
- }) ;
- Txn.executeRead(thing, ()->{
- IndexTestLib.testIndexContents(bpt2, 3, 4, 5);
- IndexTestLib.testIndexContents(bpt1, 1, 2);
- } );
-
- // Abort
- thing.begin(ReadWrite.WRITE);
- IndexTestLib.add(bpt1, 9, 10) ;
- IndexTestLib.delete(bpt2, 3, 11) ;
- thing.abort() ;
- Txn.executeRead(thing, ()->{
- IndexTestLib.testIndexContents(bpt2, 3, 4, 5);
- IndexTestLib.testIndexContents(bpt1, 1, 2);
- } );
-
- // Commit 2
- Txn.executeWrite(thing, () -> {
- IndexTestLib.delete(bpt1, 1,3) ;
- IndexTestLib.add(bpt1, 4) ;
- IndexTestLib.add(bpt2, 11, 12, 13) ;
- }) ;
- Txn.executeRead(thing, ()->{
- IndexTestLib.testIndexContents(bpt2, 3, 4, 5, 11, 12, 13);
- IndexTestLib.testIndexContents(bpt1, 2, 4);
- } );
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/rewriter/TestBPlusTreeRewriterNonTxn.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/rewriter/TestBPlusTreeRewriterNonTxn.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/rewriter/TestBPlusTreeRewriterNonTxn.java
deleted file mode 100644
index c15e3c0..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/rewriter/TestBPlusTreeRewriterNonTxn.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree.rewriter;
-
-import java.util.ArrayList ;
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.apache.jena.atlas.lib.Bytes ;
-import org.junit.AfterClass ;
-import org.junit.Assert ;
-import org.junit.BeforeClass ;
-import org.junit.Test ;
-import org.seaborne.dboe.base.block.BlockMgr ;
-import org.seaborne.dboe.base.block.BlockMgrFactory ;
-import org.seaborne.dboe.base.file.BufferChannel ;
-import org.seaborne.dboe.base.file.FileFactory ;
-import org.seaborne.dboe.base.file.FileSet ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.base.record.RecordFactory ;
-import org.seaborne.dboe.sys.Names ;
-import org.seaborne.dboe.trans.bplustree.BPTreeException ;
-import org.seaborne.dboe.trans.bplustree.BPlusTree ;
-import org.seaborne.dboe.trans.bplustree.BPlusTreeParams ;
-//import org.seaborne.dboe.trans.bplustree.rewriter.BPlusTreeRewriter ;
-
-public class TestBPlusTreeRewriterNonTxn extends Assert
-{
- // See also CmdTestBlusTreeRewriter for randomized soak testing.
-
- static int KeySize = 4 ;
- static int ValueSize = 8 ;
- static RecordFactory recordFactory = new RecordFactory(KeySize,ValueSize) ;
-
- // The BPlusTreeRewriter works directly on storage.
- static boolean b ;
- @BeforeClass public static void beforeClass() { b = BlockMgrFactory.AddTracker ; BlockMgrFactory.AddTracker = false ; }
- @AfterClass public static void afterClass() { BlockMgrFactory.AddTracker = b ;}
-
- @Test public void bpt_rewrite_01() { runTest(2, 0) ; }
- @Test public void bpt_rewrite_02() { runTest(3, 0) ; }
-
- @Test public void bpt_rewrite_03() { runTest(2, 1) ; }
- @Test public void bpt_rewrite_04() { runTest(3, 1) ; }
-
- @Test public void bpt_rewrite_05() { runTest(2, 2) ; }
- @Test public void bpt_rewrite_06() { runTest(3, 2) ; }
-
- @Test public void bpt_rewrite_07() { runTest(2, 100) ; }
- @Test public void bpt_rewrite_08() { runTest(3, 100) ; }
-
- @Test public void bpt_rewrite_99() { runTest(5, 1000) ; }
-
- static void runTest(int order, int N)
- { runOneTest(order, N , recordFactory, false) ; }
-
- public static void runOneTest(int order, int N, RecordFactory recordFactory, boolean debug)
- {
- BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory) ;
- BPlusTreeRewriter.debug = debug ;
-
- // ---- Test data
- List<Record> originaldata = TestBPlusTreeRewriterNonTxn.createData(N, recordFactory) ;
- if ( debug )
- System.out.println("Test data: "+originaldata) ;
-
- FileSet destination = FileSet.mem() ;
- // ---- Rewrite
- BufferChannel rootState = FileFactory.createBufferChannel(destination, Names.extBptState) ;
- // Write leaves to ...
- BlockMgr blkMgr1 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10) ;
- // Write nodes to ...
- BlockMgr blkMgr2 = BlockMgrFactory.create(destination, Names.extBptTree, bptParams.getCalcBlockSize(), 10, 10) ;
-
- BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(originaldata.iterator(), bptParams, recordFactory,
- rootState, blkMgr1, blkMgr2) ;
- if ( debug )
- {
- BPlusTreeRewriterUtils.divider() ;
- bpt2.dump();
- }
-
- // ---- Checking
- bpt2.check() ;
-
- scanComparision(originaldata, bpt2) ;
- findComparison(originaldata, bpt2) ;
- sizeComparison(originaldata, bpt2) ;
- }
-
- public static void scanComparision(List<Record> originaldata, BPlusTree bpt2)
- {
- // ** Scan comparisonSetupIndex
- Iterator<Record> iter1 = originaldata.iterator() ;
- Iterator<Record> iter2 = bpt2.iterator() ;
- long count = 0 ;
- for ( ; iter1.hasNext() ; )
- {
- count++ ;
- Record r1 = iter1.next();
- if ( ! iter2.hasNext() )
- error("Deviation: new B+Tree is smaller") ;
- Record r2 = iter2.next();
-
- if ( ! Record.equals(r1, r2) )
- error("Deviation in iteration record %d: %s : %s", count, r1, r2) ;
- }
- if ( iter2.hasNext() )
- error("New B+Tree larger than original") ;
- }
-
- public static void findComparison(List<Record> originaldata, BPlusTree bpt2)
- {
- Iterator<Record> iter1 = originaldata.iterator() ;
-
- long count = 0 ;
- for ( ; iter1.hasNext() ; )
- {
- count++ ;
- Record r1 = iter1.next();
-
- Record r3 = bpt2.find(r1) ;
- if ( r3 == null )
- {
- r3 = bpt2.find(r1) ;
- error("Deviation in find at record %d: %s : null", count, r1) ;
- }
- if ( ! Record.equals(r1, r3) )
- error("Deviation in find at record %d: %s : %s", count, r1, r3) ;
- }
-
- }
-
- public static void sizeComparison(List<Record> originaldata, BPlusTree bpt2)
- {
- long count1 = originaldata.size() ;
- long count2 = bpt2.size() ;
- //System.out.printf("Sizes = %d / %d\n", count1, count2) ;
- if ( count1 != count2 )
- // Not error - this test does not identify why there was a problem so continue.
- System.err.println("**** DIFFERENT") ;
- }
-
- static List<Record> createData(int N, RecordFactory recordFactory)
- {
- List<Record> originaldata = new ArrayList<>(N) ;
- for ( int i = 0; i < N ; i++ )
- {
- Record record = recordFactory.create() ;
- Bytes.setInt(i+1, record.getKey()) ;
- if ( recordFactory.hasValue() )
- Bytes.setInt(10*i+1, record.getValue()) ;
- originaldata.add(record) ;
- }
- return originaldata ;
- }
-
- private static void error(String string, Object ...args)
- {
- String msg = String.format(string, args) ;
- System.err.println(msg) ;
- throw new BPTreeException(msg) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/soak/CmdTestBPlusTree.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/soak/CmdTestBPlusTree.java b/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/soak/CmdTestBPlusTree.java
deleted file mode 100644
index 9a58756..0000000
--- a/jena-db/jena-dboe-trans-data/src/test/java/org/seaborne/dboe/trans/bplustree/soak/CmdTestBPlusTree.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.seaborne.dboe.trans.bplustree.soak;
-
-import org.seaborne.dboe.base.file.BlockAccessMem ;
-import org.seaborne.dboe.index.test.BaseSoakTest ;
-import org.seaborne.dboe.index.test.IndexTestLib ;
-import org.seaborne.dboe.sys.SystemIndex ;
-import org.seaborne.dboe.sys.Sys ;
-import org.seaborne.dboe.trans.bplustree.BPT ;
-import org.seaborne.dboe.trans.bplustree.BPlusTree ;
-import org.seaborne.dboe.trans.bplustree.BPlusTreeFactory ;
-import org.seaborne.dboe.trans.bplustree.BlockTracker ;
-
-public class CmdTestBPlusTree extends BaseSoakTest
-{
- static public void main(String... argv) {
- //argv = new String[] {"50", "150", "1000000"} ;
-// System.setProperty("bpt:checking", "false") ;
-// System.setProperty("bpt:duplication", "true") ;
- new CmdTestBPlusTree(argv).mainRun() ;
- }
-
- protected CmdTestBPlusTree(String[] argv) {
- super(argv) ;
- }
-
- @Override
- protected void before() {
- SystemIndex.setNullOut(true) ;
- BlockTracker.collectHistory = false ;
- // Forced mode
- if ( true ) {
- BlockAccessMem.SafeMode = true ;
- BPT.CheckingNode = trueOrFalse("bpt:checking", false) ;
- boolean duplication = trueOrFalse("bpt:duplication", false) ;
- BPT.forcePromoteModes = true ;
- BPT.promoteDuplicateNodes = duplication ;
- BPT.promoteDuplicateRecords = duplication ;
- }
- if ( false ) {
- // Transactions.
- }
-
- System.out.printf(" BPT.CheckingNode = %s\n", BPT.CheckingNode) ;
- System.out.printf(" BPT.forcePromoteModes = %s\n", BPT.forcePromoteModes) ;
- System.out.printf(" BPT.promoteDuplicateNodes = %s\n", BPT.promoteDuplicateRecords) ;
- System.out.printf(" BPT.promoteDuplicateRecords = %s\n", BPT.promoteDuplicateRecords) ;
- }
-
- private boolean trueOrFalse(String property, boolean dftValue) {
- String s = System.getProperty(property) ;
- if ( s == null )
- return dftValue ;
- if ( s.equalsIgnoreCase("true") || s.equalsIgnoreCase("T") || s.equalsIgnoreCase("1") )
- return true ;
- if ( s.equalsIgnoreCase("false") || s.equalsIgnoreCase("F") || s.equalsIgnoreCase("0") )
- return false ;
- System.err.println("Not recognized: "+property+"="+s);
- return dftValue ;
- }
-
- @Override
- protected void after() {}
-
- @Override
- protected void runOneTest(int testCount, int order, int size, boolean debug) {
- runOneTest(testCount, order, size) ;
- }
-
- @Override
- protected void runOneTest(int testCount, int order, int size) {
-// //System.err.println("runOneTest("+order+","+size+")") ;
- BPlusTree bpt = BPlusTreeFactory.makeMem(order, Sys.SizeOfInt, 0) ;
- bpt = BPlusTreeFactory.addTracking(bpt) ;
- bpt.nonTransactional() ;
- IndexTestLib.randTest(bpt, 5*size, size, true);
- bpt.close() ;
-
- // Transaction.
-// BPlusTree bpt = BPlusTreeFactory.makeMem(order, SystemLz.SizeOfInt, 0) ;
-// Journal journal = Journal.create(Location.mem()) ;
-// Transactional holder = TransactionalFactory.create(journal, bpt) ;
-// holder.begin(ReadWrite.WRITE);
-// IndexTestLib.randTest(bpt, 5*size, size, true);
-// holder.commit() ;
-// holder.end() ;
- }
-}
\ No newline at end of file