Skip to content

Commit

Permalink
GH-4785: unit test for timeout / deadlock in FedX Join
Browse files Browse the repository at this point in the history
This commit provides a unit test that reproduces a deadlock scenario.
The issue is somewhere caused in the join with NUnion, and specifically
the union parts having relevant statements in multiple sources.

Note that the dataset is really small (42 triples, 40 relevant ones
contributing to the result)
  • Loading branch information
aschwarte10 committed Oct 31, 2023
1 parent 743673b commit d670bba
Showing 1 changed file with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.rdf4j.model.vocabulary.FOAF;
import org.eclipse.rdf4j.model.vocabulary.RDF;
import org.eclipse.rdf4j.model.vocabulary.RDFS;
import org.eclipse.rdf4j.model.vocabulary.SKOS;
import org.eclipse.rdf4j.query.BindingSet;
import org.eclipse.rdf4j.query.TupleQuery;
import org.eclipse.rdf4j.repository.Repository;
Expand Down Expand Up @@ -122,6 +123,76 @@ public void testWithLocalRepositoryManager() throws Exception {

}

@Test
public void testJoinWithNUnion() throws Exception {

int N_LEFT_SIZE = 20;

addNativeStore("repo1");
addNativeStore("repo2");

try (RepositoryConnection conn = repoManager.getRepository("repo1").getConnection()) {
for (int i = 0; i < N_LEFT_SIZE; i++) {
conn.add(Values.iri("http://example.com/p" + i), RDF.TYPE, FOAF.PERSON);
}
}

// add statements for the union
try (RepositoryConnection conn = repoManager.getRepository("repo1").getConnection()) {
for (int i = 0; i < N_LEFT_SIZE; i += 2) {
conn.add(Values.iri("http://example.com/p" + i), RDFS.LABEL, Values.literal("Person " + i));
}

// add dummy skos:prefLabel statement to avoid exclusive group
conn.add(Values.iri("http://example.com/subj1"), SKOS.PREF_LABEL, Values.literal("Subj1"));

}
try (RepositoryConnection conn = repoManager.getRepository("repo2").getConnection()) {
for (int i = 1; i < N_LEFT_SIZE; i += 2) {
conn.add(Values.iri("http://example.com/p" + i), SKOS.PREF_LABEL, Values.literal("Person " + i));
}

// add dummy rdfs:label statement to avoid exclusive group
conn.add(Values.iri("http://example.com/subj2"), RDFS.LABEL, Values.literal("Subj2"));
}

FedXConfig config = new FedXConfig();
config.withDebugQueryPlan(true);

FedXRepository repo = FedXFactory.newFederation()
.withResolvableEndpoint("repo1")
.withResolvableEndpoint("repo2")
.withRepositoryResolver(repoManager)
.withConfig(config)
.create();

try {
repo.init();
try (RepositoryConnection conn = repo.getConnection()) {
TupleQuery tq = conn
.prepareTupleQuery(
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
+ "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
+ "PREFIX skos: <http://www.w3.org/2004/02/skos/core#>\n"
+ "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
+ "SELECT * WHERE { "
+ " ?person a foaf:Person ."
+ " ?person rdfs:label | skos:prefLabel ?label ."
+ " }"
);

tq.setMaxExecutionTime(2);

List<BindingSet> res = Iterations.asList(tq.evaluate());
Assertions.assertEquals(N_LEFT_SIZE, res.size());

}
} finally {
repo.shutDown();
}

}

protected void addNativeStore(String repoId) throws Exception {

RepositoryImplConfig implConfig = new SailRepositoryConfig(new NativeStoreConfig());
Expand Down

0 comments on commit d670bba

Please sign in to comment.