use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class KafkaGetQueryResultStreamIT method fromStart.
@Test
public void fromStart() throws Exception {
// Create an ID for the query.
final String ryaInstance = UUID.randomUUID().toString();
final UUID queryId = UUID.randomUUID();
// Create a list of test VisibilityBindingSets.
final List<VisibilityBindingSet> original = new ArrayList<>();
final ValueFactory vf = new ValueFactoryImpl();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("urn:name", vf.createLiteral("Alice"));
original.add(new VisibilityBindingSet(bs, "a|b|c"));
bs = new MapBindingSet();
bs.addBinding("urn:name", vf.createLiteral("Bob"));
original.add(new VisibilityBindingSet(bs, "a"));
bs = new MapBindingSet();
bs.addBinding("urn:name", vf.createLiteral("Charlie"));
original.add(new VisibilityBindingSet(bs, "b|c"));
// Write some entries to the query result topic in Kafka.
try (final Producer<?, VisibilityBindingSet> producer = KafkaTestUtil.makeProducer(kafka, StringSerializer.class, VisibilityBindingSetSerializer.class)) {
final String resultTopic = KafkaTopics.queryResultsTopic(ryaInstance, queryId);
for (final VisibilityBindingSet visBs : original) {
producer.send(new ProducerRecord<>(resultTopic, visBs));
}
}
// Use the interactor that is being tested to read all of the visibility binding sets.
final GetQueryResultStream<VisibilityBindingSet> interactor = new KafkaGetQueryResultStream<>(kafka.getKafkaHostname(), kafka.getKafkaPort(), VisibilityBindingSetDeserializer.class);
final List<VisibilityBindingSet> read = pollForResults(500, 3, 3, interactor.fromStart(ryaInstance, queryId));
// Show the fetched binding sets match the original, as well as their order.
assertEquals(original, read);
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class StatementOutputFormatterTest method predicateWrongType.
@Test
public void predicateWrongType() {
// 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.createLiteral("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 never invoked.
verify(context, times(0)).forward(any(), any());
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class StatementOutputFormatterTest method missingPredicate.
@Test
public void missingPredicate() {
// Create the input binding set.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bindingSet = new MapBindingSet();
bindingSet.addBinding("subject", vf.createURI("urn:Alice"));
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 never invoked.
verify(context, times(0)).forward(any(), any());
}
use of org.apache.rya.api.model.VisibilityBindingSet 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));
}
use of org.apache.rya.api.model.VisibilityBindingSet in project incubator-rya by apache.
the class VisibilityBindingSetSerdeTest method serializeAndDeserialize.
@Test
public void serializeAndDeserialize() {
// Create the object that will be serialized.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("name", vf.createLiteral("alice"));
bs.addBinding("age", vf.createLiteral(37));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b|c");
// Serialize it.
try (final Serde<VisibilityBindingSet> serde = new VisibilityBindingSetSerde()) {
final byte[] bytes = serde.serializer().serialize("topic", original);
// Deserialize it.
final VisibilityBindingSet deserialized = serde.deserializer().deserialize("topic", bytes);
// Show the deserialized value matches the original.
assertEquals(original, deserialized);
}
}
Aggregations