From: <dm...@us...> - 2010-10-18 16:51:02
|
Revision: 3808 http://bigdata.svn.sourceforge.net/bigdata/?rev=3808&view=rev Author: dmacgbr Date: 2010-10-18 16:50:53 +0000 (Mon, 18 Oct 2010) Log Message: ----------- Test demonstrating problem with default graph matching Added Paths: ----------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java Added: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java (rev 0) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-18 16:50:53 UTC (rev 3808) @@ -0,0 +1,171 @@ +/** +Copyright (C) SYSTAP, LLC 2006-2007. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; version 2 of the License. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + * Created on Sep 16, 2009 + */ + +package com.bigdata.rdf.sail; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.Collection; +import java.util.LinkedList; +import java.util.Properties; + +import org.apache.log4j.Logger; +import org.openrdf.model.Resource; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.impl.URIImpl; +import org.openrdf.query.BindingSet; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.query.impl.BindingImpl; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; +import org.openrdf.rio.RDFFormat; +import org.openrdf.rio.RDFParseException; +import org.openrdf.sail.SailException; + +import com.bigdata.rdf.axioms.NoAxioms; +import com.bigdata.rdf.vocab.NoVocabulary; + +/** + * @author <a href="mailto:mrp...@us...">Mike Personick</a> + * @version $Id$ + */ +public class DavidsTestBOps extends ProxyBigdataSailTestCase { + + protected static final Logger log = Logger.getLogger(TestBOps.class); + + @Override + public Properties getProperties() { + + Properties props = super.getProperties(); + + props.setProperty(BigdataSail.Options.TRUTH_MAINTENANCE, "false"); + props.setProperty(BigdataSail.Options.AXIOMS_CLASS, NoAxioms.class.getName()); + props.setProperty(BigdataSail.Options.VOCABULARY_CLASS, NoVocabulary.class.getName()); + props.setProperty(BigdataSail.Options.JUSTIFY, "false"); + props.setProperty(BigdataSail.Options.TEXT_INDEX, "false"); + + return props; + + } + + /** + * + */ + public DavidsTestBOps() { + } + + /** + * @param arg0 + */ + public DavidsTestBOps(String arg0) { + super(arg0); + } + + public void testDefaultGraph () + throws Exception + { + BigdataSail sail = getTheSail () ; + final ValueFactory vf = sail.getValueFactory(); + RepositoryConnection cxn = getRepositoryConnection ( sail ) ; + + String ns = "http://xyz.com/test#" ; + String kb = String.format ( "<%ss> <%sp> <%so> .", ns, ns, ns ) ; + String qs = String.format ( "select ?p ?o where { <%ss> ?p ?o .}", ns ) ; + + Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; + + Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "p", new URIImpl ( String.format ( "%sp", ns ) ) ) + , new BindingImpl ( "o", new URIImpl ( String.format ( "%so", ns ) ) ) + ) + ) ; + run ( sail, cxn, kb, graphs, qs, expected ) ; + } + + private BigdataSail getTheSail () + throws SailException + { + BigdataSail sail = getSail () ; + sail.initialize () ; + return sail ; + } + + private RepositoryConnection getRepositoryConnection ( BigdataSail sail ) + throws RepositoryException + { + BigdataSailRepository repo = new BigdataSailRepository ( sail ) ; + BigdataSailRepositoryConnection cxn = ( BigdataSailRepositoryConnection )repo.getConnection () ; + cxn.setAutoCommit ( false ) ; + return cxn ; + } + + private void run ( BigdataSail sail, RepositoryConnection rc, String kb, Resource graphs [], String qs, Collection<BindingSet> expected ) + { + try + { + for ( Resource g : graphs ) + load ( rc, kb, g ) ; + compare ( query ( rc, qs ), expected ) ; + } + catch ( Exception e ) + { + e.printStackTrace () ; + } + finally + { + try { if ( null != rc ) rc.close () ; } + catch ( Exception e ) {} + if ( null != sail ) sail.__tearDownUnitTest () ; + } + } + + private void load ( RepositoryConnection rc, String kb, Resource g ) + throws RepositoryException, RDFParseException, IOException + { + rc.add ( new ByteArrayInputStream ( kb.toString ().getBytes ( "UTF-8" ) ) + , "http://xyz.com/test" + , RDFFormat.TURTLE + , g + ) ; + rc.commit () ; + } + + private TupleQueryResult query ( RepositoryConnection rc, String qs ) + throws RepositoryException, MalformedQueryException, QueryEvaluationException + { + return rc.prepareTupleQuery ( QueryLanguage.SPARQL, qs ).evaluate () ; + } + + private Collection<BindingSet> getExpected ( BindingSet... bindingSets ) + { + Collection<BindingSet> expected = new LinkedList<BindingSet> () ; + for ( BindingSet bs : bindingSets ) + expected.add ( bs ) ; + return expected ; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-10-18 17:09:12
|
Revision: 3811 http://bigdata.svn.sourceforge.net/bigdata/?rev=3811&view=rev Author: thompsonbry Date: 2010-10-18 17:09:06 +0000 (Mon, 18 Oct 2010) Log Message: ----------- Changed logger name to class name. Modified to wrap and throw Exception in run(). Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-18 16:56:34 UTC (rev 3810) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-18 17:09:06 UTC (rev 3811) @@ -57,7 +57,7 @@ */ public class DavidsTestBOps extends ProxyBigdataSailTestCase { - protected static final Logger log = Logger.getLogger(TestBOps.class); + protected static final Logger log = Logger.getLogger(DavidsTestBOps.class); @Override public Properties getProperties() { @@ -91,6 +91,10 @@ throws Exception { BigdataSail sail = getTheSail () ; + if(!((BigdataSail)sail).isQuads()) { + log.info("This test requires quads."); + return; + } final ValueFactory vf = sail.getValueFactory(); RepositoryConnection cxn = getRepositoryConnection ( sail ) ; @@ -139,8 +143,11 @@ finally { try { if ( null != rc ) rc.close () ; } - catch ( Exception e ) {} - if ( null != sail ) sail.__tearDownUnitTest () ; + catch ( Exception e ) { + throw new RuntimeException(e); + } finally { + if ( null != sail ) sail.__tearDownUnitTest () ; + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dm...@us...> - 2010-10-19 11:16:09
|
Revision: 3817 http://bigdata.svn.sourceforge.net/bigdata/?rev=3817&view=rev Author: dmacgbr Date: 2010-10-19 11:16:00 +0000 (Tue, 19 Oct 2010) Log Message: ----------- Add a few more tests in the area of default and named graph matching Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-19 08:50:30 UTC (rev 3816) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-19 11:16:00 UTC (rev 3817) @@ -87,7 +87,7 @@ super(arg0); } - public void testDefaultGraph () + public void testImplementationDefinedDefaultGraph () throws Exception { BigdataSail sail = getTheSail () ; @@ -111,6 +111,100 @@ run ( sail, cxn, kb, graphs, qs, expected ) ; } + public void testExplicitDefaultGraph () + throws Exception + { + BigdataSail sail = getTheSail () ; + if(!((BigdataSail)sail).isQuads()) { + log.info("This test requires quads."); + return; + } + + final ValueFactory vf = sail.getValueFactory(); + RepositoryConnection cxn = getRepositoryConnection ( sail ) ; + + String ns = "http://xyz.com/test#" ; + String kb = String.format ( "<%ss> <%sp> <%so> .", ns, ns, ns ) ; + String qs = String.format ( "select ?p ?o from <%sg1> from <%sg2> where { <%ss> ?p ?o .}", ns, ns, ns ) ; + + Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; + + Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "p", new URIImpl ( String.format ( "%sp", ns ) ) ) + , new BindingImpl ( "o", new URIImpl ( String.format ( "%so", ns ) ) ) + ) + ) ; + run ( sail, cxn, kb, graphs, qs, expected ) ; + } + + public void testNamedGraphNoGraphKeyword1 () + throws Exception + { + BigdataSail sail = getTheSail () ; + if(!((BigdataSail)sail).isQuads()) { + log.info("This test requires quads."); + return; + } + + final ValueFactory vf = sail.getValueFactory(); + RepositoryConnection cxn = getRepositoryConnection ( sail ) ; + + String ns = "http://xyz.com/test#" ; + String kb = String.format ( "<%ss> <%sp> <%so> .", ns, ns, ns ) ; + String qs = String.format ( "select ?s from named <%sg2> where { ?s ?p ?o .}", ns ) ; + + Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; + + Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "s", new URIImpl ( String.format ( "%ss", ns ) ) ) ) ) ; + + run ( sail, cxn, kb, graphs, qs, expected ) ; + } + + public void testNamedGraphNoGraphKeyword2 () + throws Exception + { + BigdataSail sail = getTheSail () ; + if(!((BigdataSail)sail).isQuads()) { + log.info("This test requires quads."); + return; + } + + final ValueFactory vf = sail.getValueFactory(); + RepositoryConnection cxn = getRepositoryConnection ( sail ) ; + + String ns = "http://xyz.com/test#" ; + String kb = String.format ( "<%ss> <%sp> <%so> .", ns, ns, ns ) ; + String qs = String.format ( "select ?s from named <%sg1> from named <%sg2> where { ?s ?p ?o .}", ns, ns ) ; + + Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; + + Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "s", new URIImpl ( String.format ( "%ss", ns ) ) ) ) ) ; + + run ( sail, cxn, kb, graphs, qs, expected ) ; + } + + public void testExplicitDefaultAndNamedGraphNoGraphKeyword () + throws Exception + { + BigdataSail sail = getTheSail () ; + if(!((BigdataSail)sail).isQuads()) { + log.info("This test requires quads."); + return; + } + + final ValueFactory vf = sail.getValueFactory(); + RepositoryConnection cxn = getRepositoryConnection ( sail ) ; + + String ns = "http://xyz.com/test#" ; + String kb = String.format ( "<%ss> <%sp> <%so> .", ns, ns, ns ) ; + String qs = String.format ( "select ?s from <%sg1> from named <%sg2> where { ?s ?p ?o .}", ns, ns ) ; + + Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; + + Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "s", new URIImpl ( String.format ( "%ss", ns ) ) ) ) ) ; + + run ( sail, cxn, kb, graphs, qs, expected ) ; + } + private BigdataSail getTheSail () throws SailException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dm...@us...> - 2010-10-19 11:27:58
|
Revision: 3818 http://bigdata.svn.sourceforge.net/bigdata/?rev=3818&view=rev Author: dmacgbr Date: 2010-10-19 11:27:52 +0000 (Tue, 19 Oct 2010) Log Message: ----------- Fixed some tests based on re-reading of the spec Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java Modified: branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-19 11:16:00 UTC (rev 3817) +++ branches/QUADS_QUERY_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/DavidsTestBOps.java 2010-10-19 11:27:52 UTC (rev 3818) @@ -154,7 +154,7 @@ Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; - Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "s", new URIImpl ( String.format ( "%ss", ns ) ) ) ) ) ; + Collection<BindingSet> expected = getExpected () ; run ( sail, cxn, kb, graphs, qs, expected ) ; } @@ -177,7 +177,7 @@ Resource graphs [] = new Resource [] { vf.createURI ( String.format ( "%sg1", ns ) ), vf.createURI ( String.format ( "%sg2", ns ) ) } ; - Collection<BindingSet> expected = getExpected ( createBindingSet ( new BindingImpl ( "s", new URIImpl ( String.format ( "%ss", ns ) ) ) ) ) ; + Collection<BindingSet> expected = getExpected () ; run ( sail, cxn, kb, graphs, qs, expected ) ; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |