From: <tho...@us...> - 2011-07-12 14:22:53
|
Revision: 4890 http://bigdata.svn.sourceforge.net/bigdata/?rev=4890&view=rev Author: thompsonbry Date: 2011-07-12 14:22:46 +0000 (Tue, 12 Jul 2011) Log Message: ----------- I have modified BigdataValueFactoryImpl per the change recommended above. I have integrated the unit test into the test suite for TestBigdataSailWithQuads. I have extended the test suite for the BigdataValueFactoryImpl to verify the behavior when a DummyIV is used. These changes have been applied to the 1.0.0 release branch and to the current development branch. See https://sourceforge.net/apps/trac/bigdata/ticket/348 Modified Paths: -------------- branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java Added Paths: ----------- branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java Modified: branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java =================================================================== --- branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2011-07-12 12:21:08 UTC (rev 4889) +++ branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -42,6 +42,7 @@ import org.openrdf.model.impl.BooleanLiteralImpl; import com.bigdata.cache.WeakValueCache; +import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.util.CanonicalFactory; @@ -445,12 +446,24 @@ if (v == null) return null; - if (v instanceof BigdataValueImpl - && ((BigdataValueImpl) v).getValueFactory() == this) { + if (v instanceof BigdataValueImpl + && ((BigdataValueImpl) v).getValueFactory() == this) { - // a value from the same value factory. - return (BigdataValue) v; + final BigdataValueImpl v1 = (BigdataValueImpl) v; + final IV<?, ?> iv = v1.getIV(); + + if (iv == null || iv.isTermId() && iv.getTermId() != 0L) { + + /* + * A value from the same value factory whose IV is either + * unknown or defined (but not a NullIV or DummyIV). + */ + + return (BigdataValue) v; + + } + } if (v instanceof BooleanLiteralImpl) { Modified: branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java =================================================================== --- branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java 2011-07-12 12:21:08 UTC (rev 4889) +++ branches/BIGDATA_RELEASE_1_0_0/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -36,7 +36,11 @@ import org.openrdf.model.URI; import org.openrdf.model.ValueFactory; +import com.bigdata.rdf.internal.DummyIV; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.TermId; import com.bigdata.rdf.internal.XSD; +import com.sun.jdi.Value; /** * Unit tests for {@link BigdataValueFactoryImpl}. @@ -126,4 +130,32 @@ } + /** + * Unit test verifies that a new {@link BigdataValue} instance is returned + * when {@link BigdataValueFactory#asValue(org.openrdf.model.Value)} is + * invoked with a {@link BigdataValue} whose {@link IV} is a "dummmy" IV + * (aka a "mock" IV). A "dummy" or "mock" {@link IV} is an {@link IV} which + * stands in for a "null" and is used to hold the place for an RDF + * {@link Value} which is not known to the database. + * + * @see https://sourceforge.net/apps/trac/bigdata/ticket/348 + */ + public void test_asValue_mockIV() { + + final BigdataValue v1 = vf.createURI("http://www.bigdata.com"); + + final BigdataValue v2 = vf.asValue(v1); + + v1.setIV(DummyIV.INSTANCE); + + final BigdataValue v3 = vf.asValue(v1); + + // same BigdataValue + assertTrue(v2 == v1); + + // distinct BigdataValue + assertTrue(v3 != v1); + + } + } Modified: branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java =================================================================== --- branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-07-12 12:21:08 UTC (rev 4889) +++ branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -119,6 +119,7 @@ suite.addTestSuite(com.bigdata.rdf.sail.TestTicket275.class); suite.addTestSuite(com.bigdata.rdf.sail.TestTicket276.class); + suite.addTestSuite(com.bigdata.rdf.sail.TestTicket348.class); suite.addTestSuite(com.bigdata.rdf.sail.DavidsTestBOps.class); Added: branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java =================================================================== --- branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java (rev 0) +++ branches/BIGDATA_RELEASE_1_0_0/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -0,0 +1,141 @@ +/** +Copyright (C) SYSTAP, LLC 2011. 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 + */ + +package com.bigdata.rdf.sail; + +import java.io.IOException; + +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.RepositoryResult; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParseException; +import org.openrdf.sail.memory.MemoryStore; + +/** + * Unit test template for use in submission of bugs. + * <p> + * This test case will delegate to an underlying backing store. You can specify + * this store via a JVM property as follows: + * <code>-DtestClass=com.bigdata.rdf.sail.TestBigdataSailWithQuads</code> + * <p> + * There are three possible configurations for the testClass: + * <ul> + * <li>com.bigdata.rdf.sail.TestBigdataSailWithQuads (quads mode)</li> + * <li>com.bigdata.rdf.sail.TestBigdataSailWithoutSids (triples mode)</li> + * <li>com.bigdata.rdf.sail.TestBigdataSailWithSids (SIDs mode)</li> + * </ul> + * <p> + * The default for triples and SIDs mode is for inference with truth maintenance + * to be on. If you would like to turn off inference, make sure to do so in + * {@link #getProperties()}. + * + * @author <a href="mailto:mrp...@us...">Mike Personick</a> + * @version $Id$ + * @see https://sourceforge.net/apps/trac/bigdata/ticket/348 + */ +public class TestTicket348 extends QuadsTestCase { + + public TestTicket348() { + } + + public TestTicket348(String arg0) { + super(arg0); + } + + public void testBug() throws Exception { + // try with Sesame MemoryStore: + executeTest(new SailRepository(new MemoryStore())); + + // try with Bigdata: + try { + executeTest(new BigdataSailRepository(getSail())); + } finally { + getSail().__tearDownUnitTest(); + } + } + + private void executeTest(final SailRepository repo) + throws RepositoryException, MalformedQueryException, + QueryEvaluationException, RDFParseException, RDFHandlerException, + IOException { + try { + repo.initialize(); + final RepositoryConnection conn = repo.getConnection(); + try { + conn.setAutoCommit(false); + final ValueFactory vf = conn.getValueFactory(); + final URI uri = vf.createURI("os:/elem/example"); + // run a query which looks for a statement and then adds it if it is not found. + addDuringQueryExec(conn, uri, RDF.TYPE, vf.createURI("os:class/Clazz")); + // now try to export the statements. + final RepositoryResult<Statement> stats = conn.getStatements(null, null, null, false); + try { + // materialize the newly added statement. + stats.next(); + } catch (RuntimeException e) { + fail(e.getLocalizedMessage(), e); // With Bigdata this fails + } finally { + stats.close(); + } + conn.rollback(); // discard the result (or commit, but do something to avoid a logged warning from Sesame). + } finally { + conn.close(); + } + } finally { + repo.shutDown(); + } + } + + private void addDuringQueryExec(final RepositoryConnection conn, + final Resource subj, final URI pred, final Value obj, + final Resource... ctx) throws RepositoryException, + MalformedQueryException, QueryEvaluationException { + final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, + "select distinct ?s ?p ?o where{?s ?p ?t . ?t <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o }" + ); + tq.setBinding("s", subj); + tq.setBinding("p", pred); + tq.setBinding("o", obj); + final TupleQueryResult tqr = tq.evaluate(); + try { + if (!tqr.hasNext()) { + conn.add(subj, pred, obj, ctx); + } + } finally { + tqr.close(); + } + } +} Modified: branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java =================================================================== --- branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2011-07-12 12:21:08 UTC (rev 4889) +++ branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -42,6 +42,7 @@ import org.openrdf.model.impl.BooleanLiteralImpl; import com.bigdata.cache.WeakValueCache; +import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.lexicon.LexiconRelation; import com.bigdata.util.CanonicalFactory; @@ -456,9 +457,21 @@ if (v instanceof BigdataValueImpl && ((BigdataValueImpl) v).getValueFactory() == this) { - // a value from the same value factory. - return (BigdataValue) v; + final BigdataValueImpl v1 = (BigdataValueImpl) v; + final IV<?, ?> iv = v1.getIV(); + + if (iv == null || !iv.isNullIV()) { + + /* + * A value from the same value factory whose IV is either + * unknown or defined (but not a NullIV or DummyIV). + */ + + return (BigdataValue) v; + + } + } if (v instanceof BooleanLiteralImpl) { Modified: branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java =================================================================== --- branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java 2011-07-12 12:21:08 UTC (rev 4889) +++ branches/TERMS_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/model/TestFactory.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -36,7 +36,11 @@ import org.openrdf.model.URI; import org.openrdf.model.ValueFactory; +import com.bigdata.rdf.internal.IV; +import com.bigdata.rdf.internal.TermId; +import com.bigdata.rdf.internal.VTE; import com.bigdata.rdf.internal.XSD; +import com.sun.jdi.Value; /** * Unit tests for {@link BigdataValueFactoryImpl}. @@ -126,4 +130,32 @@ } + /** + * Unit test verifies that a new {@link BigdataValue} instance is returned + * when {@link BigdataValueFactory#asValue(org.openrdf.model.Value)} is + * invoked with a {@link BigdataValue} whose {@link IV} is a "dummmy" IV + * (aka a "mock" IV). A "dummy" or "mock" {@link IV} is an {@link IV} which + * stands in for a "null" and is used to hold the place for an RDF + * {@link Value} which is not known to the database. + * + * @see https://sourceforge.net/apps/trac/bigdata/ticket/348 + */ + public void test_asValue_mockIV() { + + final BigdataValue v1 = vf.createURI("http://www.bigdata.com"); + + final BigdataValue v2 = vf.asValue(v1); + + v1.setIV(TermId.mockIV(VTE.URI)); + + final BigdataValue v3 = vf.asValue(v1); + + // same BigdataValue + assertTrue(v2 == v1); + + // distinct BigdataValue + assertTrue(v3 != v1); + + } + } Modified: branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java =================================================================== --- branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-07-12 12:21:08 UTC (rev 4889) +++ branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestBigdataSailWithQuads.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -119,6 +119,7 @@ suite.addTestSuite(com.bigdata.rdf.sail.TestTicket275.class); suite.addTestSuite(com.bigdata.rdf.sail.TestTicket276.class); + suite.addTestSuite(com.bigdata.rdf.sail.TestTicket348.class); suite.addTestSuite(com.bigdata.rdf.sail.DavidsTestBOps.class); Added: branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java =================================================================== --- branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java (rev 0) +++ branches/TERMS_REFACTOR_BRANCH/bigdata-sails/src/test/com/bigdata/rdf/sail/TestTicket348.java 2011-07-12 14:22:46 UTC (rev 4890) @@ -0,0 +1,141 @@ +/** +Copyright (C) SYSTAP, LLC 2011. 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 + */ + +package com.bigdata.rdf.sail; + +import java.io.IOException; + +import org.openrdf.model.Resource; +import org.openrdf.model.Statement; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.ValueFactory; +import org.openrdf.model.vocabulary.RDF; +import org.openrdf.query.MalformedQueryException; +import org.openrdf.query.QueryEvaluationException; +import org.openrdf.query.QueryLanguage; +import org.openrdf.query.TupleQuery; +import org.openrdf.query.TupleQueryResult; +import org.openrdf.repository.RepositoryConnection; +import org.openrdf.repository.RepositoryException; +import org.openrdf.repository.RepositoryResult; +import org.openrdf.repository.sail.SailRepository; +import org.openrdf.rio.RDFHandlerException; +import org.openrdf.rio.RDFParseException; +import org.openrdf.sail.memory.MemoryStore; + +/** + * Unit test template for use in submission of bugs. + * <p> + * This test case will delegate to an underlying backing store. You can specify + * this store via a JVM property as follows: + * <code>-DtestClass=com.bigdata.rdf.sail.TestBigdataSailWithQuads</code> + * <p> + * There are three possible configurations for the testClass: + * <ul> + * <li>com.bigdata.rdf.sail.TestBigdataSailWithQuads (quads mode)</li> + * <li>com.bigdata.rdf.sail.TestBigdataSailWithoutSids (triples mode)</li> + * <li>com.bigdata.rdf.sail.TestBigdataSailWithSids (SIDs mode)</li> + * </ul> + * <p> + * The default for triples and SIDs mode is for inference with truth maintenance + * to be on. If you would like to turn off inference, make sure to do so in + * {@link #getProperties()}. + * + * @author <a href="mailto:mrp...@us...">Mike Personick</a> + * @version $Id$ + * @see https://sourceforge.net/apps/trac/bigdata/ticket/348 + */ +public class TestTicket348 extends QuadsTestCase { + + public TestTicket348() { + } + + public TestTicket348(String arg0) { + super(arg0); + } + + public void testBug() throws Exception { + // try with Sesame MemoryStore: + executeTest(new SailRepository(new MemoryStore())); + + // try with Bigdata: + try { + executeTest(new BigdataSailRepository(getSail())); + } finally { + getSail().__tearDownUnitTest(); + } + } + + private void executeTest(final SailRepository repo) + throws RepositoryException, MalformedQueryException, + QueryEvaluationException, RDFParseException, RDFHandlerException, + IOException { + try { + repo.initialize(); + final RepositoryConnection conn = repo.getConnection(); + try { + conn.setAutoCommit(false); + final ValueFactory vf = conn.getValueFactory(); + final URI uri = vf.createURI("os:/elem/example"); + // run a query which looks for a statement and then adds it if it is not found. + addDuringQueryExec(conn, uri, RDF.TYPE, vf.createURI("os:class/Clazz")); + // now try to export the statements. + final RepositoryResult<Statement> stats = conn.getStatements(null, null, null, false); + try { + // materialize the newly added statement. + stats.next(); + } catch (RuntimeException e) { + fail(e.getLocalizedMessage(), e); // With Bigdata this fails + } finally { + stats.close(); + } + conn.rollback(); // discard the result (or commit, but do something to avoid a logged warning from Sesame). + } finally { + conn.close(); + } + } finally { + repo.shutDown(); + } + } + + private void addDuringQueryExec(final RepositoryConnection conn, + final Resource subj, final URI pred, final Value obj, + final Resource... ctx) throws RepositoryException, + MalformedQueryException, QueryEvaluationException { + final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, + "select distinct ?s ?p ?o where{?s ?p ?t . ?t <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o }" + ); + tq.setBinding("s", subj); + tq.setBinding("p", pred); + tq.setBinding("o", obj); + final TupleQueryResult tqr = tq.evaluate(); + try { + if (!tqr.hasNext()) { + conn.add(subj, pred, obj, ctx); + } + } finally { + tqr.close(); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |