use of org.apache.rya.indexing.pcj.fluo.app.query.StatementPatternIdCache in project incubator-rya by apache.
the class StatementPatternIdCacheIT method statementPatternIdCacheTest.
/**
* Ensure streamed matches are included in the result.
*/
@Test
public void statementPatternIdCacheTest() throws Exception {
// A query that finds people who talk to Eve and work at Chipotle.
final String sparql1 = "SELECT ?x WHERE { " + "?x <urn:pred1> <urn:obj1>. " + "?x <urn:pred2> <urn:obj2>." + "}";
final String sparql2 = "SELECT ?x WHERE { " + "?x <urn:pred3> <urn:obj3>. " + "?x <urn:pred4> <urn:obj4>." + "}";
try (FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) {
String pcjId = FluoQueryUtils.createNewPcjId();
// Tell the Fluo app to maintain the PCJ.
FluoQuery query1 = new CreateFluoPcj().createPcj(pcjId, sparql1, new HashSet<>(), fluoClient);
Set<String> spIds1 = new HashSet<>();
for (StatementPatternMetadata metadata : query1.getStatementPatternMetadata()) {
spIds1.add(metadata.getNodeId());
}
StatementPatternIdCache cache = new StatementPatternIdCache();
assertEquals(spIds1, cache.getStatementPatternIds(fluoClient.newTransaction()));
FluoQuery query2 = new CreateFluoPcj().createPcj(pcjId, sparql2, new HashSet<>(), fluoClient);
Set<String> spIds2 = new HashSet<>();
for (StatementPatternMetadata metadata : query2.getStatementPatternMetadata()) {
spIds2.add(metadata.getNodeId());
}
assertEquals(Sets.union(spIds1, spIds2), cache.getStatementPatternIds(fluoClient.newTransaction()));
}
}
Aggregations