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:52 UTC
[06/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/solver/TestStats.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestStats.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestStats.java
new file mode 100644
index 0000000..8be9d87
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/solver/TestStats.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.solver;
+
+import static org.junit.Assert.assertEquals ;
+
+import java.util.Iterator ;
+
+import org.apache.jena.atlas.lib.tuple.Tuple ;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.tdb2.junit.TL;
+import org.apache.jena.tdb2.solver.stats.StatsCollectorNodeId;
+import org.apache.jena.tdb2.solver.stats.StatsResults;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.store.NodeId;
+import org.apache.jena.tdb2.store.nodetable.NodeTable;
+import org.apache.jena.tdb2.store.nodetupletable.NodeTupleTable;
+import org.apache.jena.tdb2.sys.TDBInternal;
+import org.junit.Test ;
+
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestStoreConnectionBasics.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestStoreConnectionBasics.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestStoreConnectionBasics.java
new file mode 100644
index 0000000..42538d7
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestStoreConnectionBasics.java
@@ -0,0 +1,188 @@
+/*
+ * 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.store;
+
+
+import static org.junit.Assert.*;
+
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.Quad ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+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 ;
+
+/** 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)) ;
+ }) ;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestTransPromoteTDB2.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestTransPromoteTDB2.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestTransPromoteTDB2.java
new file mode 100644
index 0000000..34af067
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/AbstractTestTransPromoteTDB2.java
@@ -0,0 +1,67 @@
+/*
+ * 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.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TS_Store.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TS_Store.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TS_Store.java
new file mode 100644
index 0000000..f4ee83d
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TS_Store.java
@@ -0,0 +1,72 @@
+/*
+ * 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.store;
+
+import org.apache.jena.dboe.base.block.FileMode;
+import org.apache.jena.tdb2.store.value.TestDoubleNode62;
+import org.apache.jena.tdb2.store.value.TestNodeIdInline;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.apache.jena.tdb2.sys.TestOps;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.runner.RunWith ;
+import org.junit.runners.Suite ;
+
+@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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDB.java
new file mode 100644
index 0000000..16149df
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDB.java
@@ -0,0 +1,324 @@
+/*
+ * 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.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.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.junit.TL;
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+/** 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDBPersist.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDBPersist.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDBPersist.java
new file mode 100644
index 0000000..9ebee84
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDatasetTDBPersist.java
@@ -0,0 +1,113 @@
+/*
+ * 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.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.apache.jena.tdb2.junit.TL;
+import org.apache.jena.tdb2.store.GraphViewSwitchable;
+import org.junit.Test ;
+
+/** 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDynamicDatasetTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDynamicDatasetTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDynamicDatasetTDB.java
new file mode 100644
index 0000000..0248314
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestDynamicDatasetTDB.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.store;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.core.AbstractTestDynamicDataset ;
+import org.apache.jena.tdb2.TDB2;
+import org.apache.jena.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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphNamedTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphNamedTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphNamedTDB.java
new file mode 100644
index 0000000..54bc851
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphNamedTDB.java
@@ -0,0 +1,61 @@
+/*
+ * 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.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.apache.jena.tdb2.junit.TL;
+import org.junit.After ;
+import org.junit.Before ;
+
+/** 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphTDB.java
new file mode 100644
index 0000000..ae9359a
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestGraphTDB.java
@@ -0,0 +1,58 @@
+/*
+ * 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.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.apache.jena.tdb2.junit.TL;
+import org.junit.After ;
+import org.junit.Before ;
+
+/** 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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
new file mode 100644
index 0000000..fc1c158
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
@@ -0,0 +1,132 @@
+/*
+ * 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.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.apache.jena.tdb2.store.NodeId;
+import org.apache.jena.tdb2.store.NodeIdFactory;
+import org.apache.jena.tdb2.store.NodeIdInline;
+import org.apache.jena.tdb2.store.NodeIdType;
+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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestQuadFilter.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestQuadFilter.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestQuadFilter.java
new file mode 100644
index 0000000..6be081f
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestQuadFilter.java
@@ -0,0 +1,113 @@
+/*
+ * 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.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.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.store.NodeId;
+import org.apache.jena.tdb2.store.nodetable.NodeTable;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+import org.junit.Ignore;
+import org.junit.Test ;
+
+@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/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionDirect.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionDirect.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionDirect.java
new file mode 100644
index 0000000..a6615d1
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionDirect.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.store ;
+
+import org.apache.jena.dboe.base.block.FileMode;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.apache.jena.tdb2.sys.TestOps;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+
+/** 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()) ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionLock.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionLock.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionLock.java
new file mode 100644
index 0000000..d47708a
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionLock.java
@@ -0,0 +1,72 @@
+/*
+ * 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.store;
+
+import static org.junit.Assert.*;
+
+import org.apache.jena.dboe.base.file.AlreadyLocked;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.base.file.ProcessFileLock;
+import org.apache.jena.tdb2.sys.StoreConnection;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+/**
+ * Tests for {@link ProcessFileLock} in conjunction with {@link StoreConnection}s
+ */
+public class TestStoreConnectionLock {
+ @Rule
+ public TemporaryFolder tempDir = new TemporaryFolder();
+
+ @Test
+ public void lock_store_connection_01() {
+ Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
+ ProcessFileLock lock = StoreConnection.lockForLocation(dir);
+ assertFalse(lock.isLockedHere());
+
+ StoreConnection sConn = StoreConnection.connectCreate(dir);
+ assertEquals(dir, sConn.getLocation());
+ assertEquals(lock, sConn.getLock());
+ assertTrue(lock.isLockedHere());
+
+ StoreConnection.release(dir);
+ assertFalse(lock.isLockedHere());
+ }
+
+ @Test(expected=AlreadyLocked.class)
+ public void lock_store_connection_02() {
+ Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
+ ProcessFileLock lock = StoreConnection.lockForLocation(dir);
+ lock.lockEx();
+ StoreConnection sConn = StoreConnection.connectCreate(dir);
+ }
+// Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
+// // Creating a StoreConnection on the location will obtain the lock
+// StoreConnection.make(dir);
+// // Releasing the connection releases the lock
+// StoreConnection.release(dir);
+// }
+//
+// @Test(expected = TDBException.class)
+// public void location_lock_store_connection_02() throws IOException {
+// Location dir = Location.create(tempDir.getRoot().getAbsolutePath());
+// StoreConnection.make(dir);
+// }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMapped.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMapped.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMapped.java
new file mode 100644
index 0000000..9b67859
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMapped.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.store;
+
+import org.apache.jena.dboe.base.block.FileMode;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.sys.SystemTDB;
+import org.apache.jena.tdb2.sys.TestOps;
+import org.junit.AfterClass ;
+import org.junit.BeforeClass ;
+
+/** Slow tests - complete cleaning of disk areas each time */
+public class TestStoreConnectionMapped extends AbstractTestStoreConnectionBasics
+{
+ static FileMode mode ;
+
+ @BeforeClass
+ public static void beforeClassFileMode()
+ {
+ mode = SystemTDB.fileMode() ;
+ TestOps.setFileMode(FileMode.mapped) ;
+ }
+
+ @AfterClass
+ public static void afterClassFileMode()
+ {
+ TestOps.setFileMode(mode) ;
+ }
+
+ @Override
+ protected Location getLocation() {
+ return Location.create(ConfigTest.getCleanDir()) ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMem.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMem.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMem.java
new file mode 100644
index 0000000..f4e9350
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestStoreConnectionMem.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.store;
+
+import org.apache.jena.dboe.base.file.Location;
+
+public class TestStoreConnectionMem extends AbstractTestStoreConnectionBasics
+{
+ @Override
+ protected Location getLocation() {
+ return Location.mem("TestStoreConnection") ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestSuiteGraphTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestSuiteGraphTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestSuiteGraphTDB.java
new file mode 100644
index 0000000..37d5ec3
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestSuiteGraphTDB.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.jena.tdb2.store;
+
+import junit.framework.TestSuite ;
+import org.apache.jena.tdb2.ConfigTest;
+import org.apache.jena.tdb2.junit.TestFactoryTDB;
+import org.junit.runner.RunWith ;
+import org.junit.runners.AllTests ;
+
+/** Scripted test generation */
+
+@RunWith(AllTests.class)
+public class TestSuiteGraphTDB extends TestSuite
+{
+ static public TestSuite suite() { return new TestSuiteGraphTDB() ; }
+
+ private TestSuiteGraphTDB()
+ {
+ super("TDB-Scripts") ;
+ String manifestMain = ConfigTest.getTestingDataRoot()+"/manifest.ttl" ;
+ TestFactoryTDB.make(this, manifestMain, "TDB-") ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransPromoteTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransPromoteTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransPromoteTDB.java
new file mode 100644
index 0000000..02afae5
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransPromoteTDB.java
@@ -0,0 +1,72 @@
+/*
+ * 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.store;
+
+import org.apache.jena.dboe.transaction.txn.Transaction;
+import org.apache.jena.dboe.transaction.txn.TransactionCoordinator;
+import org.apache.jena.dboe.transaction.txn.TransactionException;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.tdb2.DatabaseMgr;
+import org.apache.log4j.Logger;
+
+public class TestTransPromoteTDB extends AbstractTestTransPromoteTDB2 {
+
+ public TestTransPromoteTDB() {
+ super(getLoggers());
+ }
+
+ private static Logger[] getLoggers() {
+ return new Logger[]{ Logger.getLogger(Transaction.class) } ;
+ }
+
+ @Override
+ protected void setPromotion(boolean b) {
+ TransactionCoordinator.promotion = b ;
+ }
+
+ @Override
+ protected boolean getPromotion() {
+ return TransactionCoordinator.promotion ;
+ }
+
+ @Override
+ protected void setReadCommitted(boolean b) {
+ TransactionCoordinator.readCommittedPromotion = b ;
+ }
+
+ @Override
+ protected boolean getReadCommitted() {
+ return TransactionCoordinator.readCommittedPromotion ;
+ }
+
+ @Override
+ protected Class<? extends Exception> getTransactionExceptionClass() {
+ return TransactionException.class;
+ }
+
+ @Override
+ protected DatasetGraph create() {
+ return DatabaseMgr.createDatasetGraph();
+ }
+
+ @Override
+ protected boolean supportsReadCommitted() {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactionLifecycleTDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactionLifecycleTDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactionLifecycleTDB.java
new file mode 100644
index 0000000..c86b077
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactionLifecycleTDB.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.store;
+
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.sparql.transaction.AbstractTestTransactionLifecycle;
+import org.apache.jena.tdb2.TDB2Factory;
+
+/** Transaction tests - from ARQ */
+public class TestTransactionLifecycleTDB extends AbstractTestTransactionLifecycle
+{
+ @Override
+ protected Dataset create() {
+ 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/store/TestTransactions.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactions.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactions.java
new file mode 100644
index 0000000..787ec7e
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTransactions.java
@@ -0,0 +1,205 @@
+/*
+ * 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.store;
+
+import java.io.StringReader ;
+import java.util.Iterator;
+
+import org.apache.jena.atlas.iterator.Iter ;
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.dboe.transaction.txn.TransactionException;
+import org.apache.jena.query.Dataset ;
+import org.apache.jena.query.ReadWrite;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.rdf.model.Statement;
+import org.apache.jena.riot.Lang ;
+import org.apache.jena.riot.RDFDataMgr ;
+import org.apache.jena.sparql.core.Quad;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.tdb2.sys.TDBInternal;
+import org.junit.After ;
+import org.junit.Before ;
+import org.junit.Test ;
+
+/** Transactions and store connections - extended tests assuming the
+ * basics work. Hence these tests use memory databases.
+ *
+ * For tests of StoreConnection basics:
+ * @see AbstractTestStoreConnectionBasics
+ * @see TestStoreConnectionDirect
+ * @see TestStoreConnectionMapped
+ * @see TestStoreConnectionMem
+ */
+public class TestTransactions
+{
+ // Per-test unique-ish.
+ static int count = 0 ;
+ long x = System.currentTimeMillis()+(count++) ;
+
+ String ns = "http://example/TestTransactions#" ;
+ String data1 = StrUtils.strjoinNL
+ ("prefix : <"+ns+">"
+ ,":s :p '000-"+x+"' ."
+ ,":s :p '111-"+x+"' ."
+ ," :g {"
+ ," :s :p '222-"+x+"' ."
+ ," :s :p '333-"+x+"' ."
+ ," :s :p '444-"+x+"' ."
+ ,"}"
+ ) ;
+ String data2 = StrUtils.strjoinNL
+ ("prefix : <"+ns+">"
+ ,":s :p 'AAA-"+x+"' ."
+ ,":s :p 'BBB-"+x+"' ."
+ ,":s :p 'CCC-"+x+"' ."
+ ,":s :p 'DDD-"+x+"' ."
+ ) ;
+
+ Dataset dataset ;
+ Location location ;
+
+ @Before public void before() {
+ location = Location.mem() ;
+ dataset = TDB2Factory.connectDataset(location) ;
+ }
+
+ @After public void after() {
+ dataset.close() ;
+ TDBInternal.expel(dataset.asDatasetGraph());
+ }
+
+ // Models across transactions
+ @Test public void trans_01() {
+ Model named = dataset.getNamedModel(ns+"g") ;
+ Txn.executeWrite(dataset, ()->{
+ RDFDataMgr.read(dataset, new StringReader(data1), null, Lang.TRIG) ;
+ }) ;
+
+ Txn.executeRead(dataset, ()->{
+ long x1 = Iter.count(dataset.getDefaultModel().listStatements()) ;
+ assertEquals(2, x1) ;
+ long x2 = Iter.count(named.listStatements()) ;
+ assertEquals(3, x2) ;
+ }) ;
+
+ }
+
+ @Test public void trans_02() {
+ Model model = dataset.getDefaultModel() ;
+ Txn.executeWrite(dataset, ()->{
+ RDFDataMgr.read(model, new StringReader(data2), null, Lang.TURTLE) ;
+ }) ;
+ Txn.executeRead(dataset, ()->{
+ assertEquals(4, model.size()) ;
+ }) ;
+ }
+
+ // Iterators and trasnaxction scope.
+
+ private void load(String data) {
+ Txn.executeWrite(dataset, ()->{
+ RDFDataMgr.read(dataset, new StringReader(data), null, Lang.TURTLE) ;
+ }) ;
+ }
+
+ public void iterator_01() {
+ load(data2);
+
+ dataset.begin(ReadWrite.READ);
+ Iterator<Quad> iter = TDBInternal.getDatasetGraphTDB(dataset).find();
+ Iter.consume(iter);
+ dataset.end();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void iterator_02() {
+ load(data2);
+
+ dataset.begin(ReadWrite.READ);
+ Iterator<Quad> iter = dataset.asDatasetGraph().find();
+ dataset.end();
+ iter.next();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void iterator_03() {
+ load(data2);
+
+ dataset.begin(ReadWrite.READ);
+ Iterator<Quad> iter = TDBInternal.getDatasetGraphTDB(dataset).find();
+ dataset.end();
+ iter.next();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void iterator_04() {
+ load(data2);
+ Iterator<Statement> iter = Txn.calculateRead(dataset, ()->dataset.getDefaultModel().listStatements());
+ iter.next();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void iterator_05() {
+ load(data2);
+ Iterator<Statement> iter = Txn.calculateWrite(dataset, ()->dataset.getDefaultModel().listStatements());
+ iter.next();
+ }
+
+ @Test(expected=TransactionException.class)
+ public void iterator_06() {
+ load(data2);
+
+ dataset.begin(ReadWrite.READ);
+ Iterator<Quad> iter = dataset.asDatasetGraph().find();
+ dataset.end();
+
+ dataset.begin(ReadWrite.READ);
+ iter.next();
+ dataset.end();
+ }
+
+// @Test
+// public void iterator_07() {
+// load(data2);
+//
+// // Isolated by copy.
+// Iterator<Quad> iter = TDBInternal.getDatasetGraphTDB(dataset).find();
+//
+// dataset.begin(ReadWrite.READ);
+// iter.next();
+// dataset.end();
+// }
+//
+// @Test
+// public void iterator_08() {
+// load(data2);
+//
+// // Isolated by copy.
+// Iterator<Quad> iter = TDBInternal.getDatasetGraphTDB(dataset).find();
+//
+// dataset.begin(ReadWrite.READ);
+// dataset.end();
+// iter.next();
+// }
+}
+
+
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTripleTable.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTripleTable.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTripleTable.java
new file mode 100644
index 0000000..c649a57
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestTripleTable.java
@@ -0,0 +1,137 @@
+/*
+ * 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.store;
+
+import java.util.Iterator ;
+
+import static org.junit.Assert.*;
+
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.graph.Node ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.query.ReadWrite ;
+import org.apache.jena.sparql.util.NodeFactoryExtra ;
+import org.apache.jena.tdb2.setup.TDBBuilder;
+import org.apache.jena.tdb2.store.DatasetGraphTDB;
+import org.apache.jena.tdb2.store.DatasetGraphTxn;
+import org.apache.jena.tdb2.store.TripleTable;
+import org.apache.log4j.Level ;
+import org.apache.log4j.Logger ;
+import org.junit.Test ;
+
+public class TestTripleTable
+{
+ static {
+ Logger.getLogger("org.apache.jena.tdb.info").setLevel(Level.WARN) ;
+ Logger.getLogger("org.apache.jena.tdb.exec").setLevel(Level.WARN) ;
+ }
+
+ private static void add(TripleTable table, Node s, Node p, Node o)
+ {
+ table.add(new Triple(s,p,o)) ;
+ }
+
+ private static void notMatch(TripleTable table, Node s, Node p, Node o)
+ {
+ Iterator<Triple> iter = table.find(s, p, o) ;
+ assertNotNull(iter) ;
+ assertFalse(iter.hasNext()) ;
+ }
+
+ private static void match(TripleTable table, Node s, Node p, Node o)
+ {
+ Iterator<Triple> iter = table.find(s, p, o) ;
+ assertNotNull(iter) ;
+ assertTrue(iter.hasNext()) ;
+ }
+
+
+ private static void contains(TripleTable table, Node s, Node p, Node o)
+ {
+ Iterator<Triple> iter = table.find(s, p, o) ;
+ assertNotNull(iter) ;
+ assertTrue(iter.hasNext()) ;
+ assertEquals(new Triple(s, p, o), iter.next()) ;
+ assertFalse(iter.hasNext()) ;
+ }
+
+ static Node n1 = NodeFactoryExtra.parseNode("<http://example/n1>") ;
+ static Node n2 = NodeFactoryExtra.parseNode("<http://example/n2>") ;
+ static Node n3 = NodeFactoryExtra.parseNode("<http://example/n3>") ;
+ static Node n4 = NodeFactoryExtra.parseNode("<http://example/n4>") ;
+ static Node n5 = NodeFactoryExtra.parseNode("<http://example/n5>") ;
+ static Node n6 = NodeFactoryExtra.parseNode("<http://example/n6>") ;
+
+ @Test public void createTripleTable1()
+ {
+ TripleTable table = createTripleTableMem() ;
+ notMatch(table, n1, n2, n3) ;
+ }
+
+ @Test public void add1()
+ {
+ TripleTable table = createTripleTableMem() ;
+ table.add(new Triple(n1,n2,n3)) ;
+ }
+
+ @Test public void find1()
+ {
+ TripleTable table = createTripleTableMem() ;
+ add(table, n1, n2, n3) ;
+ contains(table, n1, n2, n3) ;
+ notMatch(table, n1, n2, n4) ;
+ }
+
+ @Test public void find2()
+ {
+ TripleTable table = createTripleTableMem() ;
+ add(table, n1, n2, n3) ;
+ add(table, n1, n2, n4) ;
+ contains(table, n1, n2, n3) ;
+ contains(table, n1, n2, n4) ;
+ }
+
+ @Test public void find3()
+ {
+ TripleTable table = createTripleTableMem() ;
+ add(table, n1, n2, n3) ;
+ add(table, n4, n5, n6) ;
+ contains(table, n1, n2, n3) ;
+ contains(table, n4, n5, n6) ;
+ notMatch(table, n1, n2, n4) ;
+ }
+
+ @Test public void find4()
+ {
+ TripleTable table = createTripleTableMem() ;
+ add(table, n1, n2, n3) ;
+ add(table, n4, n5, n6) ;
+ match(table, Node.ANY, n2, n3) ;
+ match(table, null, n2, n3) ;
+ match(table, null, null, null) ;
+ }
+
+ private TripleTable createTripleTableMem()
+ {
+ DatasetGraphTxn dsx = TDBBuilder.build(Location.mem()) ;
+ dsx.begin(ReadWrite.WRITE);
+ DatasetGraphTDB ds = (DatasetGraphTDB)dsx ;
+ return ds.getTripleTable() ;
+ }
+}
http://git-wip-us.apache.org/repos/asf/jena/blob/3d456654/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/Test_SPARQL_TDB.java
----------------------------------------------------------------------
diff --git a/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/Test_SPARQL_TDB.java b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/Test_SPARQL_TDB.java
new file mode 100644
index 0000000..cb335af
--- /dev/null
+++ b/jena-db/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/Test_SPARQL_TDB.java
@@ -0,0 +1,222 @@
+/*
+ * 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.store;
+
+import static org.junit.Assert.*;
+import org.apache.jena.atlas.lib.StrUtils ;
+import org.apache.jena.dboe.base.file.Location;
+import org.apache.jena.dboe.jenax.Txn;
+import org.apache.jena.graph.Graph ;
+import org.apache.jena.graph.NodeFactory ;
+import org.apache.jena.graph.Triple ;
+import org.apache.jena.query.* ;
+import org.apache.jena.rdf.model.Model ;
+import org.apache.jena.sparql.sse.SSE ;
+import org.apache.jena.tdb2.TDB2;
+import org.apache.jena.tdb2.TDB2Factory;
+import org.apache.jena.update.* ;
+import org.junit.Test ;
+
+/**
+ * Test SPARQL
+ */
+public class Test_SPARQL_TDB
+{
+ private static Dataset create() {
+ return TDB2Factory.createDataset() ;
+ }
+
+ private static Dataset create(Location location) {
+ return TDB2Factory.connectDataset(location) ;
+ }
+
+ private static String graphName = "http://example/" ;
+ private static Triple triple = SSE.parseTriple("(<x> <y> 123)") ;
+
+ // Standalone graph.
+ @Test public void sparql1()
+ {
+ // Test OpExecutor.execute(OpBGP) for a named graph used as a standalone model
+ Dataset ds = create() ;
+ add(ds, graphName, triple) ;
+ Txn.executeRead(ds, ()->{
+ Model m = ds.getNamedModel(graphName) ;
+ String qs = "SELECT * { ?s ?p ?o . }" ;
+ Query query = QueryFactory.create(qs) ;
+ QueryExecution qexec = QueryExecutionFactory.create(query, m) ;
+ ResultSet rs = qexec.execSelect() ;
+ ResultSetFormatter.consume(rs) ;
+ }) ;
+ }
+
+ // Standalone graph.
+ @Test public void sparql2()
+ {
+ // Test OpExecutor.execute(OpFilter)for a named graph used as a standalone model
+ Dataset ds = create() ;
+ add(ds, graphName, triple) ;
+
+ Txn.executeRead(ds, ()->{
+ Model m = ds.getNamedModel(graphName) ;
+ String qs = "SELECT * { ?s ?p ?o . FILTER ( ?o < 456 ) }" ;
+ Query query = QueryFactory.create(qs) ;
+ try(QueryExecution qexec = QueryExecutionFactory.create(query, m)) {
+ ResultSet rs = qexec.execSelect() ;
+ ResultSetFormatter.consume(rs) ;
+ }
+ }) ;
+ }
+
+ // Requires OpDatasetNames
+ @Test public void sparql3()
+ {
+ Dataset dataset = create() ;
+ // No triple added
+ Txn.executeRead(dataset, ()->{
+ Query query = QueryFactory.create("SELECT ?g { GRAPH ?g {} }") ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, dataset) ;
+ ResultSet rs = qExec.execSelect() ;
+ int n = ResultSetFormatter.consume(rs) ;
+ assertEquals(0, n) ;
+ }) ;
+ }
+
+ @Test public void sparql4()
+ {
+ Dataset dataset = create() ;
+ add(dataset, graphName, triple) ;
+ Txn.executeRead(dataset, ()->{
+ Query query = QueryFactory.create("SELECT ?g { GRAPH ?g {} }") ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, dataset) ;
+ ResultSet rs = qExec.execSelect() ;
+ int n = ResultSetFormatter.consume(rs) ;
+ assertEquals(1, n) ;
+ }) ;
+ }
+
+ @Test public void sparql5()
+ {
+ Dataset dataset = create() ;
+ add(dataset, graphName, triple);
+ Txn.executeRead(dataset, ()->{
+ Query query = QueryFactory.create("ASK { GRAPH <"+graphName+"> {} }") ;
+ boolean b = QueryExecutionFactory.create(query, dataset).execAsk() ;
+ assertEquals(true, b) ;
+ }) ;
+ }
+
+ @Test public void sparql6()
+ {
+ Dataset dataset = create() ;
+ add(dataset, graphName, triple);
+ Txn.executeRead(dataset, ()->{
+ Query query = QueryFactory.create("ASK { GRAPH <http://example/x> {} }") ;
+ boolean b = QueryExecutionFactory.create(query, dataset).execAsk() ;
+ assertEquals(false, b) ;
+ }) ;
+ }
+
+ private static void add(Dataset dataset, String graphName, Triple triple) {
+ Txn.executeWrite(dataset, ()->{
+ Graph g2 = dataset.asDatasetGraph().getGraph(NodeFactory.createURI(graphName)) ;
+ g2.add(triple) ;
+ });
+ }
+
+ // Test transactions effective.
+
+ @Test public void sparql_txn_1()
+ {
+ Dataset dataset = create() ;
+ Txn.executeWrite(dataset, ()->{
+ update(dataset, "INSERT DATA { <x:s> <x:p> <x:o> }") ;
+ }) ;
+ // Explicit trasnaction steps.
+ dataset.begin(ReadWrite.READ) ;
+ try {
+ int n = count(dataset) ;
+ assertEquals(1, n) ;
+ n = count(dataset, "SELECT * { <x:s> <x:p> <x:o>}") ;
+ assertEquals(1, n) ;
+ } finally { dataset.end() ; }
+ }
+
+ @Test public void sparql_txn_2()
+ {
+ Dataset dataset1 = create(Location.mem("foo")) ;
+ Dataset dataset2 = create(Location.mem("foo")) ;
+
+ Txn.executeWrite(dataset1, ()->{
+ update(dataset1, "INSERT DATA { <x:s> <x:p> <x:o> }") ;
+ }) ;
+
+ Txn.executeRead(dataset1, ()->{
+ assertEquals(1, count(dataset1)) ;
+ }) ;
+
+ // Same location.
+ Txn.executeRead(dataset2, ()->{
+ assertEquals(1, count(dataset2)) ;
+ }) ;
+ }
+
+ @Test public void sparql_update_unionGraph()
+ {
+ Dataset ds = TDB2Factory.createDataset() ;
+ // Update concrete default graph
+ Txn.executeWrite(ds, ()->{
+ ds.asDatasetGraph().add(SSE.parseQuad("(<g> <s> <p> 123)")) ;
+ }) ;
+ ds.getContext().setTrue(TDB2.symUnionDefaultGraph) ;
+
+ Txn.executeWrite(ds, ()->{
+ // Update by looking in union graph
+ String us = StrUtils.strjoinNL(
+ "INSERT { GRAPH <http://example/g2> { ?s ?p 'NEW' } }",
+ "WHERE { ",
+ "?s ?p 123",
+ " }" ) ;
+ UpdateRequest req = UpdateFactory.create(us) ;
+ UpdateAction.execute(req, ds) ;
+ }) ;
+
+ Txn.executeRead(ds, ()->{
+ Model m = ds.getNamedModel("http://example/g2") ;
+ assertEquals("Did not find 1 statement in named graph", 1, m.size()) ;
+ }) ;
+ }
+
+ private int count(Dataset dataset)
+ { return count(dataset, "SELECT * { ?s ?p ?o }") ; }
+
+ private int count(Dataset dataset, String queryString)
+
+ {
+ Query query = QueryFactory.create(queryString) ;
+ QueryExecution qExec = QueryExecutionFactory.create(query, dataset) ;
+ ResultSet rs = qExec.execSelect() ;
+ return ResultSetFormatter.consume(rs) ;
+ }
+ private void update(Dataset dataset, String string)
+ {
+ UpdateRequest req = UpdateFactory.create(string) ;
+ UpdateProcessor proc = UpdateExecutionFactory.create(req, dataset) ;
+ proc.execute() ;
+ }
+}