You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2017/10/03 19:33:53 UTC
[07/65] [abbrv] jena git commit: JENA-1397: Rename java packages
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TS_TDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TS_TDBAssembler.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TS_TDBAssembler.java
new file mode 100644
index 0000000..6daa978
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.assembler;
+
+import org.apache.jena.tdb2.junit.Base_TS;
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ TestTDBAssembler.class
+})
+
+public class TS_TDBAssembler extends Base_TS
+{
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TestTDBAssembler.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TestTDBAssembler.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TestTDBAssembler.java
new file mode 100644
index 0000000..7b8f385
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/assembler/TestTDBAssembler.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.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.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.assembler.VocabTDB2;
+import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
+import org.apache.jena.tdb2.store.GraphViewSwitchable;
+import org.apache.jena.tdb2.sys.TDBInternal;
+import org.junit.AfterClass ;
+import org.junit.Before ;
+import org.junit.BeforeClass ;
+import org.junit.Test ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/AbstractTestGraphsTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/AbstractTestGraphsTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/AbstractTestGraphsTDB.java
new file mode 100644
index 0000000..8488842
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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.apache.jena.tdb2.sys.SystemTDB;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.Ignore ;
+import org.junit.Test ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TS_Graph.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TS_Graph.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TS_Graph.java
new file mode 100644
index 0000000..df2ff35
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestDatasetGraphAccessorTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestDatasetGraphAccessorTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestDatasetGraphAccessorTDB.java
new file mode 100644
index 0000000..47c9804
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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.tdb2.junit.TL;
+import org.apache.jena.web.AbstractTestDatasetGraphAccessor ;
+import org.apache.jena.web.DatasetGraphAccessor ;
+import org.junit.After ;
+import org.junit.Before ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestDatasetGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestDatasetGraphTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestDatasetGraphTDB.java
new file mode 100644
index 0000000..a9fdca7
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.graph;
+
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.AbstractDatasetGraphTests ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.tdb2.junit.TL;
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+// 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphOverDatasetTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphOverDatasetTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphOverDatasetTDB.java
new file mode 100644
index 0000000..e7aba9f
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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.apache.jena.tdb2.junit.TL;
+import org.junit.After ;
+
+/** 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphsTDB1.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphsTDB1.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphsTDB1.java
new file mode 100644
index 0000000..461b59e
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.graph;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.tdb2.junit.TL;
+import org.junit.After ;
+import org.junit.Before ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphsTDB2.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphsTDB2.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestGraphsTDB2.java
new file mode 100644
index 0000000..7d6843c
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.graph;
+
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.junit.After ;
+import org.junit.Before ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestPrefixMappingTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestPrefixMappingTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/graph/TestPrefixMappingTDB.java
new file mode 100644
index 0000000..0d2a912
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.graph;
+
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.shared.PrefixMapping ;
+import org.apache.jena.sparql.core.DatasetPrefixStorage ;
+import org.apache.jena.sparql.graph.AbstractTestPrefixMapping2 ;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.junit.BuildTestLib;
+import org.apache.jena.tdb2.sys.TDBInternal;
+import org.junit.* ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/AbstractTestGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/AbstractTestGraphTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/AbstractTestGraphTDB.java
new file mode 100644
index 0000000..4eb6af7
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/Base_TS.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/Base_TS.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/Base_TS.java
new file mode 100644
index 0000000..04676c1
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.junit;
+
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderLib ;
+import org.apache.jena.sparql.engine.optimizer.reorder.ReorderTransformation ;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.apache.log4j.Level ;
+import org.apache.log4j.Logger ;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+
+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.apache.jena.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.apache.jena.tdb2.info").setLevel(level) ;
+ }
+ SystemTDB.defaultReorderTransform = rt ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/BuildTestLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/BuildTestLib.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/BuildTestLib.java
new file mode 100644
index 0000000..220ba21
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.junit;
+
+import org.apache.jena.dboe.base.file.*;
+import org.apache.jena.dboe.base.record.RecordFactory;
+import org.apache.jena.dboe.index.Index;
+import org.apache.jena.dboe.index.IndexParams;
+import org.apache.jena.dboe.index.RangeIndex;
+import org.apache.jena.dboe.trans.bplustree.BPlusTree;
+import org.apache.jena.dboe.trans.bplustree.BPlusTreeFactory;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.DatasetPrefixStorage ;
+import org.apache.jena.tdb2.setup.StoreParams;
+import org.apache.jena.tdb2.setup.TDBBuilder;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.store.nodetable.NodeTable;
+import org.apache.jena.tdb2.store.nodetable.NodeTableCache;
+import org.apache.jena.tdb2.store.nodetable.NodeTableInline;
+import org.apache.jena.tdb2.store.nodetable.NodeTableTRDF;
+import org.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/QueryTestTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/QueryTestTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/QueryTestTDB.java
new file mode 100644
index 0000000..acfb7f4
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.junit;
+
+import java.util.List ;
+
+import org.apache.jena.dboe.jenax.Txn;
+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.tdb2.TDB2Factory;
+import org.apache.jena.util.FileManager ;
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TDBTestException.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TDBTestException.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TDBTestException.java
new file mode 100644
index 0000000..9f574ff
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.junit;
+
+import org.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TL.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TL.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TL.java
new file mode 100644
index 0000000..af196b4
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.junit;
+
+import java.util.function.Consumer ;
+
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.sparql.core.DatasetGraph ;
+import org.apache.jena.system.Txn ;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.DatabaseMgr;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TestFactoryTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TestFactoryTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/junit/TestFactoryTDB.java
new file mode 100644
index 0000000..cce0db9
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/lib/TS_LibTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/lib/TS_LibTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/lib/TS_LibTDB.java
new file mode 100644
index 0000000..aba83a6
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.lib;
+
+import org.apache.jena.tdb2.lib.TestNodeLib;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses( {
+ TestNodeLib.class
+})
+
+
+public class TS_LibTDB
+{
+
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/lib/TestNodeLib.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/lib/TestNodeLib.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/lib/TestNodeLib.java
new file mode 100644
index 0000000..72dadc6
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.tdb2.lib;
+
+import static org.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TS_TDBSetup.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TS_TDBSetup.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TS_TDBSetup.java
new file mode 100644
index 0000000..6949710
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/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.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParams.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParams.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParams.java
new file mode 100644
index 0000000..538b072
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParams.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.setup;
+
+import org.apache.jena.atlas.json.JSON ;
+import org.apache.jena.atlas.json.JsonObject ;
+import org.apache.jena.dboe.base.block.FileMode;
+import org.apache.jena.tdb2.TDBException;
+import org.apache.jena.tdb2.setup.StoreParams;
+import org.apache.jena.tdb2.setup.StoreParamsBuilder;
+import org.apache.jena.tdb2.setup.StoreParamsCodec;
+
+import static org.junit.Assert.*;
+import org.junit.Test ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsChoose.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsChoose.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsChoose.java
new file mode 100644
index 0000000..f42a00a
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsChoose.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.setup;
+
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.FileOps ;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.sys.Names;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.setup.StoreParams;
+import org.apache.jena.tdb2.setup.StoreParamsCodec;
+import org.apache.jena.tdb2.setup.StoreParamsFactory;
+import org.junit.Test ;
+
+//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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsCreate.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsCreate.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsCreate.java
new file mode 100644
index 0000000..466a3c0
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/setup/TestStoreParamsCreate.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.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.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.sys.Names;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.setup.StoreParams;
+import org.apache.jena.tdb2.setup.StoreParamsCodec;
+import org.apache.jena.tdb2.sys.StoreConnection;
+import org.apache.jena.tdb2.sys.TDBInternal;
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+/**
+ * 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TS_SolverTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TS_SolverTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TS_SolverTDB.java
new file mode 100644
index 0000000..d4460d3
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TS_SolverTDB.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestSolverTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestSolverTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestSolverTDB.java
new file mode 100644
index 0000000..928542d
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestSolverTDB.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.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.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.junit.TL;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.Test ;
+
+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 ;
+ }
+}