use of org.apache.rya.streams.kafka.processors.ProcessorResult in project incubator-rya by apache.
the class MultiProjectionProcessorTest method showProjectionFunctionIsCalled.
@Test
public void showProjectionFunctionIsCalled() throws Exception {
// The SPARQL that will define the projection.
final MultiProjection multiProjection = RdfTestUtil.getMultiProjection("CONSTRUCT {" + "_:b a <urn:movementObservation> ; " + "<urn:location> ?location ; " + "<urn:direction> ?direction ; " + "}" + "WHERE {" + "?thing <urn:corner> ?location ." + "?thing <urn:compass> ?direction." + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet inputBs = new MapBindingSet();
inputBs.addBinding("location", vf.createURI("urn:corner1"));
inputBs.addBinding("direction", vf.createURI("urn:NW"));
final VisibilityBindingSet inputVisBs = new VisibilityBindingSet(inputBs, "a|b");
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
final String blankNodeId = UUID.randomUUID().toString();
final BNode blankNode = vf.createBNode(blankNodeId);
MapBindingSet expectedBs = new MapBindingSet();
expectedBs.addBinding("subject", blankNode);
expectedBs.addBinding("predicate", RDF.TYPE);
expectedBs.addBinding("object", vf.createURI("urn:movementObservation"));
expected.add(new VisibilityBindingSet(expectedBs, "a|b"));
expectedBs = new MapBindingSet();
expectedBs.addBinding("subject", blankNode);
expectedBs.addBinding("predicate", vf.createURI("urn:direction"));
expectedBs.addBinding("object", vf.createURI("urn:NW"));
expected.add(new VisibilityBindingSet(expectedBs, "a|b"));
expectedBs = new MapBindingSet();
expectedBs.addBinding("subject", blankNode);
expectedBs.addBinding("predicate", vf.createURI("urn:location"));
expectedBs.addBinding("object", vf.createURI("urn:corner1"));
expected.add(new VisibilityBindingSet(expectedBs, "a|b"));
// Mock the processor context that will be invoked.
final ProcessorContext context = mock(ProcessorContext.class);
// Run the test.
final MultiProjectionProcessor processor = new MultiProjectionProcessor(MultiProjectionEvaluator.make(multiProjection, () -> blankNodeId), result -> ProcessorResult.make(new UnaryResult(result)));
processor.init(context);
processor.process("key", ProcessorResult.make(new UnaryResult(inputVisBs)));
final ArgumentCaptor<ProcessorResult> results = ArgumentCaptor.forClass(ProcessorResult.class);
verify(context, times(3)).forward(any(), results.capture());
final Set<VisibilityBindingSet> resultBindingSets = results.getAllValues().stream().map(result -> {
return (result.getType() == ResultType.UNARY) ? result.getUnary().getResult() : result.getBinary().getResult();
}).collect(Collectors.toSet());
assertEquals(expected, resultBindingSets);
}
use of org.apache.rya.streams.kafka.processors.ProcessorResult in project incubator-rya by apache.
the class ProjectionProcessorTest method showProjectionFunctionIsCalled.
@Test
public void showProjectionFunctionIsCalled() throws Exception {
// A query whose projection does not change anything.
final Projection projection = RdfTestUtil.getProjection("SELECT (?person AS ?p) (?employee AS ?e) ?business " + "WHERE { " + "?person <urn:talksTo> ?employee . " + "?employee <urn:worksAt> ?business . " + "}");
// Create a Binding Set that contains the result of the WHERE clause.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet inputBs = new MapBindingSet();
inputBs.addBinding("person", vf.createURI("urn:Alice"));
inputBs.addBinding("employee", vf.createURI("urn:Bob"));
inputBs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet inputVisBs = new VisibilityBindingSet(inputBs, "a");
// The expected binding set changes the "person" binding name to "p" and "employee" to "e".
final MapBindingSet expectedBs = new MapBindingSet();
expectedBs.addBinding("p", vf.createURI("urn:Alice"));
expectedBs.addBinding("e", vf.createURI("urn:Bob"));
expectedBs.addBinding("business", vf.createURI("urn:TacoJoint"));
final VisibilityBindingSet expectedVisBs = new VisibilityBindingSet(expectedBs, "a");
// Show it resulted in the correct output BindingSet.
final ProcessorContext context = mock(ProcessorContext.class);
final ProjectionProcessor processor = new ProjectionProcessor(ProjectionEvaluator.make(projection), result -> ProcessorResult.make(new UnaryResult(result)));
processor.init(context);
processor.process("key", ProcessorResult.make(new UnaryResult(inputVisBs)));
// Verify the expected binding set was emitted.
final ProcessorResult expected = ProcessorResult.make(new UnaryResult(expectedVisBs));
verify(context, times(1)).forward(eq("key"), eq(expected));
}
Aggregations