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/09/28 16:06:40 UTC
[088/100] [abbrv] jena git commit: JENA-1397: Rename java packages
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestIndex.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestIndex.java
new file mode 100644
index 0000000..55cd717
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestIndex.java
@@ -0,0 +1,161 @@
+/*
+ * 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.index.test;
+
+import static org.apache.jena.dboe.index.test.IndexTestLib.*;
+import static org.apache.jena.dboe.test.RecordLib.intToRecord;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.index.Index;
+import org.apache.jena.dboe.test.RecordLib;
+import org.junit.Assert ;
+import org.junit.After;
+import org.junit.Test;
+
+//import org.apache.jena.tdb.base.record.RecordLib;
+
+public abstract class AbstractTestIndex extends Assert
+{
+ Index index = null ;
+
+ @After public void afterTest()
+ {
+ if ( index != null )
+ index.close();
+ index = null ;
+ }
+
+ // ---- Overridable maker
+ protected abstract Index makeIndex(int kLen, int vLen) ;
+
+ @Test public void __basic() {
+ makeIndex(4,0) ;
+ }
+
+ @Test public void index_ins_0()
+ {
+ // Empty tree
+ int[] keys = {};
+ test(keys) ;
+ }
+
+ @Test public void index_ins_1()
+ {
+ int[] keys = {1};
+ test(keys) ;
+ }
+
+ @Test public void index_ins_2()
+ {
+ int[] keys = new int[20] ;
+ for ( int i = 0 ; i < keys.length ; i++ )
+ keys[i] = i ;
+ test(keys) ;
+ }
+
+ @Test public void index_ins_3()
+ {
+ int[] keys = new int[20] ;
+ for ( int i = keys.length-1 ; i >= 0 ; i-- )
+ keys[i] = i ;
+ test(keys) ;
+ }
+
+ @Test public void index_ins_4()
+ {
+ int[] keys = new int[10] ;
+ for ( int i = 0 ; i < keys.length ; i++ )
+ keys[i] = 1<<i ;
+ test(keys) ;
+ }
+
+ @Test public void index_ins_5()
+ {
+ int[] keys = new int[10] ;
+ for ( int i = keys.length-1 ; i >= 0 ; i-- )
+ keys[i] = 1<<i ;
+ test(keys) ;
+ }
+
+ @Test public void index_find_1()
+ {
+ int[] keys = {1};
+ Index index = test(keys) ;
+ Record r = intToRecord(1, RecordLib.TestRecordLength) ;
+ r = index.find(r) ;
+ assertNotNull(r) ;
+ }
+
+ @Test public void index_find_2()
+ {
+ int[] keys = {1,2,3,4,5,6,7,8,9};
+ Index index = test(keys) ;
+ Record r = intToRecord(20, RecordLib.TestRecordLength) ;
+ r = index.find(r) ;
+ assertNull(r) ;
+ }
+
+ @Test public void index_del_1()
+ {
+ int[] keys1 = {0, 1, 2};
+ int[] keys2 = {0, 1, 2};
+ int[] keys3 = {} ;
+ test(keys1, keys2, keys3) ;
+ }
+
+ @Test public void index_del_2()
+ {
+ int[] keys1 = {0, 1, 2};
+ int[] keys2 = {0, 1};
+ int[] keys3 = {2} ;
+ test(keys1, keys2, keys3) ;
+ }
+
+ @Test public void index_del_3()
+ {
+ int[] keys1 = {0, 1, 2};
+ int[] keys2 = {0, 99};
+ int[] keys3 = {2, 1} ;
+ test(keys1, keys2, keys3) ;
+ }
+
+ private Index test(int[] insKeys, int[] delKeys, int[] expected)
+ {
+ index = makeIndex(4,0) ;
+ testInsert(index, insKeys) ;
+ long x = index.size() ;
+ if ( x >= 0 )
+ assertEquals(insKeys.length, x) ;
+
+ if ( delKeys != null )
+ {
+ testDelete(index, delKeys) ;
+
+ }
+
+ if ( expected != null )
+ testIndexContents(index, expected) ;
+ return index ;
+ }
+
+ private Index test(int[] keys)
+ {
+ return test(keys, null, keys) ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestRangeIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestRangeIndex.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestRangeIndex.java
new file mode 100644
index 0000000..4b4e74b
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/AbstractTestRangeIndex.java
@@ -0,0 +1,435 @@
+/*
+ * 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.index.test ;
+
+import static org.apache.jena.dboe.index.test.IndexTestLib.add;
+import static org.apache.jena.dboe.index.test.IndexTestLib.randTest;
+import static org.apache.jena.dboe.index.test.IndexTestLib.testInsert;
+import static org.apache.jena.dboe.index.test.IndexTestLib.testInsertDelete;
+import static org.apache.jena.dboe.test.RecordLib.intToRecord;
+import static org.apache.jena.dboe.test.RecordLib.r;
+import static org.apache.jena.dboe.test.RecordLib.toIntList;
+
+import java.util.Iterator ;
+import java.util.List ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.index.RangeIndex;
+import org.junit.Assert ;
+import org.junit.Test ;
+
+public abstract class AbstractTestRangeIndex extends Assert {
+ // ---- Overridable maker
+ protected RangeIndex makeRangeIndex(int order) {
+ return makeRangeIndex(order, order) ;
+ }
+
+ protected abstract RangeIndex makeRangeIndex(int order, int minRecords) ;
+
+ @Test public void __basic() {
+ makeRangeIndex(4,0) ;
+ }
+
+ @Test
+ public void tree_ins_0_0() {
+ // Empty tree
+ int[] keys = {} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertTrue(rIndex.isEmpty()) ;
+ assertNull(rIndex.minKey()) ;
+ assertNull(rIndex.maxKey()) ;
+ }
+
+ @Test
+ public void tree_ins_0_1() {
+ int[] keys = {0, 1, 2} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertFalse(rIndex.isEmpty()) ;
+ assertEquals(0, r(rIndex.minKey())) ;
+ assertEquals(2, r(rIndex.maxKey())) ;
+ }
+
+ @Test
+ public void tree_ins_2_01() {
+ int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertEquals(0, r(rIndex.minKey())) ;
+ assertEquals(9, r(rIndex.maxKey())) ;
+ }
+
+ @Test
+ public void tree_ins_2_02() {
+ int[] keys = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertEquals(0, r(rIndex.minKey())) ;
+ assertEquals(9, r(rIndex.maxKey())) ;
+ }
+
+ @Test
+ public void tree_ins_2_03() {
+ int[] keys = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertEquals(0, r(rIndex.minKey())) ;
+ assertEquals(9, r(rIndex.maxKey())) ;
+ }
+
+ @Test
+ public void tree_ins_2_04() {
+ int[] keys = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertEquals(0, r(rIndex.minKey())) ;
+ assertEquals(9, r(rIndex.maxKey())) ;
+ }
+
+ @Test
+ public void tree_ins_2_05() {
+ int[] keys = {0, 18, 4, 14, 8, 10, 12, 6, 16, 2} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsert(rIndex, keys) ;
+ assertFalse(rIndex.contains(r(1))) ;
+ assertFalse(rIndex.contains(r(999))) ;
+ assertFalse(rIndex.contains(r(-9))) ;
+ assertFalse(rIndex.contains(r(7))) ;
+ assertEquals(0, r(rIndex.minKey())) ;
+ assertEquals(18, r(rIndex.maxKey())) ;
+ }
+
+ @Test
+ public void tree_del_0_1() {
+ int[] keys1 = {0, 1, 2} ;
+ int[] keys2 = {0, 1, 2} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_0_2() {
+ int[] keys1 = {0, 1, 2} ;
+ int[] keys2 = {2, 1, 0} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_0_3() {
+ int[] keys1 = {0, 1, 2} ;
+ int[] keys2 = {1, 0, 2} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_01() {
+ int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ int[] keys2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_02() {
+ int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ int[] keys2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_03() {
+ int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ int[] keys2 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_04() {
+ int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ int[] keys2 = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_05() {
+ int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ int[] keys2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_06() {
+ int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ int[] keys2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_07() {
+ int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ int[] keys2 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_08() {
+ int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ int[] keys2 = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_09() {
+ int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ int[] keys2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_10() {
+ int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ int[] keys2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_11() {
+ int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ int[] keys2 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_del_2_12() {
+ int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ int[] keys2 = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ testInsertDelete(rIndex, keys1, keys2) ;
+ }
+
+ @Test
+ public void tree_iter_2_01() {
+ int[] keys = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(4), r(6))) ;
+ List<Integer> expected = toIntList(4, 5) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_02() {
+ int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(4), r(7))) ;
+ List<Integer> expected = toIntList(4, 5, 6) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_03() {
+ int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(4), null)) ;
+ List<Integer> expected = toIntList(4, 5, 6, 7, 8, 9) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_04() {
+ int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(null, null)) ;
+ List<Integer> expected = toIntList(keys) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_05() {
+ int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(null, r(4))) ;
+ List<Integer> expected = toIntList(0, 1, 2, 3) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_07() {
+ int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(null, r(99))) ;
+ List<Integer> expected = toIntList(keys) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_08() {
+ int[] keys = {1, 2, 3, 4, 5, 6, 7, 8, 9} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(0), r(99))) ;
+ List<Integer> expected = toIntList(keys) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_2_09() {
+ int[] keys = {1, 2, 3, 4, /* 5, 6, */7, 8, 9, 10, 11} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(5), r(7))) ;
+ List<Integer> expected = toIntList() ;
+ assertEquals(expected, x) ;
+ }
+
+ // Root
+ @Test
+ public void tree_iter_0_01() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(5) ;
+ add(rIndex, keys) ;
+ Iterator<Record> iter = rIndex.iterator(r(2), r(4)) ;
+ while ( iter.hasNext() )
+ iter.next() ;
+
+ List<Integer> x = toIntList(rIndex.iterator(r(2), r(4))) ;
+ List<Integer> expected = toIntList(2, 3) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_0_02() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(5) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(null, null)) ;
+ List<Integer> expected = toIntList(keys) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_0_03() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(5) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(5), null)) ;
+ List<Integer> expected = toIntList(5) ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_0_04() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(5) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(0), r(0))) ;
+ List<Integer> expected = toIntList() ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_iter_0_05() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(5) ;
+ add(rIndex, keys) ;
+ List<Integer> x = toIntList(rIndex.iterator(r(1), r(0))) ;
+ List<Integer> expected = toIntList() ;
+ assertEquals(expected, x) ;
+ }
+
+ @Test
+ public void tree_ret_1() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ boolean b = rIndex.insert(intToRecord(3)) ;
+ assertFalse(b) ;
+ b = rIndex.insert(intToRecord(9)) ;
+ assertTrue(b) ;
+ }
+
+ @Test
+ public void tree_ret_2() {
+ int[] keys = {1, 2, 3, 4, 5} ;
+ RangeIndex rIndex = makeRangeIndex(2) ;
+ add(rIndex, keys) ;
+ boolean b = rIndex.delete(intToRecord(9)) ;
+ assertFalse(b) ;
+ b = rIndex.insert(intToRecord(1)) ;
+ assertFalse(b) ;
+ }
+
+ @Test
+ public void tree_2_N() {
+ for ( int i = 0 ; i < 10 ; i++ )
+ randTest(makeRangeIndex(2), 999, 20) ;
+ }
+
+ @Test
+ public void tree_3_N() {
+ for ( int i = 0 ; i < 10 ; i++ )
+ randTest(makeRangeIndex(3), 9999, 100) ;
+ }
+
+ @Test public void tree_clear_00() { testClear(0) ; }
+
+ @Test public void tree_clear_01() { testClear(5) ; }
+
+ @Test public void tree_clear_02() { testClear(15) ; }
+
+ @Test public void tree_clear_03() { testClear(998) ; }
+
+ @Test public void tree_clear_04() { testClear(999) ; }
+
+ @Test public void tree_clear_05() { testClear(1000) ; }
+
+ @Test public void tree_clear_06() { testClear(1001) ; }
+
+ @Test public void tree_clear_07() { testClear(5500) ; }
+
+ protected void testClear(int N) {
+ int[] keys = new int[N] ; // Slice is 1000.
+ for ( int i = 0 ; i < keys.length ; i++ )
+ keys[i] = i ;
+ RangeIndex rIndex = makeRangeIndex(3) ;
+ add(rIndex, keys) ;
+ if ( N > 0 )
+ assertFalse(rIndex.isEmpty()) ;
+ rIndex.clear() ;
+ assertTrue(rIndex.isEmpty()) ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/BaseSoakTest.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/BaseSoakTest.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/BaseSoakTest.java
new file mode 100644
index 0000000..6e46c02
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/BaseSoakTest.java
@@ -0,0 +1,141 @@
+/*
+ * 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.index.test;
+
+import java.util.List ;
+
+import jena.cmd.CmdException ;
+import jena.cmd.CmdGeneral ;
+
+import org.apache.jena.atlas.lib.Lib ;
+import org.apache.jena.atlas.lib.RandomLib ;
+import org.apache.jena.atlas.logging.LogCtl ;
+
+public abstract class BaseSoakTest extends CmdGeneral {
+ static { LogCtl.setLog4j() ; }
+
+ protected final int MinOrder = 2 ;
+ protected final int MinSize = 1 ;
+ protected int MaxOrder = -1 ;
+ protected int MaxSize = -1 ;
+ protected int NumTest = -1 ;
+
+ protected BaseSoakTest(String[] argv) {
+ super(argv) ;
+ }
+
+ protected abstract void before() ;
+ protected abstract void after() ;
+
+ @Override
+ protected String getSummary() {
+ return "Usage: "+Lib.className(this)+" maxOrder maxSize NumTests" ;
+ }
+
+ @Override
+ protected void processModulesAndArgs() {
+ List<String> args = super.getPositional() ;
+ if ( args.size() != 3 )
+ throw new CmdException("Usage: maxOrder maxSize NumTests") ;
+
+ try { MaxOrder = Integer.parseInt(args.get(0)) ; }
+ catch (NumberFormatException ex)
+ { throw new CmdException("Bad number for MaxOrder") ; }
+
+ try { MaxSize = Integer.parseInt(args.get(1)) ; }
+ catch (NumberFormatException ex)
+ { throw new CmdException("Bad number for MaxSize") ; }
+
+ try { NumTest = Integer.parseInt(args.get(2)) ; }
+ catch (NumberFormatException ex)
+ { throw new CmdException("Bad number for NumTest") ; }
+ }
+
+ @Override
+ protected void exec() {
+ int successes = 0 ;
+ int failures = 0 ;
+
+ // Number of dots.
+ int numOnLine = 50 ;
+ int testsPerTick ;
+ if ( NumTest < 20 )
+ testsPerTick = 5 ;
+ else if ( NumTest < 200 )
+ testsPerTick = 50 ;
+ else
+ testsPerTick = 500 ;
+
+
+ // ---- Format for line counter.
+ int numLines = (int)Math.ceil( ((double)NumTest) / (testsPerTick * numOnLine) ) ;
+ // Start of last line.
+ int z = (numLines-1)*(testsPerTick * numOnLine) ;
+ int digits = 1 ;
+ if ( z > 0 )
+ digits = 1+(int)Math.floor(Math.log10(z));
+ String format = "[%"+digits+"d] " ;
+
+ System.out.printf("TEST : %,d tests : Max Order=%d Max Items=%,d [tests per tick=%d]\n", NumTest, MaxOrder, MaxSize, testsPerTick) ;
+
+ before() ;
+
+ int testCount = 1 ;
+
+ for ( testCount = 1 ; testCount <= NumTest ; testCount++ ) {
+ if ( testCount % testsPerTick == 0 )
+ System.out.print(".") ;
+ if ( testCount % (testsPerTick * numOnLine) == 0 )
+ System.out.println("") ;
+ if ( testCount % (testsPerTick * numOnLine) == 1 )
+ System.out.printf(format, testCount-1) ;
+
+ int idx = testCount - 1 ;
+ int order = ( MinOrder == MaxOrder ) ? MinOrder : MinOrder + RandomLib.random.nextInt(MaxOrder-MinOrder) ;
+ int size = ( MinSize == MaxSize ) ? MinSize : MinSize + RandomLib.random.nextInt(MaxSize-MinSize) ; try {
+ //System.out.printf("TEST : %,d : Order=%-2d : Size=%d\n", testCount, order, size) ;
+ runOneTest(testCount, order, size) ;
+ successes++ ;
+ }
+ catch (AssertionError | RuntimeException ex) {
+ System.err.printf("-- Fail: (order=%d, size=%d)\n", order, size) ;
+ ex.printStackTrace(System.err) ;
+ System.err.printf("--------------------------\n") ;
+ failures++ ;
+ }
+ }
+
+ // Did the last loop print a new line?
+ if ( (testCount-1) % (testsPerTick*numOnLine) != 0 )
+ System.out.println();
+
+ after() ;
+ System.err.flush() ;
+ System.out.flush() ;
+ System.out.printf("DONE : %,d tests : Success=%,d ; Failures=%,d\n", NumTest, successes, failures);
+ }
+
+ protected abstract void runOneTest(int testCount, int order, int size, boolean debug) ;
+
+ protected abstract void runOneTest(int testCount, int order, int size) ;
+
+ @Override
+ protected String getCommandName() { return Lib.className(this) ; }
+}
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexMaker.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexMaker.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexMaker.java
new file mode 100644
index 0000000..7810fa2
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexMaker.java
@@ -0,0 +1,27 @@
+/*
+ * 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.index.test;
+
+import org.apache.jena.dboe.index.Index;
+
+public interface IndexMaker
+{
+ Index makeIndex() ;
+ String getLabel() ;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestGenerator.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestGenerator.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestGenerator.java
new file mode 100644
index 0000000..6ea0faf
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestGenerator.java
@@ -0,0 +1,45 @@
+/*
+ * 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.index.test;
+
+import org.apache.jena.atlas.lib.RandomLib ;
+import org.apache.jena.atlas.test.ExecGenerator ;
+
+public class IndexTestGenerator implements ExecGenerator
+{
+ int maxNumKeys ;
+ int maxValue ;
+ IndexMaker maker ;
+
+ public IndexTestGenerator(IndexMaker maker, int maxValue, int maxNumKeys)
+ {
+ if ( maxValue <= maxNumKeys )
+ throw new IllegalArgumentException("RangeIndexTestGenerator: Max value less than number of keys") ;
+ this.maker = maker ;
+ this.maxValue = maxValue ;
+ this.maxNumKeys = maxNumKeys ;
+ }
+
+ @Override
+ public void executeOneTest()
+ {
+ int numKeys = RandomLib.random.nextInt(maxNumKeys)+1 ;
+ IndexTestLib.randTest(maker.makeIndex(), maxValue, numKeys) ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestLib.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestLib.java
new file mode 100644
index 0000000..f5c42ee
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/IndexTestLib.java
@@ -0,0 +1,219 @@
+/*
+ * 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.index.test ;
+
+import static java.lang.String.format ;
+import static org.apache.jena.atlas.lib.ListUtils.asList ;
+import static org.apache.jena.atlas.lib.ListUtils.unique ;
+import static org.apache.jena.atlas.test.Gen.rand ;
+import static org.apache.jena.atlas.test.Gen.strings ;
+import static org.apache.jena.dboe.test.RecordLib.intToRecord;
+import static org.apache.jena.dboe.test.RecordLib.r;
+import static org.apache.jena.dboe.test.RecordLib.toIntList;
+import static org.junit.Assert.assertEquals ;
+import static org.junit.Assert.assertNotNull ;
+import static org.junit.Assert.fail ;
+
+import java.util.* ;
+
+import org.apache.jena.atlas.lib.RandomLib ;
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.index.Index;
+import org.apache.jena.dboe.index.RangeIndex;
+import org.apache.jena.dboe.test.RecordLib;
+import org.apache.jena.ext.com.google.common.primitives.Ints;
+import org.junit.Assert ;
+
+public class IndexTestLib {
+
+ // ---------- Utilities
+
+ // public static RangeIndex buildRangeIndex(RangeIndexMaker maker, int[]
+ // keys)
+ // {
+ // RangeIndex index = maker.make() ;
+ // IndexTestLib.add(index, keys) ;
+ // return index ;
+ // }
+
+ public static Index buildIndex(IndexMaker maker, int[] keys) {
+ Index index = maker.makeIndex() ;
+ IndexTestLib.add(index, keys) ;
+ return index ;
+ }
+
+ private static Random random = RandomLib.qrandom ;
+
+ public static void testIteration(RangeIndex index, int[] keys, int numIterations) {
+ // Shared across test-lets
+ SortedSet<Integer> x = new TreeSet<>() ;
+ for ( int v : keys )
+ x.add(v) ;
+
+ for ( int i = 0 ; i < numIterations ; i++ ) {
+ int lo = random.nextInt(keys.length) ;
+ int hi = random.nextInt(keys.length) ;
+ if ( lo > hi ) {
+ int t = lo ;
+ lo = hi ;
+ hi = t ;
+ }
+ // Does not consider nulls for min, max)
+ // That is assumed to be part of functional testing.
+ // Tweak lo and hi
+ if ( lo != 0 && random.nextFloat() < 0.5 )
+ lo-- ; // Negatives confuse the int/record code.
+ if ( random.nextFloat() < 0.5 )
+ hi++ ;
+
+ List<Integer> slice = r(index.iterator(r(lo), r(hi))) ;
+ List<Integer> expected = new ArrayList<>(keys.length) ;
+ for ( Integer ii : x.subSet(lo, hi) )
+ expected.add(ii) ;
+ if ( ! expected.equals(slice) )
+ assertEquals(format("(%d,%d)", lo, hi), expected, slice) ;
+ }
+ }
+
+ /* One random test : print the keys if there was a problem */
+
+ public static void randTest(Index index, int maxValue, int numKeys) {
+ randTest(index, maxValue, numKeys, true) ;
+ }
+ public static void randTest(Index index, int maxValue, int numKeys, boolean includeIteratorCheck) {
+ if ( numKeys >= 5000 )
+ System.err.printf("Warning: too many keys\n") ;
+
+ int[] keys1 = rand(numKeys, 0, maxValue) ;
+ int[] keys2 = permute2(keys1) ;
+ //int[] keys2 = permute(keys1, 4 * numKeys) ;
+ //System.err.printf("int[] keys1 = {%s} ;\n", strings(keys1)) ;
+ //System.err.printf("int[] keys2 = {%s}; \n", strings(keys2)) ;
+ try {
+ testInsert(index, keys1) ;
+ if ( true ) {
+ // Checking tests.
+ testIndexContents(index, keys2) ;
+ // Test iteration - quite expensive.
+ if ( includeIteratorCheck && index instanceof RangeIndex )
+ testIteration((RangeIndex)index, keys1, 10) ;
+ }
+ testDelete(index, keys2) ;
+ }
+ catch (AssertionError | RuntimeException ex) {
+ System.err.printf("Index : %s\n", index.getClass().getName()) ;
+ System.err.printf("int[] keys1 = {%s} ;\n", strings(keys1)) ;
+ System.err.printf("int[] keys2 = {%s}; \n", strings(keys2)) ;
+ throw ex ;
+ }
+ }
+
+ /** Pull items out of the list in a random order */
+ private static int[] permute2(int[] x) {
+ int[] ints = Arrays.copyOf(x, x.length);
+ List<Integer> list = Ints.asList(ints);
+ Collections.shuffle(list, random);
+ return ints;
+ }
+
+ private static Random randInit()
+ {
+ // Cheap random numbers, well seeded.
+ int seed = random.nextInt() ;
+ return new Random(seed) ;
+ }
+
+ // ---- Test utils
+
+ public static void testInsert(Index index, int[] keys) {
+ IndexTestLib.add(index, keys) ;
+ testIndexContents(index, keys) ;
+ }
+
+ public static Index testInsert(IndexMaker maker, int[] keys) {
+ Index index = maker.makeIndex() ;
+ testInsert(index, keys) ;
+ return index ;
+ }
+
+ public static void testInsertDelete(Index index, int[] buildKeys, int[] deleteKeys) {
+ testInsert(index, buildKeys) ;
+ testDelete(index, deleteKeys) ;
+ }
+
+ public static void testDelete(Index index, int[] vals) {
+ long size1 = index.size() ;
+
+ int count = 0 ;
+ count = delete(index, vals) ;
+
+ List<Record> x = intToRecord(vals, RecordLib.TestRecordLength) ;
+ for ( Record r : x )
+ Assert.assertFalse(index.contains(r)) ;
+ long size2 = index.size() ;
+
+ assertEquals(size1 - count, size2) ;
+ }
+
+ public static int delete(Index index, int... vals) {
+ int count = 0 ;
+ for ( int v : vals ) {
+ boolean b = index.delete(r(v)) ;
+ if ( b )
+ count++ ;
+ }
+ return count ;
+ }
+
+ public static void add(Index index, int... vals) {
+ // System.out.println("Add: "+Arrays.toString(vals)) ;
+ List<Record> x = intToRecord(vals, RecordLib.TestRecordLength) ;
+ for ( Record r : x ) {
+ // System.out.println(" Add: "+r) ;
+ index.insert(r) ;
+ }
+ }
+
+ public static void testIndexContents(Index index, int... records) {
+ List<Integer> x = toIntList(index.iterator()) ;
+
+ // Make a unique list of expected records. Remove duplicates
+ List<Integer> y = unique(asList(records)) ;
+
+ assertEquals("Expected records size and tree size different", y.size(), index.size()) ;
+ assertEquals("Expected records size and iteration over all keys are of different sizes", y.size(), x.size()) ;
+
+ if ( index instanceof RangeIndex ) {
+ // Check sorted order
+ for ( int i = 0 ; i < x.size() - 2 ; i++ ) {
+ if ( x.get(i) > x.get(i + 1) ) {
+ fail("check failed: " + strings(records)) ;
+ return ;
+ }
+ }
+ }
+
+ // Check each expected record is in the tree
+ for ( int k : y ) {
+ Record rec = intToRecord(k) ;
+ Record r2 = index.find(rec) ;
+ assertNotNull(r2) ;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/RangeIndexMaker.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/RangeIndexMaker.java b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/RangeIndexMaker.java
new file mode 100644
index 0000000..584c45e
--- /dev/null
+++ b/jena-db/jena-dboe-index-test/src/main/java/org/apache/jena/dboe/index/test/RangeIndexMaker.java
@@ -0,0 +1,28 @@
+/*
+ * 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.index.test;
+
+import org.apache.jena.dboe.index.RangeIndex;
+
+public interface RangeIndexMaker extends IndexMaker
+{
+ RangeIndex makeRangeIndex() ;
+ @Override
+ String getLabel() ;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TS_Index.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TS_Index.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TS_Index.java
deleted file mode 100644
index 2eb57b1..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TS_Index.java
+++ /dev/null
@@ -1,30 +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.index;
-
-import org.junit.runner.RunWith ;
-import org.junit.runners.Suite ;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses( {
- TestIndexMem.class
-} )
-
-public class TS_Index
-{ }
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TestIndexMem.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TestIndexMem.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TestIndexMem.java
deleted file mode 100644
index 0416592..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/TestIndexMem.java
+++ /dev/null
@@ -1,35 +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.index;
-
-import org.seaborne.dboe.base.record.RecordFactory ;
-import org.seaborne.dboe.index.Index ;
-import org.seaborne.dboe.index.IndexMap ;
-import org.seaborne.dboe.index.test.AbstractTestIndex ;
-
-public class TestIndexMem 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-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestIndex.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestIndex.java
deleted file mode 100644
index 7d92054..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestIndex.java
+++ /dev/null
@@ -1,160 +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.index.test;
-
-import static org.seaborne.dboe.index.test.IndexTestLib.* ;
-import static org.seaborne.dboe.test.RecordLib.intToRecord ;
-import org.junit.Assert ;
-import org.junit.After;
-import org.junit.Test;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.index.Index ;
-import org.seaborne.dboe.test.RecordLib ;
-
-//import org.apache.jena.tdb.base.record.RecordLib;
-
-public abstract class AbstractTestIndex extends Assert
-{
- Index index = null ;
-
- @After public void afterTest()
- {
- if ( index != null )
- index.close();
- index = null ;
- }
-
- // ---- Overridable maker
- protected abstract Index makeIndex(int kLen, int vLen) ;
-
- @Test public void __basic() {
- makeIndex(4,0) ;
- }
-
- @Test public void index_ins_0()
- {
- // Empty tree
- int[] keys = {};
- test(keys) ;
- }
-
- @Test public void index_ins_1()
- {
- int[] keys = {1};
- test(keys) ;
- }
-
- @Test public void index_ins_2()
- {
- int[] keys = new int[20] ;
- for ( int i = 0 ; i < keys.length ; i++ )
- keys[i] = i ;
- test(keys) ;
- }
-
- @Test public void index_ins_3()
- {
- int[] keys = new int[20] ;
- for ( int i = keys.length-1 ; i >= 0 ; i-- )
- keys[i] = i ;
- test(keys) ;
- }
-
- @Test public void index_ins_4()
- {
- int[] keys = new int[10] ;
- for ( int i = 0 ; i < keys.length ; i++ )
- keys[i] = 1<<i ;
- test(keys) ;
- }
-
- @Test public void index_ins_5()
- {
- int[] keys = new int[10] ;
- for ( int i = keys.length-1 ; i >= 0 ; i-- )
- keys[i] = 1<<i ;
- test(keys) ;
- }
-
- @Test public void index_find_1()
- {
- int[] keys = {1};
- Index index = test(keys) ;
- Record r = intToRecord(1, RecordLib.TestRecordLength) ;
- r = index.find(r) ;
- assertNotNull(r) ;
- }
-
- @Test public void index_find_2()
- {
- int[] keys = {1,2,3,4,5,6,7,8,9};
- Index index = test(keys) ;
- Record r = intToRecord(20, RecordLib.TestRecordLength) ;
- r = index.find(r) ;
- assertNull(r) ;
- }
-
- @Test public void index_del_1()
- {
- int[] keys1 = {0, 1, 2};
- int[] keys2 = {0, 1, 2};
- int[] keys3 = {} ;
- test(keys1, keys2, keys3) ;
- }
-
- @Test public void index_del_2()
- {
- int[] keys1 = {0, 1, 2};
- int[] keys2 = {0, 1};
- int[] keys3 = {2} ;
- test(keys1, keys2, keys3) ;
- }
-
- @Test public void index_del_3()
- {
- int[] keys1 = {0, 1, 2};
- int[] keys2 = {0, 99};
- int[] keys3 = {2, 1} ;
- test(keys1, keys2, keys3) ;
- }
-
- private Index test(int[] insKeys, int[] delKeys, int[] expected)
- {
- index = makeIndex(4,0) ;
- testInsert(index, insKeys) ;
- long x = index.size() ;
- if ( x >= 0 )
- assertEquals(insKeys.length, x) ;
-
- if ( delKeys != null )
- {
- testDelete(index, delKeys) ;
-
- }
-
- if ( expected != null )
- testIndexContents(index, expected) ;
- return index ;
- }
-
- private Index test(int[] keys)
- {
- return test(keys, null, keys) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestRangeIndex.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestRangeIndex.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestRangeIndex.java
deleted file mode 100644
index a8d41ff..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/AbstractTestRangeIndex.java
+++ /dev/null
@@ -1,435 +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.index.test ;
-
-import static org.seaborne.dboe.index.test.IndexTestLib.add ;
-import static org.seaborne.dboe.index.test.IndexTestLib.randTest ;
-import static org.seaborne.dboe.index.test.IndexTestLib.testInsert ;
-import static org.seaborne.dboe.index.test.IndexTestLib.testInsertDelete ;
-import static org.seaborne.dboe.test.RecordLib.intToRecord ;
-import static org.seaborne.dboe.test.RecordLib.r ;
-import static org.seaborne.dboe.test.RecordLib.toIntList ;
-
-import java.util.Iterator ;
-import java.util.List ;
-
-import org.junit.Assert ;
-import org.junit.Test ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.index.RangeIndex ;
-
-public abstract class AbstractTestRangeIndex extends Assert {
- // ---- Overridable maker
- protected RangeIndex makeRangeIndex(int order) {
- return makeRangeIndex(order, order) ;
- }
-
- protected abstract RangeIndex makeRangeIndex(int order, int minRecords) ;
-
- @Test public void __basic() {
- makeRangeIndex(4,0) ;
- }
-
- @Test
- public void tree_ins_0_0() {
- // Empty tree
- int[] keys = {} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertTrue(rIndex.isEmpty()) ;
- assertNull(rIndex.minKey()) ;
- assertNull(rIndex.maxKey()) ;
- }
-
- @Test
- public void tree_ins_0_1() {
- int[] keys = {0, 1, 2} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertFalse(rIndex.isEmpty()) ;
- assertEquals(0, r(rIndex.minKey())) ;
- assertEquals(2, r(rIndex.maxKey())) ;
- }
-
- @Test
- public void tree_ins_2_01() {
- int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertEquals(0, r(rIndex.minKey())) ;
- assertEquals(9, r(rIndex.maxKey())) ;
- }
-
- @Test
- public void tree_ins_2_02() {
- int[] keys = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertEquals(0, r(rIndex.minKey())) ;
- assertEquals(9, r(rIndex.maxKey())) ;
- }
-
- @Test
- public void tree_ins_2_03() {
- int[] keys = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertEquals(0, r(rIndex.minKey())) ;
- assertEquals(9, r(rIndex.maxKey())) ;
- }
-
- @Test
- public void tree_ins_2_04() {
- int[] keys = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertEquals(0, r(rIndex.minKey())) ;
- assertEquals(9, r(rIndex.maxKey())) ;
- }
-
- @Test
- public void tree_ins_2_05() {
- int[] keys = {0, 18, 4, 14, 8, 10, 12, 6, 16, 2} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsert(rIndex, keys) ;
- assertFalse(rIndex.contains(r(1))) ;
- assertFalse(rIndex.contains(r(999))) ;
- assertFalse(rIndex.contains(r(-9))) ;
- assertFalse(rIndex.contains(r(7))) ;
- assertEquals(0, r(rIndex.minKey())) ;
- assertEquals(18, r(rIndex.maxKey())) ;
- }
-
- @Test
- public void tree_del_0_1() {
- int[] keys1 = {0, 1, 2} ;
- int[] keys2 = {0, 1, 2} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_0_2() {
- int[] keys1 = {0, 1, 2} ;
- int[] keys2 = {2, 1, 0} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_0_3() {
- int[] keys1 = {0, 1, 2} ;
- int[] keys2 = {1, 0, 2} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_01() {
- int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- int[] keys2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_02() {
- int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- int[] keys2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_03() {
- int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- int[] keys2 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_04() {
- int[] keys1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- int[] keys2 = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_05() {
- int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- int[] keys2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_06() {
- int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- int[] keys2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_07() {
- int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- int[] keys2 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_08() {
- int[] keys1 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- int[] keys2 = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_09() {
- int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- int[] keys2 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_10() {
- int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- int[] keys2 = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_11() {
- int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- int[] keys2 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_del_2_12() {
- int[] keys1 = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- int[] keys2 = {0, 9, 2, 7, 4, 5, 6, 3, 8, 1} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- testInsertDelete(rIndex, keys1, keys2) ;
- }
-
- @Test
- public void tree_iter_2_01() {
- int[] keys = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(4), r(6))) ;
- List<Integer> expected = toIntList(4, 5) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_02() {
- int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(4), r(7))) ;
- List<Integer> expected = toIntList(4, 5, 6) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_03() {
- int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(4), null)) ;
- List<Integer> expected = toIntList(4, 5, 6, 7, 8, 9) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_04() {
- int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(null, null)) ;
- List<Integer> expected = toIntList(keys) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_05() {
- int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(null, r(4))) ;
- List<Integer> expected = toIntList(0, 1, 2, 3) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_07() {
- int[] keys = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(null, r(99))) ;
- List<Integer> expected = toIntList(keys) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_08() {
- int[] keys = {1, 2, 3, 4, 5, 6, 7, 8, 9} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(0), r(99))) ;
- List<Integer> expected = toIntList(keys) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_2_09() {
- int[] keys = {1, 2, 3, 4, /* 5, 6, */7, 8, 9, 10, 11} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(5), r(7))) ;
- List<Integer> expected = toIntList() ;
- assertEquals(expected, x) ;
- }
-
- // Root
- @Test
- public void tree_iter_0_01() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(5) ;
- add(rIndex, keys) ;
- Iterator<Record> iter = rIndex.iterator(r(2), r(4)) ;
- while ( iter.hasNext() )
- iter.next() ;
-
- List<Integer> x = toIntList(rIndex.iterator(r(2), r(4))) ;
- List<Integer> expected = toIntList(2, 3) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_0_02() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(5) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(null, null)) ;
- List<Integer> expected = toIntList(keys) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_0_03() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(5) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(5), null)) ;
- List<Integer> expected = toIntList(5) ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_0_04() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(5) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(0), r(0))) ;
- List<Integer> expected = toIntList() ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_iter_0_05() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(5) ;
- add(rIndex, keys) ;
- List<Integer> x = toIntList(rIndex.iterator(r(1), r(0))) ;
- List<Integer> expected = toIntList() ;
- assertEquals(expected, x) ;
- }
-
- @Test
- public void tree_ret_1() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- boolean b = rIndex.insert(intToRecord(3)) ;
- assertFalse(b) ;
- b = rIndex.insert(intToRecord(9)) ;
- assertTrue(b) ;
- }
-
- @Test
- public void tree_ret_2() {
- int[] keys = {1, 2, 3, 4, 5} ;
- RangeIndex rIndex = makeRangeIndex(2) ;
- add(rIndex, keys) ;
- boolean b = rIndex.delete(intToRecord(9)) ;
- assertFalse(b) ;
- b = rIndex.insert(intToRecord(1)) ;
- assertFalse(b) ;
- }
-
- @Test
- public void tree_2_N() {
- for ( int i = 0 ; i < 10 ; i++ )
- randTest(makeRangeIndex(2), 999, 20) ;
- }
-
- @Test
- public void tree_3_N() {
- for ( int i = 0 ; i < 10 ; i++ )
- randTest(makeRangeIndex(3), 9999, 100) ;
- }
-
- @Test public void tree_clear_00() { testClear(0) ; }
-
- @Test public void tree_clear_01() { testClear(5) ; }
-
- @Test public void tree_clear_02() { testClear(15) ; }
-
- @Test public void tree_clear_03() { testClear(998) ; }
-
- @Test public void tree_clear_04() { testClear(999) ; }
-
- @Test public void tree_clear_05() { testClear(1000) ; }
-
- @Test public void tree_clear_06() { testClear(1001) ; }
-
- @Test public void tree_clear_07() { testClear(5500) ; }
-
- protected void testClear(int N) {
- int[] keys = new int[N] ; // Slice is 1000.
- for ( int i = 0 ; i < keys.length ; i++ )
- keys[i] = i ;
- RangeIndex rIndex = makeRangeIndex(3) ;
- add(rIndex, keys) ;
- if ( N > 0 )
- assertFalse(rIndex.isEmpty()) ;
- rIndex.clear() ;
- assertTrue(rIndex.isEmpty()) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/BaseSoakTest.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/BaseSoakTest.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/BaseSoakTest.java
deleted file mode 100644
index d5347ef..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/BaseSoakTest.java
+++ /dev/null
@@ -1,141 +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.index.test;
-
-import java.util.List ;
-
-import jena.cmd.CmdException ;
-import jena.cmd.CmdGeneral ;
-
-import org.apache.jena.atlas.lib.Lib ;
-import org.apache.jena.atlas.lib.RandomLib ;
-import org.apache.jena.atlas.logging.LogCtl ;
-
-public abstract class BaseSoakTest extends CmdGeneral {
- static { LogCtl.setLog4j() ; }
-
- protected final int MinOrder = 2 ;
- protected final int MinSize = 1 ;
- protected int MaxOrder = -1 ;
- protected int MaxSize = -1 ;
- protected int NumTest = -1 ;
-
- protected BaseSoakTest(String[] argv) {
- super(argv) ;
- }
-
- protected abstract void before() ;
- protected abstract void after() ;
-
- @Override
- protected String getSummary() {
- return "Usage: "+Lib.className(this)+" maxOrder maxSize NumTests" ;
- }
-
- @Override
- protected void processModulesAndArgs() {
- List<String> args = super.getPositional() ;
- if ( args.size() != 3 )
- throw new CmdException("Usage: maxOrder maxSize NumTests") ;
-
- try { MaxOrder = Integer.parseInt(args.get(0)) ; }
- catch (NumberFormatException ex)
- { throw new CmdException("Bad number for MaxOrder") ; }
-
- try { MaxSize = Integer.parseInt(args.get(1)) ; }
- catch (NumberFormatException ex)
- { throw new CmdException("Bad number for MaxSize") ; }
-
- try { NumTest = Integer.parseInt(args.get(2)) ; }
- catch (NumberFormatException ex)
- { throw new CmdException("Bad number for NumTest") ; }
- }
-
- @Override
- protected void exec() {
- int successes = 0 ;
- int failures = 0 ;
-
- // Number of dots.
- int numOnLine = 50 ;
- int testsPerTick ;
- if ( NumTest < 20 )
- testsPerTick = 5 ;
- else if ( NumTest < 200 )
- testsPerTick = 50 ;
- else
- testsPerTick = 500 ;
-
-
- // ---- Format for line counter.
- int numLines = (int)Math.ceil( ((double)NumTest) / (testsPerTick * numOnLine) ) ;
- // Start of last line.
- int z = (numLines-1)*(testsPerTick * numOnLine) ;
- int digits = 1 ;
- if ( z > 0 )
- digits = 1+(int)Math.floor(Math.log10(z));
- String format = "[%"+digits+"d] " ;
-
- System.out.printf("TEST : %,d tests : Max Order=%d Max Items=%,d [tests per tick=%d]\n", NumTest, MaxOrder, MaxSize, testsPerTick) ;
-
- before() ;
-
- int testCount = 1 ;
-
- for ( testCount = 1 ; testCount <= NumTest ; testCount++ ) {
- if ( testCount % testsPerTick == 0 )
- System.out.print(".") ;
- if ( testCount % (testsPerTick * numOnLine) == 0 )
- System.out.println("") ;
- if ( testCount % (testsPerTick * numOnLine) == 1 )
- System.out.printf(format, testCount-1) ;
-
- int idx = testCount - 1 ;
- int order = ( MinOrder == MaxOrder ) ? MinOrder : MinOrder + RandomLib.random.nextInt(MaxOrder-MinOrder) ;
- int size = ( MinSize == MaxSize ) ? MinSize : MinSize + RandomLib.random.nextInt(MaxSize-MinSize) ; try {
- //System.out.printf("TEST : %,d : Order=%-2d : Size=%d\n", testCount, order, size) ;
- runOneTest(testCount, order, size) ;
- successes++ ;
- }
- catch (AssertionError | RuntimeException ex) {
- System.err.printf("-- Fail: (order=%d, size=%d)\n", order, size) ;
- ex.printStackTrace(System.err) ;
- System.err.printf("--------------------------\n") ;
- failures++ ;
- }
- }
-
- // Did the last loop print a new line?
- if ( (testCount-1) % (testsPerTick*numOnLine) != 0 )
- System.out.println();
-
- after() ;
- System.err.flush() ;
- System.out.flush() ;
- System.out.printf("DONE : %,d tests : Success=%,d ; Failures=%,d\n", NumTest, successes, failures);
- }
-
- protected abstract void runOneTest(int testCount, int order, int size, boolean debug) ;
-
- protected abstract void runOneTest(int testCount, int order, int size) ;
-
- @Override
- protected String getCommandName() { return Lib.className(this) ; }
-}
-
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexMaker.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexMaker.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexMaker.java
deleted file mode 100644
index 3c03ec9..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexMaker.java
+++ /dev/null
@@ -1,27 +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.index.test;
-
-import org.seaborne.dboe.index.Index ;
-
-public interface IndexMaker
-{
- Index makeIndex() ;
- String getLabel() ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestGenerator.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestGenerator.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestGenerator.java
deleted file mode 100644
index f463f81..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestGenerator.java
+++ /dev/null
@@ -1,45 +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.index.test;
-
-import org.apache.jena.atlas.lib.RandomLib ;
-import org.apache.jena.atlas.test.ExecGenerator ;
-
-public class IndexTestGenerator implements ExecGenerator
-{
- int maxNumKeys ;
- int maxValue ;
- IndexMaker maker ;
-
- public IndexTestGenerator(IndexMaker maker, int maxValue, int maxNumKeys)
- {
- if ( maxValue <= maxNumKeys )
- throw new IllegalArgumentException("RangeIndexTestGenerator: Max value less than number of keys") ;
- this.maker = maker ;
- this.maxValue = maxValue ;
- this.maxNumKeys = maxNumKeys ;
- }
-
- @Override
- public void executeOneTest()
- {
- int numKeys = RandomLib.random.nextInt(maxNumKeys)+1 ;
- IndexTestLib.randTest(maker.makeIndex(), maxValue, numKeys) ;
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java
deleted file mode 100644
index 1af0cf2..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/IndexTestLib.java
+++ /dev/null
@@ -1,219 +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.index.test ;
-
-import static java.lang.String.format ;
-import static org.apache.jena.atlas.lib.ListUtils.asList ;
-import static org.apache.jena.atlas.lib.ListUtils.unique ;
-import static org.apache.jena.atlas.test.Gen.rand ;
-import static org.apache.jena.atlas.test.Gen.strings ;
-import static org.junit.Assert.assertEquals ;
-import static org.junit.Assert.assertNotNull ;
-import static org.junit.Assert.fail ;
-import static org.seaborne.dboe.test.RecordLib.intToRecord ;
-import static org.seaborne.dboe.test.RecordLib.r ;
-import static org.seaborne.dboe.test.RecordLib.toIntList ;
-
-import java.util.* ;
-
-import org.apache.jena.atlas.lib.RandomLib ;
-import org.apache.jena.ext.com.google.common.primitives.Ints;
-import org.junit.Assert ;
-import org.seaborne.dboe.base.record.Record ;
-import org.seaborne.dboe.index.Index ;
-import org.seaborne.dboe.index.RangeIndex ;
-import org.seaborne.dboe.test.RecordLib ;
-
-public class IndexTestLib {
-
- // ---------- Utilities
-
- // public static RangeIndex buildRangeIndex(RangeIndexMaker maker, int[]
- // keys)
- // {
- // RangeIndex index = maker.make() ;
- // IndexTestLib.add(index, keys) ;
- // return index ;
- // }
-
- public static Index buildIndex(IndexMaker maker, int[] keys) {
- Index index = maker.makeIndex() ;
- IndexTestLib.add(index, keys) ;
- return index ;
- }
-
- private static Random random = RandomLib.qrandom ;
-
- public static void testIteration(RangeIndex index, int[] keys, int numIterations) {
- // Shared across test-lets
- SortedSet<Integer> x = new TreeSet<>() ;
- for ( int v : keys )
- x.add(v) ;
-
- for ( int i = 0 ; i < numIterations ; i++ ) {
- int lo = random.nextInt(keys.length) ;
- int hi = random.nextInt(keys.length) ;
- if ( lo > hi ) {
- int t = lo ;
- lo = hi ;
- hi = t ;
- }
- // Does not consider nulls for min, max)
- // That is assumed to be part of functional testing.
- // Tweak lo and hi
- if ( lo != 0 && random.nextFloat() < 0.5 )
- lo-- ; // Negatives confuse the int/record code.
- if ( random.nextFloat() < 0.5 )
- hi++ ;
-
- List<Integer> slice = r(index.iterator(r(lo), r(hi))) ;
- List<Integer> expected = new ArrayList<>(keys.length) ;
- for ( Integer ii : x.subSet(lo, hi) )
- expected.add(ii) ;
- if ( ! expected.equals(slice) )
- assertEquals(format("(%d,%d)", lo, hi), expected, slice) ;
- }
- }
-
- /* One random test : print the keys if there was a problem */
-
- public static void randTest(Index index, int maxValue, int numKeys) {
- randTest(index, maxValue, numKeys, true) ;
- }
- public static void randTest(Index index, int maxValue, int numKeys, boolean includeIteratorCheck) {
- if ( numKeys >= 5000 )
- System.err.printf("Warning: too many keys\n") ;
-
- int[] keys1 = rand(numKeys, 0, maxValue) ;
- int[] keys2 = permute2(keys1) ;
- //int[] keys2 = permute(keys1, 4 * numKeys) ;
- //System.err.printf("int[] keys1 = {%s} ;\n", strings(keys1)) ;
- //System.err.printf("int[] keys2 = {%s}; \n", strings(keys2)) ;
- try {
- testInsert(index, keys1) ;
- if ( true ) {
- // Checking tests.
- testIndexContents(index, keys2) ;
- // Test iteration - quite expensive.
- if ( includeIteratorCheck && index instanceof RangeIndex )
- testIteration((RangeIndex)index, keys1, 10) ;
- }
- testDelete(index, keys2) ;
- }
- catch (AssertionError | RuntimeException ex) {
- System.err.printf("Index : %s\n", index.getClass().getName()) ;
- System.err.printf("int[] keys1 = {%s} ;\n", strings(keys1)) ;
- System.err.printf("int[] keys2 = {%s}; \n", strings(keys2)) ;
- throw ex ;
- }
- }
-
- /** Pull items out of the list in a random order */
- private static int[] permute2(int[] x) {
- int[] ints = Arrays.copyOf(x, x.length);
- List<Integer> list = Ints.asList(ints);
- Collections.shuffle(list, random);
- return ints;
- }
-
- private static Random randInit()
- {
- // Cheap random numbers, well seeded.
- int seed = random.nextInt() ;
- return new Random(seed) ;
- }
-
- // ---- Test utils
-
- public static void testInsert(Index index, int[] keys) {
- IndexTestLib.add(index, keys) ;
- testIndexContents(index, keys) ;
- }
-
- public static Index testInsert(IndexMaker maker, int[] keys) {
- Index index = maker.makeIndex() ;
- testInsert(index, keys) ;
- return index ;
- }
-
- public static void testInsertDelete(Index index, int[] buildKeys, int[] deleteKeys) {
- testInsert(index, buildKeys) ;
- testDelete(index, deleteKeys) ;
- }
-
- public static void testDelete(Index index, int[] vals) {
- long size1 = index.size() ;
-
- int count = 0 ;
- count = delete(index, vals) ;
-
- List<Record> x = intToRecord(vals, RecordLib.TestRecordLength) ;
- for ( Record r : x )
- Assert.assertFalse(index.contains(r)) ;
- long size2 = index.size() ;
-
- assertEquals(size1 - count, size2) ;
- }
-
- public static int delete(Index index, int... vals) {
- int count = 0 ;
- for ( int v : vals ) {
- boolean b = index.delete(r(v)) ;
- if ( b )
- count++ ;
- }
- return count ;
- }
-
- public static void add(Index index, int... vals) {
- // System.out.println("Add: "+Arrays.toString(vals)) ;
- List<Record> x = intToRecord(vals, RecordLib.TestRecordLength) ;
- for ( Record r : x ) {
- // System.out.println(" Add: "+r) ;
- index.insert(r) ;
- }
- }
-
- public static void testIndexContents(Index index, int... records) {
- List<Integer> x = toIntList(index.iterator()) ;
-
- // Make a unique list of expected records. Remove duplicates
- List<Integer> y = unique(asList(records)) ;
-
- assertEquals("Expected records size and tree size different", y.size(), index.size()) ;
- assertEquals("Expected records size and iteration over all keys are of different sizes", y.size(), x.size()) ;
-
- if ( index instanceof RangeIndex ) {
- // Check sorted order
- for ( int i = 0 ; i < x.size() - 2 ; i++ ) {
- if ( x.get(i) > x.get(i + 1) ) {
- fail("check failed: " + strings(records)) ;
- return ;
- }
- }
- }
-
- // Check each expected record is in the tree
- for ( int k : y ) {
- Record rec = intToRecord(k) ;
- Record r2 = index.find(rec) ;
- assertNotNull(r2) ;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java b/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java
deleted file mode 100644
index 6520b06..0000000
--- a/jena-db/jena-dboe-index-test/src/main/java/org/seaborne/dboe/index/test/RangeIndexMaker.java
+++ /dev/null
@@ -1,28 +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.index.test;
-
-import org.seaborne.dboe.index.RangeIndex ;
-
-public interface RangeIndexMaker extends IndexMaker
-{
- RangeIndex makeRangeIndex() ;
- @Override
- String getLabel() ;
-}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/Index.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/Index.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/Index.java
new file mode 100644
index 0000000..d04aa19
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/Index.java
@@ -0,0 +1,92 @@
+/*
+ * 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.index;
+
+import java.util.Iterator ;
+import java.util.stream.Stream ;
+
+import org.apache.jena.atlas.lib.Closeable ;
+import org.apache.jena.atlas.lib.Sync ;
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.dboe.base.record.RecordFactory;
+
+public interface Index extends Iterable<Record>, Sync, Closeable
+{
+ /** Find one record - and return the record actually in the index (may have a value part) */
+ public Record find(Record record) ;
+
+ /** Return whether the index contains the record or not. */
+ public boolean contains(Record record) ;
+
+ /** Insert a record - return true if an insertion was actually needed */
+ public boolean insert(Record record) ;
+
+ /** Delete a record - Return true if a record was actually removed */
+ public boolean delete(Record record) ;
+
+// public default void bulkInsert(Collection<Record> inserts) {
+// for ( Record r : inserts )
+// insert(r) ;
+// }
+//
+// public default void bulkDelete(Collection<Record> inserts) {
+// for ( Record r : inserts )
+// delete(r) ;
+// }
+
+ /** Bulk changes as given by a stream of changes.
+ * This is operations consumes the stream.
+ * @param changes
+ */
+ public default void bulkChanges(Stream<IndexChange> changes) {
+ changes.forEach(chg -> {
+ switch (chg.action) {
+ case ADD :
+ insert(chg.record) ;
+ break ;
+ case DELETE :
+ delete(chg.record) ;
+ break ;
+ }
+ }) ;
+ }
+
+ /** Iterate over the whole index */
+ @Override
+ public Iterator<Record> iterator() ;
+
+ /** Get the Record factory associated with this index */
+ public RecordFactory getRecordFactory() ;
+
+ /** Close the index - can not be used again through this object */
+ @Override
+ public void close() ;
+
+ /** Answer whether the index is empty or not. May return false for unknown or meaningless */
+ public boolean isEmpty() ;
+
+ /** Clear the index */
+ public void clear() ;
+
+ /** Perform checks on this index */
+ public void check() ;
+
+ /** Return size if known else return -1 : does not count the peristent storage */
+ public long size() ;
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexChange.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexChange.java b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexChange.java
new file mode 100644
index 0000000..cc01377
--- /dev/null
+++ b/jena-db/jena-dboe-index/src/main/java/org/apache/jena/dboe/index/IndexChange.java
@@ -0,0 +1,40 @@
+/*
+ * 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.index;
+
+import java.util.Objects ;
+
+import org.apache.jena.dboe.base.record.Record;
+import org.apache.jena.sparql.core.DatasetChanges ;
+
+/** Temporary class to refine what to put into Jena itself.
+ * @see DatasetChanges
+ */
+public class IndexChange {
+ enum Action { ADD, DELETE }
+ final Action action ;
+ final Record record ;
+ public IndexChange(Action action, Record record) {
+ Objects.requireNonNull(action, "Action can not be null") ;
+ Objects.requireNonNull(record, "Record can not be null") ;
+ this.action = action ;
+ this.record = record ;
+ }
+}
+