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 11:08:43 UTC
[27/50] [abbrv] jena git commit: JENA-1396: Merge //github/afs/mantis
as subdirectory jena-db/
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java
index 0000000,0000000..df245fb
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/lib/TS_LibTDB.java
@@@ -1,0 -1,0 +1,33 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++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/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java
index 0000000,0000000..3e85f41
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/lib/TestNodeLib.java
@@@ -1,0 -1,0 +1,69 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++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/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java
index 0000000,0000000..8f99097
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TS_TDBSetup.java
@@@ -1,0 -1,0 +1,32 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++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/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java
index 0000000,0000000..0d8468c
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParams.java
@@@ -1,0 -1,0 +1,144 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++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/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java
index 0000000,0000000..2b20d54
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsChoose.java
@@@ -1,0 -1,0 +1,157 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++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
++ }
++
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsCreate.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsCreate.java
index 0000000,0000000..071b135
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/setup/TestStoreParamsCreate.java
@@@ -1,0 -1,0 +1,180 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.setup;
++
++import static org.junit.Assert.assertEquals ;
++import static org.junit.Assert.assertFalse ;
++import static org.junit.Assert.assertNotEquals ;
++import static org.junit.Assert.assertNotNull ;
++import static org.junit.Assert.assertNull ;
++import static org.junit.Assert.assertTrue ;
++
++import java.nio.file.Files ;
++import java.nio.file.Path ;
++import java.nio.file.Paths ;
++
++import org.apache.jena.atlas.json.JSON ;
++import org.apache.jena.atlas.json.JsonObject ;
++import org.apache.jena.atlas.lib.FileOps ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.junit.Test ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.dboe.sys.Names;
++import org.seaborne.tdb2.ConfigTest ;
++import org.seaborne.tdb2.sys.StoreConnection ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++/**
++ * This test suite uses on-disk structures, does a lot of clean/create/sync
++ * calls and can be noticably slow.
++ */
++public class TestStoreParamsCreate {
++ // Thse tests work on storage locations.
++ private final String DB_DIR = ConfigTest.getCleanDir() ;
++ private final Path db = Paths.get(DB_DIR) ;
++ private final Path cfg = Paths.get(DB_DIR, Names.TDB_CONFIG_FILE) ;
++ private final Location loc = Location.create(DB_DIR) ;
++
++ static final StoreParams pApp = StoreParams.getSmallStoreParams() ;
++ static final StoreParams pDft = StoreParams.getDftStoreParams() ;
++ static final StoreParams pSpecial = StoreParams.builder(pApp)
++ .blockSize(1024)
++ .blockReadCacheSize(4)
++ .build();
++
++ private void expel() {
++ StoreConnection.internalExpel(loc, true);
++ }
++
++ @Before public void clearupTest() {
++ // Flush and clean.
++ TDBInternal.reset();
++ FileOps.clearAll(loc.getDirectoryPath());
++ }
++
++ @After public void expelDatabase() {
++ expel();
++ }
++
++ @Test public void params_create_01() {
++ StoreConnection.connectCreate(loc) ;
++ // Check. Default setup, no params.
++ assertTrue("DB directory", Files.exists(db)) ;
++ assertFalse("Config file unexpectedly found", Files.exists(cfg)) ;
++ }
++
++ @Test public void params_create_02() {
++ StoreConnection.connectCreate(loc, pApp) ;
++ // Check. Custom setup.
++ assertTrue("DB directory", Files.exists(db)) ;
++ assertTrue("Config file not found", Files.exists(cfg)) ;
++ StoreParams pLoc = StoreParamsCodec.read(loc) ;
++ assertTrue(StoreParams.sameValues(pLoc, pApp)) ;
++ }
++
++ // Defaults
++ @Test public void params_reconnect_01() {
++ // Create.
++ StoreConnection.connectCreate(loc) ;
++ // Drop.
++ expel();
++ // Reconnect
++ StoreConnection.connectCreate(loc, null) ;
++ StoreParams pLoc = StoreParamsCodec.read(loc) ;
++ assertNull(pLoc) ;
++
++ StoreParams pDB = StoreConnection.connectExisting(loc).getDatasetGraphTDB().getStoreParams() ;
++ assertNotNull(pDB) ;
++ // Should be the default setup.
++ assertTrue(StoreParams.sameValues(pDft, pDB)) ;
++ }
++
++ // Defaults, then reconnect with app modified.
++ @Test public void params_reconnect_02() {
++ // Create.
++ StoreConnection.connectCreate(loc, null) ;
++ // Drop.
++ expel();
++ // Reconnect
++ StoreConnection.connectCreate(loc, pSpecial) ;
++ //StoreParams pLoc = StoreParamsCodec.read(loc) ;
++ //assertNotNull(pLoc) ;
++
++ StoreParams pDB = StoreConnection.connectExisting(loc).getDatasetGraphTDB().getStoreParams() ;
++ assertNotNull(pDB) ;
++ // Should be the default setup, modified by pApp for cache sizes.
++ assertFalse(StoreParams.sameValues(pDft, pDB)) ;
++ assertFalse(StoreParams.sameValues(pSpecial, pDB)) ;
++
++ // Check it's default-modified-by-special.
++ assertEquals(pSpecial.getBlockReadCacheSize(), pDB.getBlockReadCacheSize()) ;
++ assertNotEquals(pDft.getBlockReadCacheSize(), pDB.getBlockReadCacheSize()) ;
++
++ assertNotEquals(pSpecial.getBlockSize(), pDB.getBlockSize()) ;
++ assertEquals(pDft.getBlockSize(), pDB.getBlockSize()) ;
++ }
++
++ // Custom, then reconnect with some special settings.
++ @Test public void params_reconnect_03() {
++ // Create.
++ StoreConnection.connectCreate(loc, pApp) ;
++ // Drop.
++ expel();
++ // Reconnect
++ StoreConnection.connectCreate(loc, pSpecial) ;
++ //StoreParams pLoc = StoreParamsCodec.read(loc) ;
++ //assertNotNull(pLoc) ;
++
++ StoreParams pDB = StoreConnection.connectExisting(loc).getDatasetGraphTDB().getStoreParams() ;
++ assertNotNull(pDB) ;
++ // Should be the default setup, modified by pApp for cache sizes.
++ assertFalse(StoreParams.sameValues(pApp, pDB)) ;
++ assertFalse(StoreParams.sameValues(pSpecial, pDB)) ;
++
++ // Check it's default-modified-by-special.
++ assertEquals(pSpecial.getBlockReadCacheSize(), pDB.getBlockReadCacheSize()) ;
++ assertNotEquals(pApp.getBlockReadCacheSize(), pDB.getBlockReadCacheSize()) ;
++
++ assertNotEquals(pSpecial.getBlockSize(), pDB.getBlockSize()) ;
++ assertEquals(pApp.getBlockSize(), pDB.getBlockSize()) ;
++ }
++
++
++// // Custom then modified.
++// @Test public void params_reconnect_03() {
++// // Create.
++// StoreConnection.connectCreate(loc, pLoc) ;
++// // Drop.
++// StoreConnection.expel(loc, true) ;
++// // Reconnect
++// StoreConnection.connectCreate(loc, pApp) ;
++// StoreParams pLoc = StoreParamsCodec.read(loc) ;
++// assertFalse(StoreParams.sameValues(pApp, pLoc)) ;
++// assertFalse(StoreParams.sameValues(pApp, pLoc)) ;
++// }
++
++ // Dataset tests
++
++ static StoreParams read(Location location) {
++ String fn = location.getPath(Names.TDB_CONFIG_FILE) ;
++ JsonObject obj = JSON.read(fn) ;
++ return StoreParamsCodec.decode(obj) ;
++ }
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TS_SolverTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TS_SolverTDB.java
index 0000000,0000000..f52d8ad
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TS_SolverTDB.java
@@@ -1,0 -1,0 +1,30 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.solver;
++
++import org.junit.runner.RunWith ;
++import org.junit.runners.Suite ;
++
++@RunWith(Suite.class)
++@Suite.SuiteClasses( {
++ TestSolverTDB.class // Tests the TDB connectivity
++ , TestStats.class
++})
++
++public class TS_SolverTDB
++{}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TestSolverTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TestSolverTDB.java
index 0000000,0000000..43ef56d
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TestSolverTDB.java
@@@ -1,0 -1,0 +1,171 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.solver;
++
++
++import java.util.ArrayList ;
++import java.util.Iterator ;
++import java.util.List ;
++
++import static org.junit.Assert.*;
++import org.apache.jena.graph.Graph ;
++import org.apache.jena.graph.Node ;
++import org.apache.jena.graph.Triple ;
++import org.apache.jena.query.* ;
++import org.apache.jena.riot.RDFDataMgr ;
++import org.apache.jena.shared.PrefixMapping ;
++import org.apache.jena.shared.impl.PrefixMappingImpl ;
++import org.apache.jena.sparql.algebra.Algebra ;
++import org.apache.jena.sparql.algebra.Op ;
++import org.apache.jena.sparql.algebra.OpVars ;
++import org.apache.jena.sparql.core.Var ;
++import org.apache.jena.sparql.engine.QueryIterator ;
++import org.apache.jena.sparql.engine.binding.Binding ;
++import org.apache.jena.sparql.resultset.ResultSetCompare ;
++import org.apache.jena.sparql.sse.SSE ;
++import org.junit.AfterClass ;
++import org.junit.BeforeClass ;
++import org.junit.Test ;
++import org.seaborne.tdb2.ConfigTest ;
++import org.seaborne.tdb2.junit.TL ;
++
++public class TestSolverTDB
++{
++ static String graphData = null ;
++ static Graph graph = null ;
++ static Dataset dataset = null ;
++ static PrefixMapping pmap = null ;
++
++ @BeforeClass static public void beforeClass()
++ {
++ dataset = TL.createTestDatasetMem() ;
++ dataset.begin(ReadWrite.WRITE);
++ graphData = ConfigTest.getTestingDataRoot()+"/Data/solver-data.ttl" ;
++ RDFDataMgr.read(dataset, graphData) ;
++ graph = dataset.asDatasetGraph().getDefaultGraph() ;
++ pmap = new PrefixMappingImpl() ;
++ pmap.setNsPrefix("", "http://example/") ;
++ }
++
++
++ @AfterClass static public void afterClass() {
++ dataset.abort();
++ TL.expel(dataset);
++ }
++
++ static private void addAll(Graph srcGraph, Graph dstGraph)
++ {
++ Iterator<Triple> triples = srcGraph.find(Node.ANY, Node.ANY, Node.ANY) ;
++ triples.forEachRemaining(dstGraph::add) ;
++ }
++
++
++ @Test public void solve_01()
++ {
++ ResultSet rs1 = exec("(bgp (:s :p :o))", graph) ;
++ ResultSet rs2 = results("unit") ;
++ equals(rs1, rs2) ;
++ }
++
++ @Test public void solve_02()
++ {
++ ResultSet rs1 = exec("(bgp (:s :p :o2))", graph) ;
++ ResultSet rs2 = results("empty") ;
++ equals(rs1, rs2) ;
++ }
++
++ @Test public void solve_03()
++ {
++ // Above everything.
++ ResultSet rs1 = exec("(bgp (:zzzz :p 999999))", graph) ;
++ ResultSet rs2 = results("empty") ;
++ equals(rs1, rs2) ;
++ }
++
++ @Test public void solve_04()
++ {
++ // Below everything.
++ ResultSet rs1 = exec("(bgp (:a :p :a))", graph) ;
++ ResultSet rs2 = results("empty") ;
++ equals(rs1, rs2) ;
++ }
++
++ @Test public void solve_05()
++ {
++ ResultSet rs1 = exec("(project (?s ?y) (bgp (?s :p ?z) (?z :q ?y)))", graph) ;
++ ResultSet rs2 = results("(row (?s :s) (?y :y))") ;
++ equals(rs1, rs2) ;
++ }
++
++ @Test public void solve_06()
++ {
++ ResultSet rs1 = exec("(bgp (:s ?p ?o))", graph) ;
++ ResultSet rs2 = results("(row (?p :p) (?o :o))",
++ "(row (?p :p) (?o 10))",
++ "(row (?p :p) (?o :x))"
++ ) ;
++ equals(rs1, rs2) ;
++ }
++
++ // ------
++
++ private static void equals(ResultSet rs1, ResultSet rs2)
++ { same(rs1, rs2, true) ; }
++
++ private static void same(ResultSet rs1, ResultSet rs2, boolean result)
++ {
++ ResultSetRewindable rsw1 = ResultSetFactory.makeRewindable(rs1) ;
++ ResultSetRewindable rsw2 = ResultSetFactory.makeRewindable(rs2) ;
++ boolean b = ResultSetCompare.equalsByValue(rsw1, rsw2) ;
++ if ( b != result)
++ {
++ System.out.println("Different: ") ;
++ rsw1.reset() ;
++ rsw2.reset() ;
++ ResultSetFormatter.out(rsw1) ;
++ ResultSetFormatter.out(rsw2) ;
++ System.out.println() ;
++ }
++
++ assertTrue(b == result) ;
++ }
++
++ private static ResultSet results(String... rows)
++ {
++ String str = "(table "+String.join("", rows)+")" ;
++ return SSE.parseTable(str).toResultSet() ;
++ }
++
++
++ private static ResultSet exec(String pattern, Graph graph)
++ {
++ Op op = SSE.parseOp(pattern, pmap) ;
++ List<Var> vars = new ArrayList<>() ;
++ vars.addAll(OpVars.visibleVars(op)) ;
++ QueryIterator qIter = Algebra.exec(op, graph) ;
++ return ResultSetFactory.create(qIter, Var.varNames(vars)) ;
++ }
++
++ private static List<Binding> toList(QueryIterator qIter)
++ {
++ List<Binding> x = new ArrayList<>() ;
++ for ( ; qIter.hasNext() ; )
++ x.add(qIter.nextBinding()) ;
++ return x ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TestStats.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TestStats.java
index 0000000,0000000..a9dfe92
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/solver/TestStats.java
@@@ -1,0 -1,0 +1,117 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.solver;
++
++import static org.junit.Assert.assertEquals ;
++
++import java.util.Iterator ;
++
++import org.apache.jena.atlas.lib.tuple.Tuple ;
++import org.apache.jena.graph.NodeFactory ;
++import org.apache.jena.sparql.core.Quad ;
++import org.apache.jena.sparql.sse.SSE ;
++import org.junit.Test ;
++import org.seaborne.dboe.jenax.Txn ;
++import org.seaborne.tdb2.junit.TL ;
++import org.seaborne.tdb2.solver.stats.StatsCollectorNodeId ;
++import org.seaborne.tdb2.solver.stats.StatsResults ;
++import org.seaborne.tdb2.store.DatasetGraphTDB ;
++import org.seaborne.tdb2.store.NodeId ;
++import org.seaborne.tdb2.store.nodetable.NodeTable ;
++import org.seaborne.tdb2.store.nodetupletable.NodeTupleTable ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++public class TestStats
++{
++ static DatasetGraphTDB dsg = TDBInternal.getDatasetGraphTDB(TL.createTestDatasetGraphMem()) ;
++ static NodeTupleTable quads = dsg.getQuadTable().getNodeTupleTable() ;
++ static NodeTupleTable triples = dsg.getTripleTable().getNodeTupleTable() ;
++ static NodeTable nt = quads.getNodeTable() ;
++
++ static Quad q1 = SSE.parseQuad("(<g1> <s> <p> 1)") ;
++ static Quad q2 = SSE.parseQuad("(<g2> <s> <p> 2)") ;
++ static Quad q3 = SSE.parseQuad("(<g2> <s> <p> 9)") ;
++ static Quad q4 = SSE.parseQuad("(_ <s> <p> 1)") ;
++ static {
++ Txn.executeWrite(dsg, ()->{
++ dsg.add(q1) ;
++ dsg.add(q2) ;
++ dsg.add(q3) ;
++ dsg.add(q4) ;
++ });
++ }
++
++ private StatsResults statsForGraph(NodeId gid) {
++ // StatsCollectorNodeId writes nodes for rdf:type (this is not good).
++ return Txn.calculateWrite(dsg, ()-> {
++ Iterator<Tuple<NodeId>> iter = quads.find(gid, null, null, null) ;
++
++ StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ;
++ for ( ; iter.hasNext() ; ) {
++ Tuple<NodeId> t = iter.next() ;
++ stats.record(t.get(0), t.get(1), t.get(2), t.get(3)) ;
++ }
++
++ return stats.results() ;
++ }) ;
++ }
++
++ private StatsResults statsForDftGraph() {
++ // StatsCollectorNodeId writes nodes for rdf:type (this is not good).
++ return Txn.calculateWrite(dsg, ()-> {
++ Iterator<Tuple<NodeId>> iter = triples.findAll() ;
++
++ StatsCollectorNodeId stats = new StatsCollectorNodeId(nt) ;
++ for ( ; iter.hasNext() ; ) {
++ Tuple<NodeId> t = iter.next() ;
++ stats.record(null, t.get(0), t.get(1), t.get(2)) ;
++ }
++
++ return stats.results() ;
++ }) ;
++ }
++
++ @Test public void stats_01() {
++ StatsResults r = statsForDftGraph() ;
++ assertEquals(1, r.getCount()) ;
++ assertEquals(1, r.getPredicates().keySet().size()) ;
++ }
++
++ @Test public void stats_02() {
++ NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g1")) ;
++ StatsResults r = statsForGraph(gid) ;
++ assertEquals(1, r.getCount()) ;
++ assertEquals(1, r.getPredicates().keySet().size()) ;
++ }
++
++ @Test public void stats_03() {
++ NodeId gid = nt.getNodeIdForNode(NodeFactory.createURI("g2")) ;
++ StatsResults r = statsForGraph(gid) ;
++ assertEquals(2, r.getCount()) ;
++ assertEquals(1, r.getPredicates().keySet().size()) ;
++ }
++
++ @Test public void stats_04() {
++ StatsResults r = statsForGraph(null) ;
++ assertEquals(3, r.getCount()) ;
++ assertEquals(1, r.getPredicates().keySet().size()) ;
++ }
++
++}
++
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/AbstractTestStoreConnectionBasics.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/AbstractTestStoreConnectionBasics.java
index 0000000,0000000..792fef4
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/AbstractTestStoreConnectionBasics.java
@@@ -1,0 -1,0 +1,185 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++
++import static org.junit.Assert.*;
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.core.Quad ;
++import org.apache.jena.sparql.sse.SSE ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.junit.Test ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.dboe.jenax.Txn ;
++import org.seaborne.tdb2.sys.StoreConnection ;
++import org.seaborne.tdb2.sys.TDBInternal ;
++
++/** StoreConnection and transactions - basic wiring.
++ * These tests are slow on rotational disk.
++ * Complet cleaning of file areas is done.
++ */
++public abstract class AbstractTestStoreConnectionBasics
++{
++ // Subclass to give direct and mapped versions.
++
++ // Per-test unique-ish.
++ static int count = 0 ;
++ long x = System.currentTimeMillis()+(count++) ;
++
++ Quad q = SSE.parseQuad("(<g> <s> <p> '000-"+x+"') ") ;
++ Quad q1 = SSE.parseQuad("(<g> <s> <p> '111-"+x+"')") ;
++ Quad q2 = SSE.parseQuad("(<g> <s> <p> '222-"+x+"')") ;
++ Quad q3 = SSE.parseQuad("(<g> <s> <p> '333-"+x+"')") ;
++ Quad q4 = SSE.parseQuad("(<g> <s> <p> '444-"+x+"')") ;
++
++ Location location = null ;
++
++ protected abstract Location getLocation() ;
++
++ @Before public void before()
++ {
++ TDBInternal.reset() ;
++ location = getLocation() ;
++ }
++
++ @After public void after() { TDBInternal.reset() ; }
++
++ @Test
++ public void store_01()
++ {
++ StoreConnection sConn = StoreConnection.connectCreate(location) ;
++ assertNotNull(sConn);
++ StoreConnection.release(location) ;
++ StoreConnection sConn2 = StoreConnection.connectExisting(location) ;
++ assertNull(sConn2);
++ StoreConnection sConn3 = StoreConnection.connectCreate(location) ;
++ assertNotNull(sConn3);
++ }
++
++ @Test
++ public void store_02()
++ {
++ StoreConnection sConn = StoreConnection.connectCreate(location) ;
++
++ { // Isolate to stop mix ups on variables.
++ DatasetGraphTDB dsg = sConn.getDatasetGraphTDB() ;
++ Txn.executeWrite(dsg, ()->{
++ dsg.add(q1) ;
++ }) ;
++
++ Txn.executeWrite(dsg, ()->{
++ assertTrue(dsg.contains(q1)) ;
++ }) ;
++
++ Txn.executeRead(dsg, ()->{
++ assertTrue(dsg.contains(q1)) ;
++ }) ;
++ }
++
++ {
++ StoreConnection sConn2 = StoreConnection.connectCreate(location) ;
++ DatasetGraphTDB dsg2 = sConn.getDatasetGraphTDB() ;
++ Txn.executeRead(dsg2, ()->{
++ assertTrue(dsg2.contains(q1)) ;
++ }) ;
++ }
++
++ StoreConnection.release(sConn.getLocation()) ;
++ sConn = null ;
++
++ {
++ if ( ! location.isMem() ) {
++ StoreConnection sConn2 = StoreConnection.connectCreate(location) ;
++ DatasetGraphTDB dsg3 = sConn2.getDatasetGraphTDB() ;
++ Txn.executeRead(dsg3, ()->{
++ assertTrue(dsg3.contains(q1)) ;
++ }) ;
++ }
++ }
++ }
++
++ @Test
++ public void store_03()
++ {
++ StoreConnection sConn = StoreConnection.connectCreate(location) ;
++
++ DatasetGraphTDB dsg = sConn.getDatasetGraphTDB() ;
++ Txn.executeWrite(dsg, ()->{
++ dsg.add(q1) ;
++ }) ;
++
++ Txn.executeWrite(dsg, ()->{
++ assertTrue(dsg.contains(q1)) ;
++ }) ;
++
++ try {
++ Txn.executeWrite(dsg, ()->{
++ dsg.add(q2) ;
++ throw new RuntimeException() ;
++ }) ;
++ fail("Should not get to here!") ;
++ } catch (RuntimeException ex) {}
++
++ Txn.executeRead(dsg, ()->{
++ assertTrue(dsg.contains(q1)) ;
++ assertFalse(dsg.contains(q2)) ;
++ }) ;
++ }
++
++ @Test
++ public void store_04()
++ {
++ StoreConnection sConn = StoreConnection.connectCreate(location) ;
++
++ DatasetGraphTDB dsg = sConn.getDatasetGraphTDB() ;
++ Txn.executeWrite(dsg, ()->{
++ dsg.add(q1) ;
++ }) ;
++
++ Txn.executeWrite(dsg, ()->{
++ assertTrue(dsg.contains(q1)) ;
++ }) ;
++
++ dsg.begin(ReadWrite.WRITE);
++ dsg.add(q2) ;
++ dsg.abort() ;
++ dsg.end() ;
++
++ Txn.executeRead(dsg, ()->{
++ assertTrue(dsg.contains(q1)) ;
++ assertFalse(dsg.contains(q2)) ;
++ }) ;
++ }
++
++ @Test
++ public void store_05()
++ {
++ StoreConnection sConn = StoreConnection.connectCreate(location) ;
++
++ DatasetGraphTDB dsg = sConn.getDatasetGraphTDB() ;
++ Txn.executeWrite(dsg, ()->{
++ dsg.add(q3) ;
++ }) ;
++
++ Txn.executeWrite(dsg, ()->{
++ assertTrue(dsg.contains(q3)) ;
++ }) ;
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/AbstractTestTransPromoteTDB2.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/AbstractTestTransPromoteTDB2.java
index 0000000,0000000..7441a56
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/AbstractTestTransPromoteTDB2.java
@@@ -1,0 -1,0 +1,71 @@@
++/*
++ * 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.
++ */
++
++// **** COPIED from Jena 3.4.0 development.
++// After Mantis moves to 3.4.0 or later, this can be removed.
++
++//package org.apache.jena.sparql.transaction ;
++package org.seaborne.tdb2.store;
++
++import static org.junit.Assert.fail ;
++
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.JenaTransactionException;
++import org.apache.jena.sparql.core.DatasetGraph ;
++import org.apache.jena.sparql.transaction.AbstractTestTransPromote;
++import org.apache.log4j.Logger ;
++import org.junit.Ignore;
++import org.junit.Test ;
++
++/** Tests for transactions that start read and then promote to write */
++public abstract class AbstractTestTransPromoteTDB2 extends AbstractTestTransPromote {
++
++ protected AbstractTestTransPromoteTDB2(Logger[] loggers) {
++ super(loggers);
++ }
++
++ // Copy in Jena 3.4.0 development
++ // write-end becomes an exception.
++
++ @Override
++ @Ignore
++ @Test public void promote_snapshot_05() { }
++ @Test public void promote_snapshot_05_x() { run_05_X(false) ; }
++
++ @Override
++ @Ignore
++ @Test public void promote_readCommitted_05() { }
++
++ @Test public void promote_readCommitted_05_x() { run_05_X(true) ; }
++
++ private void run_05_X(boolean readCommitted) {
++ //Assume.assumeTrue( ! readCommitted || supportsReadCommitted());
++
++ setReadCommitted(readCommitted);
++ DatasetGraph dsg = create() ;
++ dsg.begin(ReadWrite.READ) ;
++ dsg.add(q1) ;
++
++ try {
++ dsg.end() ;
++ fail("begin(W);end() did not throw an exception");
++ } catch ( JenaTransactionException ex) {}
++
++ assertCount(0, dsg) ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TS_Store.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TS_Store.java
index 0000000,0000000..580b301
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TS_Store.java
@@@ -1,0 -1,0 +1,71 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++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.store.value.TestDoubleNode62;
++import org.seaborne.tdb2.store.value.TestNodeIdInline;
++import org.seaborne.tdb2.sys.SystemTDB ;
++import org.seaborne.tdb2.sys.TestOps ;
++
++@RunWith(Suite.class)
++@Suite.SuiteClasses( {
++ TestNodeId.class
++ , TestNodeIdInline.class
++ , TestDoubleNode62.class
++ , TestTripleTable.class
++ , TestGraphTDB.class
++ , TestGraphNamedTDB.class
++ , TestDatasetTDB.class
++ , TestDatasetTDBPersist.class
++ //, TestBulkLoader.class
++ // The script suite
++ , TestSuiteGraphTDB.class
++
++ , Test_SPARQL_TDB.class
++ , TestDynamicDatasetTDB.class
++ , TestStoreConnectionMem.class
++ , TestStoreConnectionDirect.class
++ , TestStoreConnectionMapped.class
++ , TestStoreConnectionLock.class
++ , TestTransactions.class
++ , TestTransactionLifecycleTDB.class
++ , TestTransPromoteTDB.class
++ , TestQuadFilter.class
++} )
++public class TS_Store
++{
++ static FileMode mode ;
++
++ @BeforeClass
++ public static void beforeClass()
++ {
++ mode = SystemTDB.fileMode() ;
++ }
++
++ @AfterClass
++ public static void afterClass()
++ {
++ if ( ! SystemTDB.fileMode().equals(mode) )
++ TestOps.setFileMode(mode) ;
++ }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDatasetTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDatasetTDB.java
index 0000000,0000000..1ff5387
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDatasetTDB.java
@@@ -1,0 -1,0 +1,323 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import static org.junit.Assert.*;
++import org.apache.jena.query.* ;
++import org.apache.jena.rdf.model.Model ;
++import org.apache.jena.rdf.model.ModelFactory ;
++import org.apache.jena.rdf.model.Property ;
++import org.apache.jena.rdf.model.Resource ;
++import org.apache.jena.riot.Lang ;
++import org.apache.jena.riot.RDFDataMgr ;
++import org.apache.jena.sparql.core.Quad ;
++import org.apache.jena.sparql.sse.SSE ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.junit.Test ;
++import org.seaborne.tdb2.TDB2 ;
++import org.seaborne.tdb2.junit.TL ;
++
++/** Tests of datasets, prefixes, special URIs etc (see also {@link org.apache.jena.sparql.graph.GraphsTests} */
++public class TestDatasetTDB
++{
++ private Dataset dataset ;
++
++ @Before public void before() {
++ dataset = TL.createTestDatasetMem() ;
++ dataset.begin(ReadWrite.WRITE);
++ }
++
++ @After public void after() {
++ dataset.abort();
++ dataset.end();
++ TL.expel(dataset);
++
++ }
++
++ private Dataset dataset() {
++ return dataset ;
++ }
++
++ private static void load(Model model, String file)
++ {
++ RDFDataMgr.read(model, file) ;
++ }
++
++ private static String base1 = "http://example/" ;
++ private static String baseNS = "http://example/ns#" ;
++
++ private static void load1(Model model)
++ {
++ model.setNsPrefix("", base1) ;
++ Resource r1 = model.createResource(base1+"r1") ;
++ Property p1 = model.createProperty(baseNS+"p1") ;
++ model.add(r1, p1, "x1") ;
++ model.add(r1, p1, "x2") ;
++ }
++
++ private static void load2(Model model)
++ {
++ Resource r2 = model.createResource(base1+"r2") ;
++ Property p1 = model.createProperty(baseNS+"p1") ;
++ model.add(r2, p1, "x1") ;
++ model.add(r2, p1, "x2") ;
++ }
++
++ private static void load3(Model model)
++ {
++ Resource r3 = model.createResource(base1+"r3") ;
++ Property p1 = model.createProperty(baseNS+"p2") ;
++ model.add(r3, p1, "x1") ;
++ model.add(r3, p1, "x2") ;
++ }
++
++ @Test public void prefix1()
++ {
++ Dataset ds = dataset() ;
++ Model m = ds.getDefaultModel() ;
++ load1(m) ;
++ String x = m.expandPrefix(":x") ;
++ assertEquals(x, base1+"x") ;
++ }
++
++ @Test public void prefix2()
++ {
++ Dataset ds = dataset() ;
++ Model m = ds.getDefaultModel() ;
++ load1(m) ;
++ Model m2 = ds.getNamedModel("http://example/graph/") ;
++ String x = m2.expandPrefix(":x") ;
++ assertEquals(x, ":x") ;
++ }
++
++ @Test public void query1()
++ {
++ Dataset ds = dataset() ;
++ Model m = ds.getDefaultModel() ;
++ load1(m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE {?s ?p ?o}" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
++ Model m2 = qExec.execConstruct() ;
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ @Test public void query2()
++ {
++ Dataset ds = dataset() ;
++ Model m = ds.getDefaultModel() ;
++ load1(m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { GRAPH <http://example/graph/> {?s ?p ?o}}" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
++ Model m2 = qExec.execConstruct() ;
++ assertTrue(m2.isEmpty()) ;
++ }
++
++ static String defaultGraph = Quad.defaultGraphIRI.getURI() ;
++ static String unionGraph = Quad.unionGraph.getURI() ;
++
++ @Test public void special1()
++ {
++ Dataset ds = dataset() ;
++ Model m = ds.getDefaultModel() ;
++ load1(m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { GRAPH <"+defaultGraph+"> {?s ?p ?o}}" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
++ Model m2 = qExec.execConstruct() ;
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ @Test public void special2()
++ {
++ Dataset ds = dataset() ;
++
++ load1(ds.getDefaultModel()) ;
++ load2(ds.getNamedModel("http://example/graph1")) ;
++ load3(ds.getNamedModel("http://example/graph2")) ;
++
++ Model m = ModelFactory.createDefaultModel() ;
++ load2(m) ;
++ load3(m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { GRAPH <"+unionGraph+"> {?s ?p ?o}}" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
++ Model m2 = qExec.execConstruct() ;
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ @Test public void special3()
++ {
++ Dataset ds = dataset() ;
++
++ load1(ds.getDefaultModel()) ;
++ load2(ds.getNamedModel("http://example/graph1")) ;
++ load3(ds.getNamedModel("http://example/graph2")) ;
++
++ Model m = ModelFactory.createDefaultModel() ;
++ load2(m) ;
++ load3(m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { ?s ?p ?o }" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds) ;
++ qExec.getContext().set(TDB2.symUnionDefaultGraph, true) ;
++ Model m2 = qExec.execConstruct() ;
++ if ( ! m.isIsomorphicWith(m2) )
++ {
++ System.out.println("---- ----") ;
++ SSE.write(ds.asDatasetGraph()) ;
++ System.out.println("-- Expected") ;
++ m.write(System.out, "TTL") ;
++ System.out.println("-- Actual") ;
++ m2.write(System.out, "TTL") ;
++ System.out.println("---- ----") ;
++
++ }
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ @Test public void special4()
++ {
++ Dataset ds = dataset() ;
++
++ load1(ds.getDefaultModel()) ;
++ load2(ds.getNamedModel("http://example/graph1")) ;
++ load3(ds.getNamedModel("http://example/graph2")) ;
++
++ Model m = ModelFactory.createDefaultModel() ;
++ load2(m) ;
++ load3(m) ;
++
++ String qs = "PREFIX : <"+baseNS+"> SELECT (COUNT(?x) as ?c) WHERE { ?x (:p1|:p2) 'x1' }" ;
++ Query q = QueryFactory.create(qs) ;
++
++ long c_m ;
++ // Model
++ try (QueryExecution qExec = QueryExecutionFactory.create(q, m)) {
++ c_m = qExec.execSelect().next().getLiteral("c").getLong() ;
++ }
++
++ // dataset
++ long c_ds ;
++ try (QueryExecution qExec = QueryExecutionFactory.create(q, ds)) {
++ qExec.getContext().set(TDB2.symUnionDefaultGraph, true) ;
++ c_ds = qExec.execSelect().next().getLiteral("c").getLong() ;
++ }
++
++// String qs2 = "PREFIX : <"+baseNS+"> SELECT * WHERE { ?x (:p1|:p2) 'x1' }" ;
++// Query q2 = QueryFactory.create(qs2) ;
++// qExec = QueryExecutionFactory.create(q2, ds) ;
++// qExec.getContext().set(TDB.symUnionDefaultGraph, true) ;
++// ResultSetFormatter.out(qExec.execSelect()) ;
++//
++// qExec = QueryExecutionFactory.create(q2, m) ;
++// ResultSetFormatter.out(qExec.execSelect()) ;
++ // --------
++
++ assertEquals(c_m, c_ds) ;
++ }
++
++ @Test public void special5()
++ {
++ Dataset ds = dataset() ;
++
++ //load1(ds.getDefaultModel()) ;
++ load1(ds.getNamedModel("http://example/graph1")) ; // Same triples, different graph
++ load1(ds.getNamedModel("http://example/graph2")) ;
++
++ Model m = ds.getNamedModel(unionGraph) ;
++ assertEquals(2, m.size()) ;
++ }
++
++ // Put a model into a general dataset and use it.
++ @Test public void generalDataset1()
++ {
++ Dataset ds = dataset() ;
++ load1(ds.getDefaultModel()) ;
++ load2(ds.getNamedModel("http://example/graph1")) ;
++ load3(ds.getNamedModel("http://example/graph2")) ;
++ Model m = ds.getNamedModel("http://example/graph2") ;
++
++ // Use graph2 as default model.
++ Dataset ds2 = DatasetFactory.create() ;
++ ds2.setDefaultModel(ds.getNamedModel("http://example/graph2")) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { ?s ?p ?o}" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
++ Model m2 = qExec.execConstruct() ;
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ @Test public void generalDataset2()
++ {
++ Dataset ds = dataset() ;
++ load1(ds.getDefaultModel()) ;
++ load2(ds.getNamedModel("http://example/graph1")) ;
++ load3(ds.getNamedModel("http://example/graph2")) ;
++ Model m = ds.getNamedModel("http://example/graph2") ;
++
++ // Use graph1 as a differently named model.
++ Dataset ds2 = DatasetFactory.create() ;
++ ds2.addNamedModel("http://example/graphOther", m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { {?s ?p ?o} UNION { GRAPH <http://example/graphOther> {?s ?p ?o} } }" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
++ Model m2 = qExec.execConstruct() ;
++ if ( ! m.isIsomorphicWith(m2) )
++ {
++ System.out.println(m.getGraph().getClass().getSimpleName()+"/"+m.size()+" : "+m2.getGraph().getClass().getSimpleName()+"/"+m2.size()) ;
++ System.out.println("---- Different:" ) ;
++ RDFDataMgr.write(System.out, m, Lang.TTL) ;
++ System.out.println("---- ----" ) ;
++ RDFDataMgr.write(System.out, m2, Lang.TTL) ;
++ System.out.println("---- ----") ;
++ }
++
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ @Test public void generalDataset3()
++ {
++ Dataset ds = dataset() ;
++ load1(ds.getDefaultModel()) ;
++ load2(ds.getNamedModel("http://example/graph1")) ;
++ load3(ds.getNamedModel("http://example/graph2")) ;
++ Model m = ds.getDefaultModel() ;
++
++ // Use the default model in one dataset as a named model in another.
++ Dataset ds2 = DatasetFactory.create() ;
++ ds2.addNamedModel("http://example/graphOther", m) ;
++
++ String qs = "CONSTRUCT {?s ?p ?o } WHERE { {?s ?p ?o} UNION { GRAPH <http://example/graphOther> {?s ?p ?o} } }" ;
++ Query q = QueryFactory.create(qs) ;
++ QueryExecution qExec = QueryExecutionFactory.create(q, ds2) ;
++ Model m2 = qExec.execConstruct() ;
++ assertTrue(m.isIsomorphicWith(m2)) ;
++ }
++
++ // removeAll
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDatasetTDBPersist.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDatasetTDBPersist.java
index 0000000,0000000..81a5dd5
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDatasetTDBPersist.java
@@@ -1,0 -1,0 +1,111 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import static org.junit.Assert.assertFalse ;
++import static org.junit.Assert.assertTrue ;
++
++import org.apache.jena.graph.Graph ;
++import org.apache.jena.graph.Node ;
++import org.apache.jena.graph.Triple ;
++import org.apache.jena.sparql.util.NodeFactoryExtra ;
++import org.junit.Test ;
++import org.seaborne.tdb2.junit.TL ;
++
++/** Testing persistence */
++public class TestDatasetTDBPersist
++{
++ static Node n0 = NodeFactoryExtra.parseNode("<http://example/n0>") ;
++ static Node n1 = NodeFactoryExtra.parseNode("<http://example/n1>") ;
++ static Node n2 = NodeFactoryExtra.parseNode("<http://example/n2>") ;
++
++ @Test
++ public void dataset1() {
++ TL.exec((ds) -> {
++ assertTrue(ds.getDefaultModel().getGraph() instanceof GraphViewSwitchable) ;
++ assertTrue(ds.getNamedModel("http://example/").getGraph() instanceof GraphViewSwitchable) ;
++ }) ;
++ }
++
++ @Test
++ public void dataset2() {
++ TL.exec((ds) -> {
++ Graph g1 = ds.getDefaultModel().getGraph() ;
++ Graph g2 = ds.getNamedModel("http://example/").getGraph() ;
++
++ g1.add(new Triple(n0, n1, n2)) ;
++ assertTrue(g1.contains(n0, n1, n2)) ;
++ assertFalse(g2.contains(n0, n1, n2)) ;
++ }) ;
++ }
++
++// @Test
++// public void dataset3() {
++// TL.exec((ds) -> {
++// Graph g1 = ds.getDefaultModel().getGraph() ;
++// // Sometimes, under windows, deleting the files by
++// // clearDirectory does not work.
++// // Needed for safe tests on windows.
++// g1.clear() ;
++//
++// Graph g2 = ds.getNamedModel("http://example/").getGraph() ;
++// g2.add(new Triple(n0, n1, n2)) ;
++// assertTrue(g2.contains(n0, n1, n2)) ;
++// assertFalse(g1.contains(n0, n1, n2)) ;
++// }) ;
++// }
++//
++// @Test
++// public void dataset4() {
++// String graphName = "http://example/" ;
++// Triple triple = SSE.parseTriple("(<x> <y> <z>)") ;
++// Node gn = org.apache.jena.graph.NodeFactory.createURI(graphName) ;
++//
++// TL.exec((ds) -> {
++// // ?? See TupleLib.
++// ds.asDatasetGraph().deleteAny(gn, null, null, null) ;
++//
++// Graph g2 = ds.asDatasetGraph().getGraph(gn) ;
++//
++// // Graphs only exists if they have a triple in them
++// assertFalse(ds.containsNamedModel(graphName)) ;
++//
++// List<String> names = Iter.toList(ds.listNames()) ;
++// assertEquals(0, names.size()) ;
++// assertEquals(0, ds.asDatasetGraph().size()) ;
++// }) ;
++// }
++//
++// @Test
++// public void dataset5() {
++// String graphName = "http://example/" ;
++// Triple triple = SSE.parseTriple("(<x> <y> <z>)") ;
++// TL.exec((ds) -> {
++// Graph g2 = ds.asDatasetGraph().getGraph(org.apache.jena.graph.NodeFactory.createURI(graphName)) ;
++// // Graphs only exists if they have a triple in them
++// g2.add(triple) ;
++//
++// assertTrue(ds.containsNamedModel(graphName)) ;
++// List<String> x = Iter.toList(ds.listNames()) ;
++// List<String> y = Arrays.asList(graphName) ;
++// assertEquals(x, y) ;
++//
++// assertEquals(1, ds.asDatasetGraph().size()) ;
++// }) ;
++// }
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDynamicDatasetTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDynamicDatasetTDB.java
index 0000000,0000000..d0376e9
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestDynamicDatasetTDB.java
@@@ -1,0 -1,0 +1,44 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.core.AbstractTestDynamicDataset ;
++import org.seaborne.tdb2.TDB2 ;
++import org.seaborne.tdb2.junit.TL ;
++
++public class TestDynamicDatasetTDB extends AbstractTestDynamicDataset
++{
++ @Override
++ protected Dataset createDataset()
++ {
++ Dataset ds = TL.createTestDatasetMem() ;
++ ds.begin(ReadWrite.WRITE);
++ return ds;
++ }
++
++ @Override
++ protected void releaseDataset(Dataset ds) { ds.abort(); TL.expel(ds); }
++
++ protected void startDynamicAndUnionTest() { TDB2.getContext().setTrue(TDB2.symUnionDefaultGraph) ; }
++
++ protected void finishDynamicAndUnionTest() { TDB2.getContext().unset(TDB2.symUnionDefaultGraph) ; }
++
++}
++
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestGraphNamedTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestGraphNamedTDB.java
index 0000000,0000000..d844c5a
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestGraphNamedTDB.java
@@@ -1,0 -1,0 +1,60 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import org.apache.jena.graph.Graph ;
++import org.apache.jena.graph.Node ;
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.graph.AbstractTestGraph2 ;
++import org.apache.jena.sparql.util.NodeFactoryExtra ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.seaborne.tdb2.junit.TL ;
++
++/** Programmatic tests on persistent graph */
++public class TestGraphNamedTDB extends AbstractTestGraph2
++{
++ static Node graphNode = NodeFactoryExtra.parseNode("<http://example/namedGraph>") ;
++ private Dataset dataset ;
++ private Graph graph ;
++
++ @Before
++ public void before() {
++ dataset = TL.createTestDatasetMem() ;
++ dataset.begin(ReadWrite.WRITE);
++ graph = dataset.asDatasetGraph().getGraph(graphNode) ;
++ }
++
++ @After
++ public void after() {
++ dataset.abort();
++ dataset.end();
++ TL.expel(dataset) ;
++ }
++
++ @Override
++ protected Graph emptyGraph() {
++ graph.clear() ;
++ return graph ;
++ }
++
++ @Override
++ protected void returnGraph(Graph g)
++ {}
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestGraphTDB.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestGraphTDB.java
index 0000000,0000000..7f941eb
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestGraphTDB.java
@@@ -1,0 -1,0 +1,57 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import org.apache.jena.graph.Graph ;
++import org.apache.jena.query.Dataset ;
++import org.apache.jena.query.ReadWrite ;
++import org.apache.jena.sparql.graph.AbstractTestGraph2 ;
++import org.junit.After ;
++import org.junit.Before ;
++import org.seaborne.tdb2.junit.TL ;
++
++/** Programmatic tests on graphs */
++public class TestGraphTDB extends AbstractTestGraph2
++{
++ private Dataset dataset ;
++ private Graph graph ;
++
++ @Before
++ public void before() {
++ dataset = TL.createTestDatasetMem() ;
++ dataset.begin(ReadWrite.WRITE);
++ graph = dataset.getDefaultModel().getGraph() ;
++ }
++
++ @After
++ public void after() {
++ dataset.abort();
++ dataset.end();
++ TL.expel(dataset) ;
++ }
++
++ @Override
++ protected Graph emptyGraph() {
++ graph.clear() ;
++ return graph ;
++ }
++
++ @Override
++ protected void returnGraph(Graph g)
++ {}
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestNodeId.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestNodeId.java
index 0000000,0000000..56cf166
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestNodeId.java
@@@ -1,0 -1,0 +1,127 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import static org.junit.Assert.assertEquals;
++import static org.junit.Assert.assertFalse;
++
++import java.nio.ByteBuffer;
++
++import org.apache.jena.atlas.lib.BitsLong;
++import org.apache.jena.graph.Node;
++import org.apache.jena.sparql.util.NodeFactoryExtra;
++import org.junit.Test ;
++
++public class TestNodeId
++{
++ // Pointers.
++ @Test public void nodeId_ptr_01() {
++ NodeId nodeId = NodeIdFactory.createPtrLong(17, 37);
++ assertEquals(NodeIdType.PTR, nodeId.type());
++// assertEquals(37L, nodeId.getPtrLo());
++// assertEquals(17, nodeId.getPtrHi());
++ assertEquals(37L, nodeId.getValue2());
++ assertEquals(17, nodeId.getValue1());
++ }
++
++ @Test public void nodeId_ptr_02() {
++ NodeId nodeId = NodeIdFactory.createPtr(37);
++ assertEquals(NodeIdType.PTR, nodeId.type());
++// assertEquals(37L, nodeId.getPtrLo());
++// assertEquals(0, nodeId.getPtrHi());
++ assertEquals(37L, nodeId.getPtrLocation());
++ }
++
++ @Test public void nodeId_ptr_03() {
++ NodeId nodeId = NodeIdFactory.createPtr(39);
++ // 64 bit
++ long x = nodeId.getValue2();
++ long t = BitsLong.unpack(x, 56, 64);
++ assertEquals(0, t);
++ assertEquals(NodeIdType.PTR.type(), t);
++ }
++
++ // Specials.
++ @Test public void nodeId_special_01() {
++ assertFalse(NodeId.isConcrete(NodeId.NodeDoesNotExist));
++ assertEquals(NodeIdType.SPECIAL, NodeId.NodeDoesNotExist.type());
++ }
++
++ @Test public void nodeId_special_02() {
++ assertFalse(NodeId.isConcrete(NodeId.NodeIdAny));
++ assertEquals(NodeIdType.SPECIAL, NodeId.NodeIdAny.type());
++ }
++
++ // Storage
++
++ @Test public void nodeId_codec_01() { testCodecArray(NodeIdFactory.createPtr(37)); }
++
++ @Test public void nodeId_codec_02() { testCodecArray(NodeId.createRaw(NodeIdType.XSD_INTEGER, 1)); }
++
++ // 56 bit -1.
++ @Test public void nodeId_codec_03() { testCodecArray(NodeId.createRaw(NodeIdType.XSD_INTEGER, BitsLong.clear(-1L, 56,64))); }
++
++ @Test public void nodeId_codec_04() { testCodecArray("12.34"); }
++
++ @Test public void nodeId_codec_05() { testCodecArray("'2.2'^^xsd:float"); }
++
++ private static void testCodecArray(String str) {
++ Node n = NodeFactoryExtra.parseNode(str);
++ NodeId nid = NodeIdInline.inline(n);
++ testCodecArray(nid);
++ }
++
++ private static void testCodecArray(NodeId nid) {
++ testCodecArray(nid, nid);
++ }
++
++ private static void testCodecArray(NodeId testNid,NodeId expected) {
++ byte[] b = new byte[8];
++ NodeIdFactory.set(testNid, b);
++ NodeId nid1 = NodeIdFactory.get(b);
++ assertEquals(expected, nid1);
++ }
++
++ @Test public void nodeId_codec_11() { testCodecBuffer(NodeIdFactory.createPtr(37)); }
++
++ @Test public void nodeId_codec_12() { testCodecBuffer(NodeId.createRaw(NodeIdType.XSD_INTEGER, 1)); }
++
++ @Test public void nodeId_codec_13() { testCodecBuffer(NodeId.createRaw(NodeIdType.XSD_INTEGER, BitsLong.clear(-1L, 56,64))); }
++
++ @Test public void nodeId_codec_14() { testCodecBuffer("12.34"); }
++
++ @Test public void nodeId_codec_15() { testCodecBuffer("'2.2'^^xsd:float"); }
++
++ private static void testCodecBuffer(String str) {
++ Node n = NodeFactoryExtra.parseNode(str);
++ NodeId nid = NodeIdInline.inline(n);
++ testCodecArray(nid);
++ }
++
++ private static void testCodecBuffer(NodeId nid) {
++ testCodecArray(nid, nid);
++ }
++
++ private static void testCodecBuffer(NodeId testNid,NodeId expected) {
++ ByteBuffer b = ByteBuffer.allocate(8);
++ NodeIdFactory.set(testNid, b);
++ NodeId nid1 = NodeIdFactory.get(b);
++ assertEquals(expected, nid1);
++ }
++
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestQuadFilter.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestQuadFilter.java
index 0000000,0000000..78ee4c4
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestQuadFilter.java
@@@ -1,0 -1,0 +1,110 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store;
++
++import java.util.function.Predicate ;
++
++import static org.junit.Assert.*;
++import org.apache.jena.atlas.lib.tuple.Tuple ;
++import org.apache.jena.graph.NodeFactory ;
++import org.apache.jena.query.* ;
++import org.apache.jena.sparql.core.Quad ;
++import org.apache.jena.sparql.sse.SSE ;
++import org.apache.jena.system.Txn;
++import org.junit.AfterClass ;
++import org.junit.BeforeClass ;
++import org.junit.Ignore;
++import org.junit.Test ;
++import org.seaborne.tdb2.TDB2 ;
++import org.seaborne.tdb2.TDB2Factory ;
++import org.seaborne.tdb2.store.nodetable.NodeTable ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++
++@Ignore("Quad filter tests not ready (transactions)")
++public class TestQuadFilter
++{
++ private static String graphToHide = "http://example/g2" ;
++ private static Dataset ds = setup() ;
++
++
++ @BeforeClass public static void beforeClass()
++ {
++
++ }
++
++ @AfterClass public static void afterClass() {}
++
++ /** Example setup - in-memory dataset with two graphs, one triple in each */
++ private static Dataset setup()
++ {
++ Dataset ds = TDB2Factory.createDataset() ;
++ DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ;
++ Txn.executeWrite(dsg, ()->{
++ Quad q1 = SSE.parseQuad("(<http://example/g1> <http://example/s> <http://example/p> <http://example/o1>)") ;
++ Quad q2 = SSE.parseQuad("(<http://example/g2> <http://example/s> <http://example/p> <http://example/o2>)") ;
++ dsg.add(q1) ;
++ dsg.add(q2) ;
++ });
++ return ds ;
++ }
++
++ /** Create a filter to exclude the graph http://example/g2 */
++ private static Predicate<Tuple<NodeId>> createFilter(Dataset ds)
++ {
++ DatasetGraphTDB dsg = (DatasetGraphTDB)(ds.asDatasetGraph()) ;
++ final NodeTable nodeTable = dsg.getQuadTable().getNodeTupleTable().getNodeTable() ;
++ final NodeId target = nodeTable.getNodeIdForNode(NodeFactory.createURI(graphToHide)) ;
++ return item -> !( item.len() == 4 && item.get(0).equals(target) );
++ }
++
++ @Test public void quad_filter_1() { test("SELECT * { GRAPH ?g { ?s ?p ?o } }", 1, 2) ; }
++ @Test public void quad_filter_2() { test("SELECT * { ?s ?p ?o }", 1, 2) ; }
++ @Test public void quad_filter_3() { test("SELECT * { GRAPH ?g { } }", 1, 2) ; }
++
++ private void test(String qs, int withFilter, int withoutFilter)
++ {
++ Predicate<Tuple<NodeId>> filter = createFilter(ds) ;
++
++// private static void example(Dataset ds, Filter<Tuple<NodeId>> filter)
++// {
++// String[] x = {
++// "SELECT * { GRAPH ?g { ?s ?p ?o } }",
++// "SELECT * { ?s ?p ?o }",
++// // THis filter does not hide the graph itself, just the quads associated with the graph.
++// "SELECT * { GRAPH ?g {} }"
++// } ;
++ Query query = QueryFactory.create(qs) ;
++
++ try(QueryExecution qExec = QueryExecutionFactory.create(query, ds)) {
++ // Install filter for this query only.
++ qExec.getContext().set(SystemTDB.symTupleFilter, filter) ;
++ qExec.getContext().setTrue(TDB2.symUnionDefaultGraph) ;
++ long x1 = ResultSetFormatter.consume(qExec.execSelect()) ;
++ assertEquals(withFilter, x1) ;
++ }
++ // No filter.
++ try(QueryExecution qExec = QueryExecutionFactory.create(query, ds)) {
++ qExec.getContext().setTrue(TDB2.symUnionDefaultGraph) ;
++ long x2 = ResultSetFormatter.consume(qExec.execSelect()) ;
++ assertEquals(withoutFilter, x2) ;
++ }
++
++ }
++
++
++}
http://git-wip-us.apache.org/repos/asf/jena/blob/d9da3592/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestStoreConnectionDirect.java
----------------------------------------------------------------------
diff --cc jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestStoreConnectionDirect.java
index 0000000,0000000..ccf1b41
new file mode 100644
--- /dev/null
+++ b/jena-db/tdb2/src/test/java/org/seaborne/tdb2/store/TestStoreConnectionDirect.java
@@@ -1,0 -1,0 +1,47 @@@
++/*
++ * Licensed 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.
++ *
++ * See the NOTICE file distributed with this work for additional
++ * information regarding copyright ownership.
++ */
++
++package org.seaborne.tdb2.store ;
++
++import org.junit.AfterClass ;
++import org.junit.BeforeClass ;
++import org.seaborne.dboe.base.block.FileMode ;
++import org.seaborne.dboe.base.file.Location ;
++import org.seaborne.tdb2.ConfigTest ;
++import org.seaborne.tdb2.sys.SystemTDB ;
++import org.seaborne.tdb2.sys.TestOps ;
++
++/** Slow tests - complete cleaning of disk areas each time */
++public class TestStoreConnectionDirect extends AbstractTestStoreConnectionBasics {
++ static FileMode mode ;
++
++ @BeforeClass
++ public static void beforeClassFileMode() {
++ mode = SystemTDB.fileMode() ;
++ TestOps.setFileMode(FileMode.direct) ;
++ }
++
++ @AfterClass
++ public static void afterClassFileMode() {
++ TestOps.setFileMode(mode) ;
++ }
++
++ @Override
++ protected Location getLocation() {
++ return Location.create(ConfigTest.getCleanDir()) ;
++ }
++}