use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class StatementOutputFormatterTest method binaryResult.
@Test
public void binaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new BinaryResult(Side.LEFT, visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class StatementOutputFormatterTest method unaryResult.
@Test
public void unaryResult() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
bindingSet.addBinding("predicate", vf.createURI("urn:age"));
bindingSet.addBinding("object", vf.createLiteral(34));
final VisibilityBindingSet visBs = new VisibilityBindingSet(bindingSet, "a");
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final StatementOutputFormatter formatter = new StatementOutputFormatter();
formatter.init(context);
formatter.process("key", ProcessorResult.make(new UnaryResult(visBs)));
// Verify the mock was invoked with the expected output.
final VisibilityStatement expectedStmt = new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(34)), "a");
verify(context, times(1)).forward(eq("key"), eq(expectedStmt));
}
use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class RunQueryCommandIT method runQuery.
@Test
public void runQuery() throws Exception {
// Register a query with the Query Repository.
final StreamsQuery sQuery = queryRepo.add("SELECT * WHERE { ?person <urn:worksAt> ?business . }", true, false);
// Arguments that run the query we just registered with Rya Streams.
final String[] args = new String[] { "--ryaInstance", "" + ryaInstance, "--kafkaHostname", kafka.getKafkaHostname(), "--kafkaPort", kafka.getKafkaPort(), "--queryID", sQuery.getQueryId().toString(), "--zookeepers", kafka.getZookeeperServers() };
// Create a new Thread that runs the command.
final Thread commandThread = new Thread() {
@Override
public void run() {
final RunQueryCommand command = new RunQueryCommand();
try {
command.execute(args);
} catch (ArgumentsException | ExecutionException e) {
// Do nothing. Test will still fail because the expected results will be missing.
}
}
};
// Create the statements that will be loaded.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = new ArrayList<>();
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:worksAt"), vf.createURI("urn:BurgerJoint")), "a"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:worksAt"), vf.createURI("urn:TacoShop")), "a"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:worksAt"), vf.createURI("urn:TacoShop")), "a"));
// Create the expected results.
final List<VisibilityBindingSet> expected = new ArrayList<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("business", vf.createURI("urn:BurgerJoint"));
expected.add(new VisibilityBindingSet(bs, "a"));
bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Bob"));
bs.addBinding("business", vf.createURI("urn:TacoShop"));
expected.add(new VisibilityBindingSet(bs, "a"));
bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Charlie"));
bs.addBinding("business", vf.createURI("urn:TacoShop"));
expected.add(new VisibilityBindingSet(bs, "a"));
// Execute the test. This will result in a set of results that were read from the results topic.
final List<VisibilityBindingSet> results;
try {
// Wait for the program to start.
commandThread.start();
Thread.sleep(5000);
// Write some statements to the program.
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final LoadStatements loadStatements = new KafkaLoadStatements(statementsTopic, stmtProducer);
loadStatements.fromCollection(statements);
// Read the output of the streams program.
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, sQuery.getQueryId());
resultConsumer.subscribe(Lists.newArrayList(resultsTopic));
results = KafkaTestUtil.pollForResults(500, 6, 3, resultConsumer);
} finally {
// Tear down the test.
commandThread.interrupt();
commandThread.join(3000);
}
// Show the read results matched the expected ones.
assertEquals(expected, results);
}
use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class GeoFilterIT method showProcessorWorks.
@Test
public void showProcessorWorks() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
// Get the RDF model objects that will be used to build the query.
final String sparql = "PREFIX geo: <http://www.opengis.net/ont/geosparql#>\n" + "PREFIX geof: <" + GEO + ">\n" + "SELECT * \n" + "WHERE { \n" + " <urn:event1> geo:asWKT ?point .\n" + " FILTER(geof:sfWithin(?point, \"POLYGON((-3 -2, -3 2, 1 2, 1 -2, -3 -2))\"^^geo:wktLiteral)) " + "}";
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Create the statements that will be input into the query.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = getStatements();
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
final WKTWriter w = new WKTWriter();
bs.addBinding("point", vf.createLiteral(w.write(ZERO), GeoConstants.XMLSCHEMA_OGC_WKT));
expected.add(new VisibilityBindingSet(bs, "a"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class FilterProcessorIT method showProcessorWorks.
@Test
public void showProcessorWorks() throws Exception {
// Enumerate some topics that will be re-used
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
final String statementsTopic = KafkaTopics.statementsTopic(ryaInstance);
final String resultsTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
// Get the RDF model objects that will be used to build the query.
final String sparql = "SELECT * " + "WHERE { " + "FILTER(?age < 10)" + "?person <urn:age> ?age " + "}";
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Create the statements that will be input into the query.
final ValueFactory vf = new ValueFactoryImpl();
final List<VisibilityStatement> statements = new ArrayList<>();
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(11)), "a"));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Alice"), vf.createURI("urn:age"), vf.createLiteral(9)), "a"));
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("person", vf.createURI("urn:Alice"));
bs.addBinding("age", vf.createLiteral(9));
expected.add(new VisibilityBindingSet(bs, "a"));
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
Aggregations