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:05:27 UTC

[015/100] [abbrv] [partial] jena git commit: JENA-1397: Rename modules and set versions

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java
new file mode 100644
index 0000000..aac7ce0
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TC_TDB.java
@@ -0,0 +1,81 @@
+/*
+ * 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.tdb2;
+
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
+import org.apache.log4j.Level ;
+import org.apache.log4j.Logger ;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+import org.seaborne.dboe.base.block.FileMode ;
+import org.seaborne.tdb2.assembler.TS_TDBAssembler ;
+import org.seaborne.tdb2.graph.TS_Graph ;
+import org.seaborne.tdb2.lib.TS_LibTDB ;
+import org.seaborne.tdb2.setup.TS_TDBSetup ;
+import org.seaborne.tdb2.solver.TS_SolverTDB ;
+import org.seaborne.tdb2.store.TS_Store ;
+import org.seaborne.tdb2.store.nodetable.TS_NodeTable ;
+import org.seaborne.tdb2.store.tupletable.TS_TupleTable ;
+import org.seaborne.tdb2.sys.SystemTDB ;
+import org.seaborne.tdb2.sys.TS_Sys ;
+
+// Naming conventions.
+// TS_* - Test sets: collections of testing files (Often Test*)
+// TC_*  - Test collection: sets of TS's and TC's.
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+    // TDB
+    TS_LibTDB.class
+    , TS_NodeTable.class
+    , TS_TupleTable.class
+    , TS_TDBSetup.class
+    , TS_Store.class
+    , TS_SolverTDB.class
+    , TS_Graph.class
+    , TS_Factory.class
+    , TS_TDBAssembler.class
+    , TS_Sys.class
+} )
+
+public class TC_TDB
+{
+    static {
+        if ( false )
+            SystemTDB.setFileMode(FileMode.direct) ;
+    }
+    static ReorderTransformation dftReorder = null ; 
+        
+    @BeforeClass static public void beforeClass()   
+    {
+        //org.apache.log4j.LogManager.resetConfiguration() ;
+        //org.apache.log4j.PropertyConfigurator.configure("log4j.properties") ;
+        Logger.getLogger("org.apache.jena.tdb.info").setLevel(Level.WARN) ;
+        //Logger.getLogger("org.apache.jena.tdb.exec").setLevel(Level.WARN) ;
+        dftReorder = SystemTDB.defaultReorderTransform ;
+        SystemTDB.defaultReorderTransform = ReorderLib.identity() ;
+    }
+    
+    @AfterClass static public void afterClass() {
+        SystemTDB.defaultReorderTransform = dftReorder ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java
new file mode 100644
index 0000000..cd0f6ee
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TS_Factory.java
@@ -0,0 +1,33 @@
+/*
+ * 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.tdb2;
+
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+    TestDatabaseMgr.class
+    , TestTDBFactory.class
+
+})
+
+public class TS_Factory
+{}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java
new file mode 100644
index 0000000..38731e2
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestDatabaseMgr.java
@@ -0,0 +1,90 @@
+/*
+ * 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.tdb2;
+
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.junit.Test ;
+import org.seaborne.dboe.base.file.Location ;
+import org.seaborne.dboe.jenax.Txn ;
+import org.seaborne.tdb2.sys.TDBInternal ;
+
+/** Test of DatabaseMgr - the DatasetGraph level API to TDB2 **/
+public class TestDatabaseMgr
+{
+//    String DIRx = ConfigTest.getCleanDir() ;
+//    Location DIR = Location.create(DIRx);
+    
+    static Quad quad1 = SSE.parseQuad("(_ _:a <p> 1)") ;
+    static Quad quad2 = SSE.parseQuad("(_ <s> <p> 1)") ;
+    
+    @Test
+    public void testDatabaseMgr1() {
+        TDBInternal.reset() ; 
+        DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(Location.mem("FOO")) ;
+        DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(Location.mem("FOO")) ;
+        Txn.executeWrite(dg1, ()->{
+            dg1.add(quad1) ;
+        }) ;
+        Txn.executeRead(dg2, ()->{
+            assertTrue(dg2.contains(quad1)) ;
+        }) ;
+    }
+    
+    @Test
+    public void testDatabaseMgr2() {
+        TDBInternal.reset() ;
+        // The unnamed location is unique each time.
+        DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(Location.mem()) ;
+        DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(Location.mem()) ;
+        Txn.executeWrite(dg1, ()->{
+            dg1.add(quad1) ;    
+        }) ;
+        Txn.executeRead(dg2, ()->{
+            assertFalse(dg2.contains(quad1)) ;
+        }) ;
+    }
+
+    @Test
+    public void testDatabaseMgrDisk() {
+        TDBInternal.reset() ;
+        // The named disk location
+        String DIRx = ConfigTest.getCleanDir() ;
+        Location LOC = Location.create(DIRx) ;
+        FileOps.clearDirectory(DIRx) ;
+        try {
+            DatasetGraph dg1 = DatabaseMgr.connectDatasetGraph(LOC) ;
+            DatasetGraph dg2 = DatabaseMgr.connectDatasetGraph(Location.create(LOC.getDirectoryPath())) ;
+            assertSame(dg1, dg2) ;
+            Txn.executeWrite(dg1, ()-> {
+                dg1.add(quad1) ;
+            }) ;
+            Txn.executeRead(dg2, ()-> {
+                assertTrue(dg2.contains(quad1)) ;
+            }) ;
+        }
+        finally {
+            FileOps.clearDirectory(DIRx) ;
+        }
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.java
new file mode 100644
index 0000000..fe7ee53
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/TestTDBFactory.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.seaborne.tdb2;
+
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.datatypes.xsd.XSDDatatype ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.rdf.model.Literal ;
+import org.apache.jena.rdf.model.Property ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.rdf.model.ResourceFactory ;
+import org.junit.Test ;
+import org.seaborne.dboe.base.file.Location ;
+import org.seaborne.dboe.jenax.Txn ;
+import org.seaborne.tdb2.sys.TDBInternal ;
+
+/** Test of TDB2Factory - the Dataset level API to TDB2 **/
+public class TestTDBFactory
+{
+    static Resource s1 = ResourceFactory.createResource("http://example/s2");
+    static Resource s2 = ResourceFactory.createResource();
+    static Property p  =  ResourceFactory.createProperty("http://example/ns#", "p");
+    static Literal  o1 =  ResourceFactory.createPlainLiteral("object");
+    static Literal  o2 =  ResourceFactory.createTypedLiteral("1", XSDDatatype.XSDinteger);
+    
+    @Test
+    public void testTDBFactory1() {
+        TDBInternal.reset() ;
+        Dataset ds = TDB2Factory.connectDataset(Location.mem()) ;
+        test(ds);
+    }
+    
+    @Test
+    public void testTDBFactory2() {
+        TDBInternal.reset() ;
+        Dataset ds = TDB2Factory.connectDataset(Location.mem("MEMORY")) ;
+        test(ds);
+    }
+    
+    @Test
+    public void testTDBFactory3() {
+        TDBInternal.reset() ;
+        // Only do disk things for tests that need them (disk takes time!).
+        String DIRx = ConfigTest.getCleanDir() ;
+        Location DIR = Location.create(DIRx);
+        try { 
+            FileOps.clearDirectory(DIRx) ;
+            Dataset ds = TDB2Factory.connectDataset(DIR) ;
+            test(ds);
+        } finally { FileOps.clearDirectory(DIRx) ; }
+    }
+    
+    @Test
+    public void testTDBFactory2DS_1() {
+        TDBInternal.reset() ;
+        Dataset ds1 = TDB2Factory.connectDataset(Location.mem("FOO")) ;
+        Dataset ds2 = TDB2Factory.connectDataset(Location.mem("FOO")) ;
+        Txn.executeWrite(ds1, ()->{
+            ds1.getDefaultModel().add(s1, p, o1);
+        });
+        Txn.executeRead(ds2, ()->{
+            assertTrue(ds2.getDefaultModel().contains(s1, p, o1));
+        });
+    }
+    
+    @Test
+    public void testTDBFactory2DS_2() {
+        TDBInternal.reset() ;
+        // The unnamed location is unique each time.
+        Dataset ds1 = TDB2Factory.connectDataset(Location.mem()) ;
+        Dataset ds2 = TDB2Factory.connectDataset(Location.mem()) ;
+        Txn.executeWrite(ds1, ()->{
+            ds1.getDefaultModel().add(s1, p, o1);
+        });
+        Txn.executeRead(ds2, ()->{
+            assertFalse(ds2.getDefaultModel().contains(s1, p, o1));
+        });
+    }
+    
+    @Test
+    public void testTDBFactory2DS_3() {
+        TDBInternal.reset() ;
+        TDBInternal.reset() ;
+        String DIRx = ConfigTest.getCleanDir() ;
+        Location DIR = Location.create(DIRx);
+        try {
+            Dataset ds1 = TDB2Factory.connectDataset(DIR) ;
+            Dataset ds2 = TDB2Factory.connectDataset(DIR) ;
+            Txn.executeWrite(ds1, ()->{
+                ds1.getDefaultModel().add(s1, p, o1);
+            });
+            Txn.executeRead(ds2, ()->{
+                assertTrue(ds2.getDefaultModel().contains(s1, p, o1));
+            });
+        } finally { FileOps.clearDirectory(DIRx) ; }
+    }
+
+    private static void test(Dataset ds) {
+        Txn.executeWrite(ds, ()->{
+            ds.getDefaultModel().add(s1, p, o1);
+        });
+        Txn.executeRead(ds, ()->{
+            assertTrue(ds.getDefaultModel().contains(s1, p, o1));
+        });
+        Txn.executeWrite(ds, ()->{
+            ds.getDefaultModel().remove(s1, p, o1);
+            ds.getDefaultModel().add(s2, p, o2);
+        });
+        Txn.executeRead(ds, ()->{
+            assertFalse(ds.getDefaultModel().contains(s1, p, o1));
+            assertTrue(ds.getDefaultModel().contains(s2, p, o2));
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java
new file mode 100644
index 0000000..055c088
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TS_TDBAssembler.java
@@ -0,0 +1,33 @@
+/*
+ * 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.tdb2.assembler;
+
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+import org.seaborne.tdb2.junit.Base_TS ;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+     TestTDBAssembler.class
+})
+
+public class TS_TDBAssembler extends Base_TS
+{
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java
new file mode 100644
index 0000000..b55ba13
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/assembler/TestTDBAssembler.java
@@ -0,0 +1,143 @@
+/*
+ * 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.tdb2.assembler;
+
+import org.apache.jena.assembler.JA ;
+import org.apache.jena.assembler.exceptions.AssemblerException ;
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.sparql.core.assembler.AssemblerUtils ;
+import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab ;
+import org.junit.AfterClass ;
+import org.junit.Before ;
+import org.junit.BeforeClass ;
+import org.junit.Test ;
+import org.seaborne.tdb2.ConfigTest ;
+import org.seaborne.tdb2.store.DatasetGraphSwitchable ;
+import org.seaborne.tdb2.store.GraphViewSwitchable ;
+import org.seaborne.tdb2.sys.TDBInternal ;
+
+public class TestTDBAssembler
+{
+    // Can be slow - explicitly closes the dataset.
+    static String dirAssem      = null ;
+    static final String dirDB   = ConfigTest.getTestingDir()+"/DB" ;
+
+    @BeforeClass
+    static public void beforeClass() {
+        dirAssem = ConfigTest.getTestingDataRoot() + "/Assembler" ;
+        FileOps.ensureDir(dirDB) ;
+    }
+
+    @Before
+    public void before() {
+        TDBInternal.reset() ;
+        FileOps.clearDirectory(dirDB) ;
+    }
+
+    @AfterClass
+    static public void afterClass() {
+        TDBInternal.reset() ;
+        FileOps.clearDirectory(dirDB) ;
+    }
+
+    @Test
+    public void createDatasetDirect() {
+        createTest(dirAssem + "/tdb-dataset.ttl", VocabTDB2.tDatasetTDB) ;
+    }
+
+    @Test
+    public void createDatasetEmbed() {
+        createTest(dirAssem + "/tdb-dataset-embed.ttl", DatasetAssemblerVocab.tDataset) ;
+    }
+
+    private void createTest(String filename, Resource type) {
+        Object thing = AssemblerUtils.build(filename, type) ;
+        assertTrue(thing instanceof Dataset) ;
+        Dataset ds = (Dataset)thing ;
+        assertTrue(ds.asDatasetGraph() instanceof DatasetGraphSwitchable) ;
+        assertTrue(ds.supportsTransactions()) ;
+        ds.close() ;
+    }
+
+    @Test
+    public void createGraphDirect() {
+        testGraph(dirAssem + "/tdb-graph.ttl", false) ;
+    }
+
+    @Test
+    public void createGraphEmbed() {
+        String f = dirAssem + "/tdb-graph-embed.ttl" ;
+        Object thing = null ;
+        try {
+            thing = AssemblerUtils.build(f, JA.Model) ;
+        }
+        catch (AssemblerException e) {
+            e.getCause().printStackTrace(System.err) ;
+            throw e ;
+        }
+
+        assertTrue(thing instanceof Model) ;
+        Graph graph = ((Model)thing).getGraph() ;
+        assertTrue(graph instanceof GraphViewSwitchable) ;
+
+        DatasetGraphSwitchable ds = ((GraphViewSwitchable)graph).getDataset() ;
+        if ( ds != null )
+            ds.close() ;
+    }
+
+    @Test
+    public void createNamedGraph1() {
+        testGraph(dirAssem + "/tdb-named-graph-1.ttl", true) ;
+    }
+
+    @Test
+    public void createNamedGraph2() {
+        testGraph(dirAssem + "/tdb-named-graph-2.ttl", true) ;
+    }
+
+    @Test
+    public void createNamedGraphViaDataset() {
+        testGraph(dirAssem + "/tdb-graph-ref-dataset.ttl", false) ;
+    }
+
+    private static void testGraph(String assemblerFile, boolean named) {
+        Object thing = null ;
+        try {
+            thing = AssemblerUtils.build(assemblerFile, VocabTDB2.tGraphTDB) ;
+        }
+        catch (AssemblerException e) {
+            e.getCause().printStackTrace(System.err) ;
+            throw e ;
+        }
+
+        assertTrue(thing instanceof Model) ;
+        Graph graph = ((Model)thing).getGraph() ;
+
+        assertTrue(graph instanceof GraphViewSwitchable) ;
+
+        DatasetGraphSwitchable dsg = ((GraphViewSwitchable)graph).getDataset();
+        if ( dsg != null )
+            dsg.close() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java
new file mode 100644
index 0000000..78adf72
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/AbstractTestGraphsTDB.java
@@ -0,0 +1,51 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
+import org.apache.jena.sparql.graph.GraphsTests ;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.Ignore ;
+import org.junit.Test ;
+import org.seaborne.tdb2.sys.SystemTDB ;
+
+public abstract class AbstractTestGraphsTDB extends GraphsTests
+{
+    private static ReorderTransformation reorder  ;
+    
+    @BeforeClass public static void setupClass()
+    {
+        reorder = SystemTDB.defaultReorderTransform ;
+        SystemTDB.defaultReorderTransform = ReorderLib.identity() ;
+    }
+    
+    @AfterClass public static void afterClass() {  SystemTDB.defaultReorderTransform = reorder ; }
+
+    // These don't pass ... not quite clear if the test is right.  Investigate.
+    
+    @Override
+    @Ignore @Test public void graph_count5() {} 
+    
+    @Override
+    @Ignore @Test public void graph_count6() {} 
+    
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java
new file mode 100644
index 0000000..1867edc
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TS_Graph.java
@@ -0,0 +1,36 @@
+/*
+ * 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.tdb2.graph;
+
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+    TestPrefixMappingTDB.class
+    , TestDatasetGraphTDB.class
+    , TestGraphsTDB1.class
+    , TestGraphsTDB2.class
+    , TestDatasetGraphAccessorTDB.class
+    , TestGraphOverDatasetTDB.class
+})
+public class TS_Graph
+{
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java
new file mode 100644
index 0000000..70a405a
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphAccessorTDB.java
@@ -0,0 +1,48 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.query.DatasetAccessorFactory ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.web.AbstractTestDatasetGraphAccessor ;
+import org.apache.jena.web.DatasetGraphAccessor ;
+import org.junit.After ;
+import org.junit.Before ;
+import org.seaborne.tdb2.junit.TL ;
+
+public class TestDatasetGraphAccessorTDB extends AbstractTestDatasetGraphAccessor
+{
+    DatasetGraph dsg = TL.createTestDatasetGraphMem() ;
+    @Before public void before() {
+        dsg.begin(ReadWrite.WRITE);
+    }
+    
+    @After public void after() {
+        dsg.abort();
+        dsg.end();
+        TL.expel(dsg);
+    }
+
+    @Override
+    protected DatasetGraphAccessor getDatasetUpdater()
+    {
+        return DatasetAccessorFactory.make(dsg) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java
new file mode 100644
index 0000000..a869a86
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestDatasetGraphTDB.java
@@ -0,0 +1,53 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.AbstractDatasetGraphTests ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+import org.seaborne.tdb2.junit.TL ;
+
+// Quad tests
+public class TestDatasetGraphTDB extends AbstractDatasetGraphTests
+{
+    DatasetGraph dsg = TL.createTestDatasetGraphMem() ;
+    @Before public void before() {
+        dsg.begin(ReadWrite.WRITE);
+    }
+    
+    @After public void after() {
+        dsg.abort();
+        dsg.end();
+        TL.expel(dsg);
+    }
+    
+    @Override
+    protected DatasetGraph emptyDataset() {
+        return dsg ;
+    }
+
+    @Override
+    // Empty graph tests: N/A
+    @Test public void graph_01()
+    {}
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java
new file mode 100644
index 0000000..7270b11
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphOverDatasetTDB.java
@@ -0,0 +1,64 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.AbstractTestGraphOverDataset ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.junit.After ;
+import org.seaborne.tdb2.junit.TL ;
+
+/** This is the view-graph test suite run over a TDB DatasetGraph to check compatibility */
+public class TestGraphOverDatasetTDB extends AbstractTestGraphOverDataset
+{
+    DatasetGraph dsg = null;
+    @After public void after2() {
+        if ( dsg == null )
+            return;
+        dsg.abort();
+        dsg.end();
+        TL.expel(dsg);
+    }
+    
+    @Override
+    protected DatasetGraph createBaseDSG() {
+        // Called in initialization.
+        if ( dsg == null ) {
+            dsg = TL.createTestDatasetGraphMem() ;
+            dsg.begin(ReadWrite.WRITE);
+        }
+        return dsg ;
+    }
+    
+    @Override
+    protected Graph makeNamedGraph(DatasetGraph dsg, Node gn)
+    {
+        return dsg.getGraph(gn) ;
+    }
+
+    @Override
+    protected Graph makeDefaultGraph(DatasetGraph dsg)
+    {
+        return  dsg.getDefaultGraph() ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java
new file mode 100644
index 0000000..8e8da11
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB1.java
@@ -0,0 +1,43 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite ;
+import org.junit.After ;
+import org.junit.Before ;
+import org.seaborne.tdb2.junit.TL ;
+
+public class TestGraphsTDB1 extends AbstractTestGraphsTDB
+{
+    Dataset ds = TL.createTestDatasetMem();
+    @Before public void before() {
+        ds.begin(ReadWrite.WRITE);
+    }
+    
+    @After public void after() {
+        ds.abort();
+        ds.end();
+        TL.expel(ds);
+    }
+    @Override
+    protected Dataset createDataset() {
+        return ds ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java
new file mode 100644
index 0000000..7e38166
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestGraphsTDB2.java
@@ -0,0 +1,52 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite ;
+import org.junit.After ;
+import org.junit.Before ;
+import org.seaborne.dboe.jenax.Txn ;
+import org.seaborne.tdb2.TDB2Factory ;
+
+public class TestGraphsTDB2 extends AbstractTestGraphsTDB
+{
+    // Transactional.
+    @Before
+    public void before() {
+        getDataset().begin(ReadWrite.READ) ;
+    }
+
+    @After
+    public void after() {
+        getDataset().end() ;
+    }
+
+    @Override
+    protected void fillDataset(Dataset dataset) {
+        Txn.executeWrite(dataset, ()->{
+            super.fillDataset(dataset) ;
+        });
+    }
+    
+    @Override
+    protected Dataset createDataset() {
+        return TDB2Factory.createDataset() ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java
new file mode 100644
index 0000000..ccd90b7
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/graph/TestPrefixMappingTDB.java
@@ -0,0 +1,107 @@
+/*
+ * 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.tdb2.graph;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.sparql.core.DatasetPrefixStorage ;
+import org.apache.jena.sparql.graph.AbstractTestPrefixMapping2 ;
+import org.junit.* ;
+import org.seaborne.dboe.base.file.Location ;
+import org.seaborne.tdb2.ConfigTest ;
+import org.seaborne.tdb2.junit.BuildTestLib ;
+import org.seaborne.tdb2.sys.TDBInternal ;
+
+public class TestPrefixMappingTDB extends AbstractTestPrefixMapping2
+{
+    static DatasetPrefixStorage last = null ;
+    
+    @BeforeClass public static void beforeClass() {}
+    @AfterClass public static void afterClass()   { TDBInternal.reset() ; ConfigTest.deleteTestingDir() ; }
+
+    @Before public void before() { TDBInternal.reset() ; }
+    @After public  void after()  { }
+
+    
+    @Override
+    protected PrefixMapping create() {
+        last = createTestingMem() ;
+        return view() ;
+    }
+
+    static DatasetPrefixStorage createTestingMem() { 
+        return createTesting(Location.mem()) ;
+    }
+    
+    static DatasetPrefixStorage createTesting(Location location) {
+        return BuildTestLib.makePrefixes(location) ;
+    }
+
+    @Override
+    protected PrefixMapping view() {
+        return last.getPrefixMapping() ; 
+    }
+
+    @Test public void multiple1() {
+        DatasetPrefixStorage prefixes = createTestingMem() ;
+        PrefixMapping pmap1 = prefixes.getPrefixMapping() ;
+        PrefixMapping pmap2 = prefixes.getPrefixMapping("http://graph/") ;
+        pmap1.setNsPrefix("x", "http://foo/") ;
+        assertNull(pmap2.getNsPrefixURI("x")) ;
+        assertNotNull(pmap1.getNsPrefixURI("x")) ;
+    }
+    
+    @Test public void multiple2() {
+        DatasetPrefixStorage prefixes = createTestingMem() ;
+        PrefixMapping pmap1 = prefixes.getPrefixMapping("http://graph/") ;  // Same
+        PrefixMapping pmap2 = prefixes.getPrefixMapping("http://graph/") ;
+        pmap1.setNsPrefix("x", "http://foo/") ;
+        assertNotNull(pmap2.getNsPrefixURI("x")) ;
+        assertNotNull(pmap1.getNsPrefixURI("x")) ;
+    }
+    
+    // Persistent.
+    @Test
+    public void persistent1() {
+        String dir = ConfigTest.getTestingDir() ;
+        FileOps.clearDirectory(dir) ;
+
+        DatasetPrefixStorage prefixes = createTesting(Location.create(dir)) ;
+        PrefixMapping pmap1 = prefixes.getPrefixMapping() ;
+
+        String x = pmap1.getNsPrefixURI("x") ;
+        assertNull(x) ;
+        prefixes.close() ;
+    }
+    
+    // Persistent.
+    @Test
+    public void persistent2() {
+        String dir = ConfigTest.getTestingDir() ;
+        FileOps.clearDirectory(dir) ;
+
+        DatasetPrefixStorage prefixes = createTesting(Location.create(dir)) ;
+        PrefixMapping pmap1 = prefixes.getPrefixMapping() ;
+
+        pmap1.setNsPrefix("x", "http://foo/") ;
+        assertEquals("http://foo/", pmap1.getNsPrefixURI("x")) ;
+        prefixes.close() ;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java
new file mode 100644
index 0000000..dcfa506
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/AbstractTestGraphTDB.java
@@ -0,0 +1,34 @@
+/*
+ * 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.tdb2.junit;
+
+import org.apache.jena.graph.test.AbstractTestGraph ;
+
+public abstract class AbstractTestGraphTDB extends AbstractTestGraph
+{
+    public AbstractTestGraphTDB(String name)
+    {
+        super(name) ;
+    }
+    
+    @Override public void testIsomorphismFile() {}
+    
+    // Meaning less - graphs (and hence models) are not indpenedent of their datasets. 
+    @Override public void testCloseSetsIsClosed() {}
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java
new file mode 100644
index 0000000..b422a55
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/Base_TS.java
@@ -0,0 +1,52 @@
+/*
+ * 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.tdb2.junit;
+
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
+import org.apache.log4j.Level ;
+import org.apache.log4j.Logger ;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.seaborne.tdb2.sys.SystemTDB ;
+
+public class Base_TS
+{
+    static Level level = null ;
+    static ReorderTransformation rt = null ;
+    
+    @BeforeClass static public void beforeClass()   
+    {
+        rt = SystemTDB.defaultReorderTransform ;
+        level = Logger.getLogger("org.apache.jena.tdb.info").getLevel() ;
+        Logger.getLogger("org.apache.jena.tdb.info").setLevel(Level.FATAL) ;
+        Logger.getLogger("org.seaborne.tdb2.info").setLevel(Level.FATAL) ;
+        SystemTDB.defaultReorderTransform = ReorderLib.identity() ;
+        rt = SystemTDB.defaultReorderTransform ;
+    }
+    
+    @AfterClass static public void afterClass()
+    {
+        if ( level != null ) {
+            Logger.getLogger("org.apache.jena.tdb.info").setLevel(level) ;
+            Logger.getLogger("org.seaborne.tdb2.info").setLevel(level) ;
+        }
+        SystemTDB.defaultReorderTransform = rt ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java
new file mode 100644
index 0000000..b7e7bc3
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/BuildTestLib.java
@@ -0,0 +1,82 @@
+/*
+ * 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.tdb2.junit;
+
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.DatasetPrefixStorage ;
+import org.seaborne.dboe.base.file.* ;
+import org.seaborne.dboe.base.record.RecordFactory ;
+import org.seaborne.dboe.index.Index ;
+import org.seaborne.dboe.index.IndexParams ;
+import org.seaborne.dboe.index.RangeIndex ;
+import org.seaborne.dboe.trans.bplustree.BPlusTree ;
+import org.seaborne.dboe.trans.bplustree.BPlusTreeFactory ;
+import org.seaborne.tdb2.setup.StoreParams ;
+import org.seaborne.tdb2.setup.TDBBuilder ;
+import org.seaborne.tdb2.store.DatasetGraphTDB ;
+import org.seaborne.tdb2.store.nodetable.NodeTable ;
+import org.seaborne.tdb2.store.nodetable.NodeTableCache ;
+import org.seaborne.tdb2.store.nodetable.NodeTableInline ;
+import org.seaborne.tdb2.store.nodetable.NodeTableTRDF ;
+import org.seaborne.tdb2.sys.SystemTDB ;
+
+/** Build things for non-transactional tests.
+ * Sometimes, create a daatset and find the relevant part. 
+ */
+public class BuildTestLib {
+
+    public static RangeIndex buildRangeIndex(FileSet mem, RecordFactory factory, IndexParams indexParams) {
+        BPlusTree bpt = BPlusTreeFactory.makeMem(5, factory.keyLength(), factory.valueLength()) ;
+        bpt.nonTransactional() ;
+        return bpt ; 
+    }
+
+    public static NodeTable makeNodeTable(Location location, String basename, StoreParams params) {
+        NodeTable nt = makeNodeTableBase(location, basename, params) ;
+        nt = NodeTableCache.create(nt, params) ;
+        nt = NodeTableInline.create(nt) ;
+        return nt ;
+    }
+    
+    public static NodeTable makeNodeTableBase(Location location, String basename, StoreParams params) {
+        RecordFactory recordFactory = new RecordFactory(SystemTDB.LenNodeHash, SystemTDB.SizeOfNodeId) ;
+        FileSet fs = new FileSet(location, basename) ;
+                
+        Index index = buildRangeIndex(fs, recordFactory, params) ;
+        BinaryDataFile bdf = createBinaryDataFile(location, basename+"-data") ;
+        NodeTable nt = new NodeTableTRDF(index, bdf) ;
+        return nt ;
+    }
+
+    public static DatasetPrefixStorage makePrefixes(Location location) {
+        DatasetGraphTDB ds = (DatasetGraphTDB)TDBBuilder.build(location) ;
+        ds.begin(ReadWrite.WRITE);
+        return ds.getPrefixes() ; 
+    }
+    
+    /** Create a non-thread-safe BinaryDataFile*/ 
+    public static BinaryDataFile createBinaryDataFile(Location loc, String name) {
+        if ( loc.isMem() )
+            return new BinaryDataFileMem() ;
+        String filename = loc.getPath(name) ;
+        return new BinaryDataFileRandomAccess(filename) ;
+    }
+
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java
new file mode 100644
index 0000000..3bbc484
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/QueryTestTDB.java
@@ -0,0 +1,193 @@
+/*
+ * 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.tdb2.junit;
+
+import java.util.List ;
+
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.sparql.SystemARQ ;
+import org.apache.jena.sparql.engine.QueryEngineFactory ;
+import org.apache.jena.sparql.engine.QueryExecutionBase ;
+import org.apache.jena.sparql.engine.ref.QueryEngineRef ;
+import org.apache.jena.sparql.junit.EarlReport ;
+import org.apache.jena.sparql.junit.EarlTestCase ;
+import org.apache.jena.sparql.junit.TestItem ;
+import org.apache.jena.sparql.resultset.ResultSetCompare ;
+import org.apache.jena.sparql.resultset.SPARQLResult ;
+import org.apache.jena.util.FileManager ;
+import org.seaborne.dboe.jenax.Txn ;
+import org.seaborne.tdb2.TDB2Factory ;
+import org.slf4j.Logger ;
+import org.slf4j.LoggerFactory ;
+
+public class QueryTestTDB extends EarlTestCase
+{
+    // Changed to using in-memory graphs/datasets because this is testing the query
+    // processing.  Physical graph/datsets is in package "store". 
+    
+    private static Logger log = LoggerFactory.getLogger(QueryTestTDB.class) ;
+    private Dataset dataset = null ;
+
+    boolean skipThisTest = false ;
+
+    final List<String> defaultGraphURIs ;
+    final List<String> namedGraphURIs ;
+    final String queryFile ; 
+    final SPARQLResult results ;
+    
+    // Track what's currently loaded in the GraphLocation
+    private static List<String> currentDefaultGraphs = null ;
+    private static List<String> currentNamedGraphs = null ;
+
+    // Old style (Junit3)
+    public QueryTestTDB(String testName, EarlReport report, TestItem item)
+    {
+        this(testName, report, item.getURI(), 
+             item.getDefaultGraphURIs(), item.getNamedGraphURIs(), 
+             item.getResults(), item.getQueryFile()
+             ) ;
+    }
+    
+    public QueryTestTDB(String testName, EarlReport report, 
+                        String uri,
+                        List<String> dftGraphs,
+                        List<String> namedGraphs,
+                        SPARQLResult rs,
+                        String queryFile
+                        )
+    {
+        super(testName, uri, report) ;
+        this.defaultGraphURIs = dftGraphs ;
+        this.namedGraphURIs = namedGraphs ;
+        this.queryFile = queryFile ;
+        this.results = rs ;
+    }
+    
+    boolean oldValueUsePlainGraph = SystemARQ.UsePlainGraph ;
+    
+    @Override public void setUpTest() {
+        dataset = TDB2Factory.createDataset() ;
+        Txn.executeWrite(dataset, ()->{
+            setupData() ;
+        }) ;
+        // Make sure a plain, no sameValueAs graph is used.
+        oldValueUsePlainGraph = SystemARQ.UsePlainGraph ;
+        SystemARQ.UsePlainGraph = true ;
+    }
+    
+    @Override public void tearDownTest()
+    { 
+        if ( dataset != null )
+        {
+            dataset.close() ;
+            dataset = null ;
+        }
+        SystemARQ.UsePlainGraph = oldValueUsePlainGraph ;
+    }
+    
+    public void setupData()
+    {
+        if ( compareLists(defaultGraphURIs, currentDefaultGraphs) &&
+             compareLists(namedGraphURIs, currentNamedGraphs) )
+            return ;
+        
+        if ( defaultGraphURIs == null )
+            throw new TDBTestException("No default graphs given") ;
+
+        //graphLocation.clear() ;
+        
+        for ( String fn : defaultGraphURIs )
+            load(dataset.getDefaultModel(), fn) ;
+        
+        for ( String fn : namedGraphURIs )
+            load(dataset.getNamedModel(fn), fn) ;
+    }
+    
+    
+    @Override
+    protected void runTestForReal() throws Throwable
+    {
+        if ( skipThisTest )
+        {
+            log.info(this.getName()+" : Skipped") ;
+            return ;
+        }
+        
+        Query query = QueryFactory.read(queryFile) ;
+        Dataset ds = DatasetFactory.create(defaultGraphURIs, namedGraphURIs) ;
+        
+        // ---- First, get the expected results by executing in-memory or from a results file.
+        
+        ResultSetRewindable rs1$ = null ;
+        String expectedLabel$ = "" ;
+        if ( results != null )
+        {
+            rs1$ = ResultSetFactory.makeRewindable(results.getResultSet()) ;
+            expectedLabel$ = "Results file" ;
+        }
+        else
+        {
+            QueryEngineFactory f = QueryEngineRef.getFactory() ;
+            try(QueryExecution qExec1 = new QueryExecutionBase(query, ds, null, f)) {
+                rs1$ = ResultSetFactory.makeRewindable(qExec1.execSelect()) ;
+            }
+            expectedLabel$ = "Standard engine" ;
+        }
+        // Effectively final.
+        ResultSetRewindable rs1 = rs1$ ;
+        String expectedLabel = expectedLabel$ ;
+        // ---- Second, execute in persistent graph
+
+        Dataset ds2 = dataset ; //DatasetFactory.create(model) ;
+        Txn.executeRead(ds2, ()->{
+            try(QueryExecution qExec2 = QueryExecutionFactory.create(query, ds2)) {
+                ResultSet rs = qExec2.execSelect() ;
+                ResultSetRewindable rs2 = ResultSetFactory.makeRewindable(rs) ;
+
+                // See if the same.
+                boolean b = ResultSetCompare.equalsByValue(rs1, rs2) ;
+                if ( !b )
+                {
+                    rs1.reset() ;
+                    rs2.reset() ;
+                    System.out.println("------------------- "+this.getName());
+                    System.out.printf("**** Expected (%s)", expectedLabel) ;
+                    ResultSetFormatter.out(System.out, rs1) ; 
+                    System.out.println("**** Got (TDB)") ;
+                    ResultSetFormatter.out(System.out, rs2) ;
+                }
+
+                assertTrue("Results sets not the same", b) ;
+            }
+        }) ;
+    }
+
+    private static void load(Model model, String fn)
+    {
+        FileManager.get().readModel(model, fn) ;
+    }
+    
+    private static boolean compareLists(List<String> list1, List<String> list2)
+    {
+        if ( list1 == null )
+            return ( list2 == null ) ;
+        return list1.equals(list2) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java
new file mode 100644
index 0000000..f94c91c
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TDBTestException.java
@@ -0,0 +1,29 @@
+/*
+ * 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.tdb2.junit;
+
+import org.seaborne.tdb2.TDBException ;
+
+public class TDBTestException extends TDBException
+{
+    public TDBTestException() {}
+    public TDBTestException(String msg) { super(msg) ; }
+    public TDBTestException(Throwable th) { super(th) ;}
+    public TDBTestException(String msg, Throwable th) { super(msg, th) ; }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java
new file mode 100644
index 0000000..449e4c6
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TL.java
@@ -0,0 +1,90 @@
+/*
+ * 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.tdb2.junit;
+
+import java.util.function.Consumer ;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.system.Txn ;
+import org.seaborne.dboe.base.file.Location ;
+import org.seaborne.tdb2.ConfigTest ;
+import org.seaborne.tdb2.DatabaseMgr ;
+import org.seaborne.tdb2.TDB2Factory ;
+import org.seaborne.tdb2.sys.TDBInternal ;
+
+/** Support for tests to be less "transaction-y" */
+public class TL {
+    
+    public static void exec(Consumer<Dataset> action) {
+        Dataset dataset = createTestDataset();
+        try { 
+            Txn.executeWrite(dataset, ()->action.accept(dataset));
+            //TDBInternal.reset();
+            
+        } finally { expel(dataset); } 
+    }
+    
+    public static void execMem(Consumer<Dataset> action) {
+        Dataset dataset = createTestDatasetMem() ;
+        Txn.executeWrite(dataset, ()->action.accept(dataset));
+        expel(dataset);
+    }
+    
+    public static void expel(Dataset dataset) {
+        expel(dataset.asDatasetGraph());
+    }
+
+    public static void expel(DatasetGraph dataset) {
+        TDBInternal.expel(dataset);
+    }
+
+    // Or use these for @Before, @After style.
+    
+    public static Location cleanLocation() {
+        // To avoid the problems on MS Windows where memory mapped files
+        // can't be deleted from a running JVM, we use a different, cleaned 
+        // directory each time.
+        String dirname = ConfigTest.getCleanDir() ;
+        Location location = Location.create(dirname) ;
+        return location ;
+    }
+    
+    private static void releaseDataset(Dataset dataset) {
+        dataset.abort() ;
+        expel(dataset);
+    }
+
+    private static Dataset createTestDataset() {
+        Location location = cleanLocation() ;
+        Dataset dataset = TDB2Factory.connectDataset(location) ;
+        return dataset ;
+    }
+    
+    public static Dataset createTestDatasetMem() {
+        Dataset dataset = TDB2Factory.createDataset() ;
+        return dataset ;
+    }
+
+    public static DatasetGraph createTestDatasetGraphMem() {
+        DatasetGraph dataset = DatabaseMgr.createDatasetGraph() ;
+        return dataset ;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java
new file mode 100644
index 0000000..0a95dbc
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/junit/TestFactoryTDB.java
@@ -0,0 +1,88 @@
+/*
+ * 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.tdb2.junit;
+
+import junit.framework.Test ;
+import junit.framework.TestCase ;
+import junit.framework.TestSuite ;
+import org.apache.jena.rdf.model.Resource ;
+import org.apache.jena.sparql.junit.EarlReport ;
+import org.apache.jena.sparql.junit.SurpressedTest ;
+import org.apache.jena.sparql.junit.TestItem ;
+import org.apache.jena.sparql.vocabulary.TestManifestX ;
+import org.apache.jena.util.junit.TestFactoryManifest ;
+
+public class TestFactoryTDB extends TestFactoryManifest
+{
+    public static EarlReport report = null ;
+    
+    public static void make(TestSuite ts, String manifestFile, String testRootName)
+    {
+        // for each graph type do
+        TestSuite ts2 = makeSuite(manifestFile, testRootName) ;
+        ts.addTest(ts2) ;
+    }
+    
+    public static TestSuite makeSuite(String manifestFile, String testRootName)
+    {
+        TestFactoryTDB f = new TestFactoryTDB(testRootName) ;
+        TestSuite ts = f.process(manifestFile) ;
+        if ( testRootName != null )
+            ts.setName(testRootName+ts.getName()) ;
+        return ts ;
+    }
+    
+    // Factory
+    
+    public String testRootName ;
+
+    public TestFactoryTDB(String testRootName)
+    {
+        this.testRootName = testRootName ;
+    }
+    
+    @Override
+    protected Test makeTest(Resource manifest, Resource entry, String testName, Resource action, Resource result)
+    {
+        if ( testRootName != null )
+            testName = testRootName+testName ;
+        
+        TestItem testItem = TestItem.create(entry, null) ;
+        
+        TestCase test = null ;
+        
+        if ( testItem.getTestType() != null )
+        {
+            if ( testItem.getTestType().equals(TestManifestX.TestQuery) )
+                test = new QueryTestTDB(testName, report, testItem) ;
+            
+            if ( testItem.getTestType().equals(TestManifestX.TestSurpressed) )
+                test = new SurpressedTest(testName, report, testItem) ;
+            
+            if ( test == null )
+                System.err.println("Unrecognized test type: "+testItem.getTestType()) ;
+        }
+        // Default 
+        if ( test == null )
+            test = new QueryTestTDB(testName, report, testItem) ;
+
+        return test ;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java
new file mode 100644
index 0000000..2453a16
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java
@@ -0,0 +1,34 @@
+/*
+ * 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.tdb2.lib;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.seaborne.tdb2.lib.TestNodeLib ;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+    TestNodeLib.class
+})
+
+
+public class TS_LibTDB
+{
+
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java
new file mode 100644
index 0000000..e3d9447
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java
@@ -0,0 +1,70 @@
+/*
+ * 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.tdb2.lib;
+
+import static org.seaborne.tdb2.lib.NodeLib.hash ;
+import static org.junit.Assert.*;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+import org.junit.Test ;
+
+public class TestNodeLib
+{
+    // Tests of TDBs NodeLib
+    @Test public void hash1() 
+    {
+        Node x1 = NodeFactoryExtra.parseNode("<http://example/x>") ;
+        Node x2 = NodeFactoryExtra.parseNode("<http://example/x>") ;
+        assertEquals(hash(x1), hash(x2)) ;
+    }
+    
+    @Test public void hash2() 
+    {
+        Node x1 = NodeFactoryExtra.parseNode("<http://example/x1>") ;
+        Node x2 = NodeFactoryExtra.parseNode("<http://example/x2>") ;
+        assertNotEquals(hash(x1), hash(x2)) ;
+    }
+    
+    @Test public void hash3() 
+    {
+        Node x1 = NodeFactoryExtra.parseNode("<lex>") ;
+        Node x2 = NodeFactoryExtra.parseNode("'lex'") ;
+        Node x3 = NodeFactoryExtra.parseNode("_:lex") ;
+        assertNotEquals(hash(x1), hash(x2)) ;
+        assertNotEquals(hash(x2), hash(x3)) ;
+        assertNotEquals(hash(x3), hash(x1)) ;
+    }
+    
+    @Test public void hash4() 
+    {
+        Node x1 = NodeFactoryExtra.parseNode("123") ;
+        Node x2 = NodeFactoryExtra.parseNode("'123'") ;
+        assertNotEquals(hash(x1), hash(x2)) ;
+    }
+
+    @Test public void hash5() 
+    {
+        Node x1 = NodeFactoryExtra.parseNode("123") ;
+        Node x2 = NodeFactoryExtra.parseNode("123.0") ;
+        Node x3 = NodeFactoryExtra.parseNode("123e0") ;
+        assertNotEquals(hash(x1), hash(x2)) ;
+        assertNotEquals(hash(x2), hash(x3)) ;
+        assertNotEquals(hash(x3), hash(x1)) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java
new file mode 100644
index 0000000..0714358
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java
@@ -0,0 +1,33 @@
+/*
+ * 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.tdb2.setup;
+
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+    TestStoreParams.class
+    , TestStoreParamsChoose.class
+    , TestStoreParamsCreate.class
+})
+public class TS_TDBSetup {
+    
+}
+

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java
new file mode 100644
index 0000000..248dcef
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java
@@ -0,0 +1,145 @@
+/*
+ * 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.tdb2.setup;
+
+import org.apache.jena.atlas.json.JSON ;
+import org.apache.jena.atlas.json.JsonObject ;
+import static org.junit.Assert.*;
+import org.junit.Test ;
+import org.seaborne.dboe.base.block.FileMode ;
+import org.seaborne.tdb2.TDBException ;
+import org.seaborne.tdb2.setup.StoreParams ;
+import org.seaborne.tdb2.setup.StoreParamsBuilder ;
+import org.seaborne.tdb2.setup.StoreParamsCodec ;
+
+public class TestStoreParams {
+
+    @Test public void store_params_01() {
+        assertEqualsStoreParams(StoreParams.getDftStoreParams(), StoreParams.getDftStoreParams()) ; 
+    }
+    
+    @Test public void store_params_02() {
+        StoreParams input = StoreParams.getDftStoreParams() ;
+        StoreParams sp = StoreParams.builder(input).build() ;
+        assertEqualsStoreParams(StoreParams.getDftStoreParams(), sp) ; 
+    }
+
+    @Test public void store_params_03() {
+        StoreParams sp = StoreParams.builder().build() ;
+        assertEqualsStoreParams(StoreParams.getDftStoreParams(), sp) ; 
+    }
+
+    @Test public void store_params_04() {
+        StoreParams params = StoreParams.builder().build() ;
+        StoreParams params2 = roundTrip(params) ;
+        assertEqualsStoreParams(params,params2) ;
+    }
+    
+    // ----
+    
+    @Test public void store_params_10() {
+        StoreParams params = StoreParams.builder().fileMode(FileMode.direct).blockSize(1024).build() ;
+        StoreParams params2 = roundTrip(params) ;
+        assertEqualsStoreParams(params,params2) ;
+        assertEquals(params.getFileMode(), params2.getFileMode()) ;
+        assertEquals(params.getBlockSize(), params2.getBlockSize()) ;
+    }
+
+    @Test public void store_params_11() {
+        String xs = "{ \"tdb.block_size\": 2048 }" ;
+        JsonObject x = JSON.parse(xs) ;
+        StoreParams paramsExpected = StoreParams.builder().blockSize(2048).build() ;
+        StoreParams paramsActual = StoreParamsCodec.decode(x) ;
+        assertEqualsStoreParams(paramsExpected,paramsActual) ;
+    }
+
+    @Test public void store_params_12() {
+        String xs = "{ \"tdb.file_mode\": \"direct\" , \"tdb.block_size\": 2048 }" ;
+        JsonObject x = JSON.parse(xs) ;
+        StoreParams paramsExpected = StoreParams.builder().blockSize(2048).fileMode(FileMode.direct).build() ;
+        StoreParams paramsActual = StoreParamsCodec.decode(x) ;
+        assertEqualsStoreParams(paramsExpected,paramsActual) ;
+    }
+
+    @Test public void store_params_13() {
+        String xs = "{ \"tdb.triple_indexes\" : [ \"POS\" , \"PSO\"] } " ; 
+        JsonObject x = JSON.parse(xs) ;
+        StoreParams params = StoreParamsCodec.decode(x) ;
+        String[] expected =  { "POS" , "PSO" } ;
+        assertArrayEquals(expected, params.getTripleIndexes()) ;
+    }
+
+    @Test(expected=TDBException.class)
+    public void store_params_14() {
+        String xs = "{ \"tdb.triples_indexes\" : [ \"POS\" , \"PSO\"] } " ; // Misspelt. 
+        JsonObject x = JSON.parse(xs) ;
+        StoreParams params = StoreParamsCodec.decode(x) ;
+        String[] expected =  { "POS" , "PSO" } ;
+        assertArrayEquals(expected, params.getTripleIndexes()) ;
+    }
+
+    // Check that setting gets recorded and propagated.
+
+    @Test public void store_params_20() {
+        StoreParams params = StoreParams.builder().blockReadCacheSize(0).build();
+        assertTrue(params.isSetBlockReadCacheSize()) ;
+        assertFalse(params.isSetBlockWriteCacheSize()) ;
+    }
+    
+    @Test public void store_params_21() {
+        StoreParams params1 = StoreParams.builder().blockReadCacheSize(0).build();
+        assertTrue(params1.isSetBlockReadCacheSize()) ;
+        assertFalse(params1.isSetBlockWriteCacheSize()) ;
+        StoreParams params2 = StoreParams.builder(params1).blockWriteCacheSize(0).build();
+        assertTrue(params2.isSetBlockReadCacheSize()) ;
+        assertTrue(params2.isSetBlockWriteCacheSize()) ;
+        assertFalse(params2.isSetNodeMissCacheSize()) ;
+    }
+
+    // Modify
+    @Test public void store_params_22() {
+        StoreParams params1 = StoreParams.builder()
+            .blockReadCacheSize(0)
+            .blockWriteCacheSize(1)
+            .build();
+        StoreParams params2 = StoreParams.builder()
+            .blockReadCacheSize(5)
+            .build();
+        StoreParams params3 = StoreParamsBuilder.modify(params1, params2) ;
+        assertFalse(params2.isSetBlockWriteCacheSize()) ;
+        assertTrue(params3.isSetBlockReadCacheSize()) ;
+        assertTrue(params3.isSetBlockWriteCacheSize()) ;
+        assertEquals(5, params3.getBlockReadCacheSize().intValue()) ;   // From params2
+        assertEquals(1, params3.getBlockWriteCacheSize().intValue()) ;  // From params1, not params2(unset)
+        
+    }
+
+    
+    // --------
+    
+    private static StoreParams roundTrip(StoreParams params) {
+        JsonObject obj = StoreParamsCodec.encodeToJson(params) ;
+        StoreParams params2 = StoreParamsCodec.decode(obj) ;
+        return params2 ;
+    }
+    
+    private static void assertEqualsStoreParams(StoreParams params1, StoreParams params2) {
+        assertTrue(StoreParams.sameValues(params1, params2)) ;
+    }
+}

http://git-wip-us.apache.org/repos/asf/jena/blob/1dabea3a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java
new file mode 100644
index 0000000..3e828c4
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java
@@ -0,0 +1,158 @@
+/*
+ * 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.tdb2.setup;
+
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.junit.Test ;
+import org.seaborne.dboe.base.file.Location ;
+import org.seaborne.dboe.sys.Names;
+import org.seaborne.tdb2.ConfigTest ;
+
+//TestParamsCreate
+/** This test suite uses on-disk structures and can be slow */ 
+public class TestStoreParamsChoose {
+    private String DIR = ConfigTest.getCleanDir() ;
+    
+    static final StoreParams pApp = StoreParams.builder()
+        .blockSize(12)              // Not dynamic
+        .nodeMissCacheSize(12)      // Dynamic
+        .build();
+    static final StoreParams pLoc = StoreParams.builder()
+        .blockSize(0)
+        .nodeMissCacheSize(0).build();
+    
+    static final StoreParams pDft = StoreParams.getDftStoreParams() ;
+
+    @Test public void params_choose_new_1() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), true, null, null, pDft) ;
+        // New store, no pLoc, no pApp so pDft.
+        assertTrue(StoreParams.sameValues(p, pDft)) ;
+    }
+    
+    @Test public void params_choose_new_2() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), true, pApp, null, pDft) ;
+        // New store, no pLoc, so pApp is the enire settings.
+        assertEquals(12, p.getBlockSize().intValue()) ;
+        assertTrue(StoreParams.sameValues(p, pApp)) ;
+    }
+
+    @Test public void params_choose_new_3() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), true, null, pLoc, pDft) ;
+        // New store, pLoc, no pApp, so pLoc is the entire settings.
+        assertEquals(0, p.getBlockSize().intValue()) ;
+        assertTrue(StoreParams.sameValues(p, pLoc)) ;
+    }
+
+    @Test public void params_choose_new_4() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), true, pApp, pLoc, pDft) ;
+        // New store, pLoc, no pApp, so pLoc is the entire settings.
+        
+        assertFalse(StoreParams.sameValues(p, pApp)) ;
+        assertFalse(StoreParams.sameValues(p, pLoc)) ;
+        assertFalse(StoreParams.sameValues(p, pDft)) ;
+        
+        assertEquals(0, p.getBlockSize().intValue()) ;
+        assertEquals(12,  p.getNodeMissCacheSize().intValue()) ;
+    }
+
+    @Test public void params_choose_existing_1() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), false, null, null, pDft) ;
+        // p is pDft.
+        assertTrue(StoreParams.sameValues(p, pDft)) ;
+    }
+
+    @Test public void params_choose_existing_2() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), false, pApp, null, pDft) ;
+        // p is pLoc modified by pApp
+        assertFalse(StoreParams.sameValues(p, pApp)) ;
+        assertFalse(StoreParams.sameValues(p, pDft)) ;
+        // Existing store, no pLoc, so pDft is implicit pLoc and fixed the block size.  
+        assertEquals(pDft.getBlockSize(), p.getBlockSize()) ;
+        assertEquals(12, p.getNodeMissCacheSize().intValue()) ;
+    }
+    
+    @Test public void params_choose_existing_3() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), false, null, pLoc, pDft) ;
+        // p is pLoc
+        assertTrue(StoreParams.sameValues(p, pLoc)) ;
+        
+    }
+
+    @Test public void params_choose_existing_4() {
+        StoreParams p = StoreParamsFactory.decideStoreParams(Location.mem(), false, pApp, pLoc, pDft) ;
+        // p is pLoc modifed by pApp.
+        assertFalse(StoreParams.sameValues(p, pApp)) ;
+        assertFalse(StoreParams.sameValues(p, pLoc)) ;
+        assertFalse(StoreParams.sameValues(p, pDft)) ;
+        
+        assertEquals(0, p.getBlockSize().intValue()) ;
+        assertEquals(12,  p.getNodeMissCacheSize().intValue()) ;
+    }
+    
+    @Test public void params_choose_new_persist_1() {
+        // new database, app defined.
+        Location loc = Location.create(DIR) ;
+        FileOps.clearAll(loc.getDirectoryPath());
+        // Clear.
+        StoreParams p = StoreParamsFactory.decideStoreParams(loc, true, pApp, null, pDft) ;
+        // Check location now has a pLoc.
+        String fn = loc.getPath(Names.TDB_CONFIG_FILE) ;
+        assertTrue(FileOps.exists(fn)) ;
+
+        StoreParams pLoc2 = StoreParamsCodec.read(loc) ;
+        assertTrue(StoreParams.sameValues(pLoc2, p)) ;
+    }
+    
+    @Test public void params_choose_new_persist_2() {
+        // new database, location defined.
+        Location loc = Location.create(DIR) ;
+        FileOps.clearAll(loc.getDirectoryPath());
+        StoreParamsCodec.write(loc, pLoc); 
+        
+        // Clear.
+        StoreParams p = StoreParamsFactory.decideStoreParams(loc, true, null, pLoc, pDft) ;
+        // Check location still has a pLoc.
+        String fn = loc.getPath(Names.TDB_CONFIG_FILE) ;
+        assertTrue(FileOps.exists(fn)) ;
+
+        StoreParams pLoc2 = StoreParamsCodec.read(loc) ;
+        assertTrue(StoreParams.sameValues(pLoc, p)) ;
+    }
+
+    @Test public void params_choose_new_persist_3() {
+        // new database, location defined, application modified.
+        Location loc = Location.create(DIR) ;
+        FileOps.clearAll(loc.getDirectoryPath());
+        StoreParamsCodec.write(loc, pLoc); 
+        
+        // Clear.
+        StoreParams p = StoreParamsFactory.decideStoreParams(loc, true, pApp, pLoc, pDft) ;
+        // Check location still has a pLoc.
+        String fn = loc.getPath(Names.TDB_CONFIG_FILE) ;
+        assertTrue(FileOps.exists(fn)) ;
+
+        StoreParams pLoc2 = StoreParamsCodec.read(loc) ;
+        assertFalse(StoreParams.sameValues(pLoc, p)) ;
+        assertEquals(0, p.getBlockSize().intValue()) ;  // Location
+        assertEquals(12, p.getNodeMissCacheSize().intValue()) ;  // Application
+    }
+
+}
+