This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch jena4 in repository https://gitbox.apache.org/repos/asf/jena.git
commit a52ebbd4e6a20a243b281085b1dabc99c9306c0f Author: Andy Seaborne <[email protected]> AuthorDate: Tue Nov 7 09:00:54 2023 +0000 GH-2076: Test case for Iterator.remove in GraphMem --- .../jena/rdf/model/test/AbstractTestPackage.java | 13 ++-- .../java/org/apache/jena/test/TestPackage.java | 3 + .../model/test => test/jena4}/TestRemoveBug.java | 70 ++++++++++++++++++---- .../graph-mem-broken-iterator-delete-01.ttl | 22 +++++++ 4 files changed, 89 insertions(+), 19 deletions(-) diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/test/AbstractTestPackage.java b/jena-core/src/test/java/org/apache/jena/rdf/model/test/AbstractTestPackage.java index de87d215e6..18341d1456 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/test/AbstractTestPackage.java +++ b/jena-core/src/test/java/org/apache/jena/rdf/model/test/AbstractTestPackage.java @@ -6,9 +6,9 @@ * 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. @@ -31,9 +31,9 @@ import org.apache.jena.shared.Lock ; /** * Collected test suite for the .model package. - * + * * This is the base class for TestPackage implementations. - * + * * Model developers should extend this class to implement the package test * suite. * See TestPackage for example of usage. @@ -44,7 +44,7 @@ public abstract class AbstractTestPackage extends TestSuite /** * Constructor. - * + * * @param suiteName * The name for this TestPackage * @param modelFactory @@ -119,7 +119,6 @@ public abstract class AbstractTestPackage extends TestSuite addTest(TestModelExtract.class, modelFactory); addTest(TestModelRead.class, modelFactory); addTestSuite(TestPropertyImpl.class); - addTest(TestRemoveBug.class, modelFactory); addTest(TestContainerConstructors.class, modelFactory); addTest(TestAltMethods.class, modelFactory); addTest(TestBagMethods.class, modelFactory); @@ -147,7 +146,7 @@ public abstract class AbstractTestPackage extends TestSuite * Adds a test to the test suite by looking for the standard test methods. * These are * methods that start with "test" and have no arguments. - * + * * @param testClass * @param constructorArgs * @throws SecurityException diff --git a/jena-core/src/test/java/org/apache/jena/test/TestPackage.java b/jena-core/src/test/java/org/apache/jena/test/TestPackage.java index c087851100..2c3322c96d 100644 --- a/jena-core/src/test/java/org/apache/jena/test/TestPackage.java +++ b/jena-core/src/test/java/org/apache/jena/test/TestPackage.java @@ -61,6 +61,9 @@ public class TestPackage extends TestCase { // Local TTL parser for tests - not fully compliant. addTest(ts, "Turtle", org.apache.jena.ttl_test.test.turtle.TurtleTestSuite.suite()) ; + // Jena4 reports + addTest(ts, "RemoveBug", org.apache.jena.test.jena4.TestRemoveBug.suite()); + return ts ; } diff --git a/jena-core/src/test/java/org/apache/jena/rdf/model/test/TestRemoveBug.java b/jena-core/src/test/java/org/apache/jena/test/jena4/TestRemoveBug.java similarity index 65% rename from jena-core/src/test/java/org/apache/jena/rdf/model/test/TestRemoveBug.java rename to jena-core/src/test/java/org/apache/jena/test/jena4/TestRemoveBug.java index 91c91b5fd2..c80489daca 100644 --- a/jena-core/src/test/java/org/apache/jena/rdf/model/test/TestRemoveBug.java +++ b/jena-core/src/test/java/org/apache/jena/test/jena4/TestRemoveBug.java @@ -6,9 +6,9 @@ * 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. @@ -16,26 +16,65 @@ * limitations under the License. */ -package org.apache.jena.rdf.model.test; +package org.apache.jena.test.jena4; + +import static org.junit.Assert.assertEquals; import java.io.StringReader; +import junit.framework.JUnit4TestAdapter; +import junit.framework.TestSuite; +import org.apache.jena.graph.Graph; +import org.apache.jena.graph.Triple; +import org.apache.jena.mem.GraphMem; import org.apache.jena.rdf.model.* ; -import org.apache.jena.rdf.model.test.helpers.TestingModelFactory ; +import org.apache.jena.rdf.model.impl.RDFReaderFImpl; +import org.apache.jena.test.X_RDFReaderF; +import org.apache.jena.util.iterator.ExtendedIterator; import org.junit.Assert; +import org.junit.Test; -public class TestRemoveBug extends AbstractModelTestBase +@SuppressWarnings("deprecation") +public class TestRemoveBug { + // Make test suite runnable on it's own. + static { RDFReaderFImpl.alternative(new X_RDFReaderF()); } - public TestRemoveBug( final TestingModelFactory modelFactory, - final String name ) - { - super(modelFactory, name); - } + public static TestSuite suite() { + TestSuite ts = new TestSuite(); + ts.setName("TestRemoveBug"); + ts.addTest(new JUnit4TestAdapter(TestRemoveBug.class)); + return ts; + } + + public TestRemoveBug(){ } - /** - * Test a bug case, intermittent only (about 1 in 50!) + @Test + public void testRemoveBug_GH2076() { + Model model = createModel(); + model.read("file:testing/reports/graph-mem-broken-iterator-delete-01.ttl", "TURTLE"); + Graph graph = model.getGraph(); + + long x1 = graph.size(); + ExtendedIterator<Triple> it = graph.find(); + try { + while (it.hasNext()) { + Triple t = it.next(); + it.remove(); + } + } finally { + it.close(); + } + long x2 = graph.size(); + assertEquals(0L, x2); + } + + /* + * This seems to be the same bug as testBug2. + * It is intermittent - it fails much less than 1 in 50. + * The test above is a deterministic failure. */ + //@Test public void testBug1() { final String src = "@prefix foaf: <http://xmlns.com/foaf/0.1/> .\n" @@ -98,4 +137,11 @@ public class TestRemoveBug extends AbstractModelTestBase ian.hasProperty(name)); } } + + private Model createModel() { + // Must be GraphMem + Graph graph = new GraphMem(); + Model model = ModelFactory.createModelForGraph(graph); + return model; + } } diff --git a/jena-core/testing/reports/graph-mem-broken-iterator-delete-01.ttl b/jena-core/testing/reports/graph-mem-broken-iterator-delete-01.ttl new file mode 100644 index 0000000000..004267899e --- /dev/null +++ b/jena-core/testing/reports/graph-mem-broken-iterator-delete-01.ttl @@ -0,0 +1,22 @@ +# graph-mem-broken-iterator-delete-01.ttl +# This dataset is an ordered dump of HashCommon.keys with jena-4.9.0 and jena-4.10.0 +# It creates a situation where clearing all data using iterator.remove() on the iterator returned by graph.find() fails. + +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#statusCode> "200"^^<http://www.w3.org/2001/XMLSchema#int> . +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#user> "-" . +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://www.w3.org/ns/prov#atTime> "2023-06-02T08:00:00Z"^^<http://www.w3.org/2001/XMLSchema#dateTime> . +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#logRecord> "8955735dbec9f8a013df85d57bac725b - - [02/Jun/2023 10:00:00 +0200] \"GET /sparql?&timeout=60000&query=CONSTRUCT+%7B+%3Fsubject+%3Fproperty+%3Fvalue%7D+WHERE+%7B++%3Fsubject+%3Fproperty+%3Fvalue.+%3Fsubject+a+%3Ftype+.+%3Fsubject+rdfs%3Alabel+%3Flabel++FILTER+%28%28+lang%28%3Flabel%29+%3D+%22%22+%7C%7C+langMatches%28lang%28%3Flabel%29%2C+%22en%22%29%29+%26%26+%3Fsubject+%3D+%3Chttp%3A%2F%2Fdbpedia.org%2Fresourc [...] +# null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#query> "CONSTRUCT { ?subject ?property ?value} WHERE { ?subject ?property ?value. ?subject a ?type . ?subject rdfs:label ?label FILTER (( lang(?label) = \"\" || langMatches(lang(?label), \"en\")) && ?subject = <http://dbpedia.org/resource/Lobbyist>) } ORDER BY ASC(?subject ?property ?value)" . +#, null, null, null, null, null, null, null, null, null, null, null, null, +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#sequenceId> "110723"^^<http://www.w3.org/2001/XMLSchema#long> . +#, null, null, null, null, null, null, null, null, null, +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#uri> "/sparql?&timeout=60000&query=CONSTRUCT+%7B+%3Fsubject+%3Fproperty+%3Fvalue%7D+WHERE+%7B++%3Fsubject+%3Fproperty+%3Fvalue.+%3Fsubject+a+%3Ftype+.+%3Fsubject+rdfs%3Alabel+%3Flabel++FILTER+%28%28+lang%28%3Flabel%29+%3D+%22%22+%7C%7C+langMatches%28lang%28%3Flabel%29%2C+%22en%22%29%29+%26%26+%3Fsubject+%3D+%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FLobbyist%3E%29+%7D+ORDER+BY+ASC%28%3Fsubject+%3Fproperty+%3Fvalue%29" . +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#verb> "GET" . +# , null, null, null, null, null, +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#protocol> "HTTP/1.1" . +# null, null, +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#numResponseBytes> "394"^^<http://www.w3.org/2001/XMLSchema#int> . +# , null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#hostHash> "RNxI06DRVty3nU8fTEvds_BV31N6xtLq0JclkZQMNLM" . +<_:50470aa7-9d2b-4695-be38-a96f6fc1d7c7> <http://lsq.aksw.org/vocab#endpoint> <http://dbpedia.org/sparql> . \ No newline at end of file
