Skip to content

Commit

Permalink
run two fuseki servers with different default graph behaviors
Browse files Browse the repository at this point in the history
On a SPARQLUpdateStore we need two different behaviors for:
- Dataset tests: need empty default graph.
- ConjunctiveGraph tests: need default graph to be union of all graphs.
  • Loading branch information
joernhees committed Mar 4, 2015
1 parent 3e7b793 commit b75c875
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ before_install:
- tar -zxf jena-fuseki-1.1.1-distribution.tar.gz
- mv jena-fuseki-1.1.1 fuseki
- cd fuseki
- bash fuseki-server --debug --update --memTDB --set tdb:unionDefaultGraph=true /db &>fuseki.log &
# normal SPARQLStore & Dataset tests:
- bash fuseki-server --port 3030 --debug --update --mem /db &>fuseki.log &
# SPARQLUpdateStore tests & ConjunctiveGraph endpoint behavior:
- bash fuseki-server --port 3031 --debug --update --memTDB --set tdb:unionDefaultGraph=true /db &>fuseki.log &
- sleep 2
- cd ..

Expand Down
44 changes: 30 additions & 14 deletions test/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@
from nose.exc import SkipTest


# Will also run SPARQLUpdateStore tests against local SPARQL1.1 endpoint if
# available. This assumes SPARQL1.1 query/update endpoints running locally at
# http://localhost:3030/db/
#
# Testing SPARQLUpdateStore Dataset behavior needs a different endpoint behavior
# than our ConjunctiveGraph tests in test_sparqlupdatestore.py!
#
# For the tests here to run, you can for example start fuseki with:
# ./fuseki-server --mem --update /db

# THIS WILL DELETE ALL DATA IN THE /db dataset

HOST = 'http://localhost:3030'
DB = '/db/'


class DatasetTestCase(unittest.TestCase):
store = 'default'
slow = True
Expand All @@ -25,7 +41,7 @@ def setUp(self):
_, self.tmppath = mkstemp(
prefix='test', dir='/tmp', suffix='.sqlite')
elif self.store == "SPARQLUpdateStore":
root = "http://localhost:3030/db/"
root = HOST + DB
self.graph.open((root + "sparql", root + "update"))
else:
self.tmppath = mkdtemp()
Expand Down Expand Up @@ -64,8 +80,8 @@ def tearDown(self):

def testGraphAware(self):

if not self.graph.store.graph_aware: return
if not self.graph.store.graph_aware: return

g = self.graph
g1 = g.graph(self.c1)

Expand All @@ -76,9 +92,9 @@ def testGraphAware(self):
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
set([self.c1, DATASET_DEFAULT_GRAPH_ID]))

# added graph is empty
# added graph is empty
self.assertEquals(len(g1), 0)

g1.add( (self.tarek, self.likes, self.pizza) )

# added graph still exists
Expand All @@ -90,7 +106,7 @@ def testGraphAware(self):

g1.remove( (self.tarek, self.likes, self.pizza) )

# added graph is empty
# added graph is empty
self.assertEquals(len(g1), 0)

# Some SPARQL endpoint backends (e.g. TDB) do not consider
Expand All @@ -101,29 +117,29 @@ def testGraphAware(self):
set([self.c1, DATASET_DEFAULT_GRAPH_ID]))

g.remove_graph(self.c1)

# graph is gone
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
set([DATASET_DEFAULT_GRAPH_ID]))

def testDefaultGraph(self):
# Something the default graph is read-only (e.g. TDB in union mode)
if self.store == "SPARQLUpdateStore":
print "Please make sure updating the default graph " \
"is supported by your SPARQL endpoint"

self.graph.add(( self.tarek, self.likes, self.pizza))
self.assertEquals(len(self.graph), 1)
# only default exists
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
set([DATASET_DEFAULT_GRAPH_ID]))

# removing default graph removes triples but not actual graph
self.graph.remove_graph(DATASET_DEFAULT_GRAPH_ID)

self.assertEquals(len(self.graph), 0)
# default still exists
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
self.assertEquals(set(x.identifier for x in self.graph.contexts()),
set([DATASET_DEFAULT_GRAPH_ID]))

def testNotUnion(self):
Expand All @@ -134,7 +150,7 @@ def testNotUnion(self):
g1 = self.graph.graph(self.c1)
g1.add((self.tarek, self.likes, self.pizza))

self.assertEqual(list(self.graph.objects(self.tarek, None)),
self.assertEqual(list(self.graph.objects(self.tarek, None)),
[])
self.assertEqual(list(g1.objects(self.tarek, None)), [self.pizza])

Expand All @@ -159,7 +175,7 @@ def testNotUnion(self):
if s.name == "SPARQLUpdateStore":
import urllib2
try:
assert len(urllib2.urlopen("http://localhost:3030/").read()) > 0
assert len(urllib2.urlopen(HOST).read()) > 0
except:
sys.stderr.write("No SPARQL endpoint for %s (tests skipped)\n" % s.name)
continue
Expand Down
22 changes: 15 additions & 7 deletions test/test_sparqlupdatestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@
from rdflib import ConjunctiveGraph, URIRef, Literal
from rdflib.util import from_n3

# this assumed SPARQL1.1 query/update endpoints
# running locally at http://localhost:3030/db/
# for instance fuseki started with
# ./fuseki-server --memTDB --update --set tdb:unionDefaultGraph=true /db
HOST = 'http://localhost:3031'
DB = '/db/'

# this assumes SPARQL1.1 query/update endpoints running locally at
# http://localhost:3031/db/
#
# The ConjunctiveGraph tests below require that the SPARQL endpoint renders its
# default graph as the union of all known graphs! This is incompatible with the
# endpoint behavior required by our Dataset tests in test_dataset.py, so you
# need to run a second SPARQL endpoint on a non standard port,
# e.g. fuseki started with:
# ./fuseki-server --port 3031 --memTDB --update --set tdb:unionDefaultGraph=true /db

# THIS WILL DELETE ALL DATA IN THE /db dataset

Expand All @@ -30,7 +38,7 @@ def setUp(self):
self.longMessage = True
self.graph = ConjunctiveGraph('SPARQLUpdateStore')

root = "http://localhost:3030/db/"
root = HOST + DB
self.graph.open((root + "sparql", root + "update"))

# clean out the store
Expand Down Expand Up @@ -297,9 +305,9 @@ def testEmptyLiteral(self):
from nose import SkipTest
import urllib2
try:
assert len(urllib2.urlopen("http://localhost:3030/").read()) > 0
assert len(urllib2.urlopen(HOST).read()) > 0
except:
raise SkipTest("http://localhost:3030/ is unavailable.")
raise SkipTest(HOST + " is unavailable.")


if __name__ == '__main__':
Expand Down

0 comments on commit b75c875

Please sign in to comment.