|
10 | 10 | *******************************************************************************/ |
11 | 11 | package org.eclipse.rdf4j.federated.evaluation; |
12 | 12 |
|
| 13 | +import java.util.Arrays; |
13 | 14 | import java.util.List; |
| 15 | +import java.util.Set; |
| 16 | +import java.util.stream.Collectors; |
14 | 17 |
|
15 | 18 | import org.eclipse.rdf4j.federated.SPARQLBaseTest; |
| 19 | +import org.eclipse.rdf4j.federated.cache.SourceSelectionCache; |
| 20 | +import org.eclipse.rdf4j.federated.cache.SourceSelectionCache.StatementSourceAssurance; |
| 21 | +import org.eclipse.rdf4j.federated.endpoint.Endpoint; |
| 22 | +import org.eclipse.rdf4j.federated.structures.SubQuery; |
| 23 | +import org.eclipse.rdf4j.model.util.Values; |
| 24 | +import org.eclipse.rdf4j.model.vocabulary.FOAF; |
| 25 | +import org.eclipse.rdf4j.model.vocabulary.OWL; |
| 26 | +import org.eclipse.rdf4j.model.vocabulary.RDF; |
| 27 | +import org.eclipse.rdf4j.query.TupleQuery; |
| 28 | +import org.eclipse.rdf4j.repository.Repository; |
| 29 | +import org.eclipse.rdf4j.repository.RepositoryConnection; |
16 | 30 | import org.junit.jupiter.api.Assertions; |
17 | 31 | import org.junit.jupiter.api.Test; |
18 | 32 |
|
@@ -46,4 +60,50 @@ public void testOptimize_SingleMember_Service() throws Exception { |
46 | 60 |
|
47 | 61 | Assertions.assertTrue(queryPlan.startsWith("QueryRoot")); |
48 | 62 | } |
| 63 | + |
| 64 | + @Test |
| 65 | + public void testSourceSelectionCache_setBindings() throws Exception { |
| 66 | + |
| 67 | + var bob = Values.iri("http://example.com/bob"); |
| 68 | + |
| 69 | + List<Endpoint> endpoints = prepareTest( |
| 70 | + Arrays.asList("/tests/basic/data_emptyStore.ttl", "/tests/basic/data_emptyStore.ttl")); |
| 71 | + |
| 72 | + Repository repo1 = getRepository(1); |
| 73 | + Repository repo2 = getRepository(2); |
| 74 | + |
| 75 | + String repo1Id = endpoints.get(0).getId(); |
| 76 | + |
| 77 | + try (RepositoryConnection con = repo1.getConnection()) { |
| 78 | + con.add(bob, RDF.TYPE, FOAF.PERSON); |
| 79 | + } |
| 80 | + |
| 81 | + try (RepositoryConnection con = repo2.getConnection()) { |
| 82 | + con.add(FOAF.PERSON, RDF.TYPE, OWL.CLASS); |
| 83 | + } |
| 84 | + |
| 85 | + Repository fedxRepo = fedxRule.getRepository(); |
| 86 | + |
| 87 | + fedxRule.enableDebug(); |
| 88 | + |
| 89 | + try (var conn = fedxRepo.getConnection()) { |
| 90 | + |
| 91 | + TupleQuery tq = conn.prepareTupleQuery("SELECT * WHERE { ?s a ?type }"); |
| 92 | + tq.setBinding("s", bob); |
| 93 | + |
| 94 | + try (var tqr = tq.evaluate()) { |
| 95 | + // just consume the result |
| 96 | + Assertions.assertEquals(Set.of(FOAF.PERSON), |
| 97 | + tqr.stream().map(bs -> bs.getValue("type")).collect(Collectors.toSet())); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + SourceSelectionCache cache = federationContext().getSourceSelectionCache(); |
| 102 | + |
| 103 | + var assurance = cache.getAssurance(new SubQuery(bob, RDF.TYPE, null), |
| 104 | + federationContext().getEndpointManager().getEndpoint(repo1Id)); |
| 105 | + |
| 106 | + // we expect that the source selection cache can assure statements |
| 107 | + Assertions.assertEquals(StatementSourceAssurance.HAS_REMOTE_STATEMENTS, assurance); |
| 108 | + } |
49 | 109 | } |
0 commit comments