use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class VisibilityBindingSetKafkaIT method readAndWrite.
@Test
public void readAndWrite() throws Exception {
// Create the object that will be written to the topic.
final ValueFactory vf = new ValueFactoryImpl();
final MapBindingSet bs = new MapBindingSet();
bs.addBinding("urn:name", vf.createURI("urn:alice"));
bs.addBinding("urn:age", vf.createLiteral(32));
final VisibilityBindingSet original = new VisibilityBindingSet(bs, "a|b|c");
// Write a VisibilityBindingSet to the test topic.
try (Producer<String, VisibilityBindingSet> producer = KafkaTestUtil.makeProducer(kafka, StringSerializer.class, VisibilityBindingSetSerializer.class)) {
producer.send(new ProducerRecord<String, VisibilityBindingSet>(kafka.getKafkaTopicName(), original));
}
// Read a VisibilityBindingSet from the test topic.
try (Consumer<String, VisibilityBindingSet> consumer = KafkaTestUtil.fromStartConsumer(kafka, StringDeserializer.class, VisibilityBindingSetDeserializer.class)) {
// Register the topic.
consumer.subscribe(Arrays.asList(kafka.getKafkaTopicName()));
// Poll for the result.
final List<VisibilityBindingSet> results = KafkaTestUtil.pollForResults(500, 6, 1, consumer);
// Show the written statement matches the read one.
final VisibilityBindingSet read = results.iterator().next();
assertEquals(original, read);
}
}
use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class VisibilityStatementKafkaIT method readAndWrite.
@Test
public void readAndWrite() throws Exception {
// Create the object that will be written to the topic.
final ValueFactory vf = new ValueFactoryImpl();
final VisibilityStatement original = new VisibilityStatement(vf.createStatement(vf.createURI("urn:alice"), vf.createURI("urn:age"), vf.createLiteral(32), vf.createURI("urn:context")), "a|b|c");
// Write a VisibilityStatement to the test topic.
try (Producer<String, VisibilityStatement> producer = KafkaTestUtil.makeProducer(kafka, StringSerializer.class, VisibilityStatementSerializer.class)) {
producer.send(new ProducerRecord<String, VisibilityStatement>(kafka.getKafkaTopicName(), original));
}
// Read a VisibilityStatement from the test topic.
try (Consumer<String, VisibilityStatement> consumer = KafkaTestUtil.fromStartConsumer(kafka, StringDeserializer.class, VisibilityStatementDeserializer.class)) {
// Register the topic.
consumer.subscribe(Arrays.asList(kafka.getKafkaTopicName()));
// Poll for the result.
final List<VisibilityStatement> results = KafkaTestUtil.pollForResults(500, 6, 1, consumer);
// Show the written statement matches the read one.
final VisibilityStatement read = results.iterator().next();
assertEquals(original, read);
}
}
use of org.openrdf.model.impl.ValueFactoryImpl in project incubator-rya by apache.
the class AggregationProcessorIT method average.
@Test
public void average() throws Exception {
// A query that figures out the average age across all people.
final String sparql = "SELECT (avg(?age) as ?avgAge) " + "WHERE { " + "?person <urn:age> ?age " + "}";
// 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:Alice"), vf.createURI("urn:age"), vf.createLiteral(3)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(7)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:age"), vf.createLiteral(2)), ""));
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("avgAge", vf.createLiteral("3", XMLSchema.DECIMAL));
expected.add(new VisibilityBindingSet(bs, ""));
bs = new MapBindingSet();
bs.addBinding("avgAge", vf.createLiteral("5", XMLSchema.DECIMAL));
expected.add(new VisibilityBindingSet(bs, ""));
bs = new MapBindingSet();
bs.addBinding("avgAge", vf.createLiteral("4", XMLSchema.DECIMAL));
expected.add(new VisibilityBindingSet(bs, ""));
// 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);
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// 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 AggregationProcessorIT method max.
@Test
public void max() throws Exception {
// A query that figures out what the oldest age is across all people.
final String sparql = "SELECT (max(?age) as ?oldest) " + "WHERE { " + "?person <urn:age> ?age " + "}";
// 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:Alice"), vf.createURI("urn:age"), vf.createLiteral(13)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(14)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:age"), vf.createLiteral(7)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:David"), vf.createURI("urn:age"), vf.createLiteral(5)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Eve"), vf.createURI("urn:age"), vf.createLiteral(25)), ""));
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("oldest", vf.createLiteral(13));
expected.add(new VisibilityBindingSet(bs, ""));
bs = new MapBindingSet();
bs.addBinding("oldest", vf.createLiteral(14));
expected.add(new VisibilityBindingSet(bs, ""));
bs = new MapBindingSet();
bs.addBinding("oldest", vf.createLiteral(25));
expected.add(new VisibilityBindingSet(bs, ""));
// 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);
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// 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 AggregationProcessorIT method min.
@Test
public void min() throws Exception {
// A query that figures out what the youngest age is across all people.
final String sparql = "SELECT (min(?age) as ?youngest) " + "WHERE { " + "?person <urn:age> ?age " + "}";
// 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:Alice"), vf.createURI("urn:age"), vf.createLiteral(13)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Bob"), vf.createURI("urn:age"), vf.createLiteral(14)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Charlie"), vf.createURI("urn:age"), vf.createLiteral(7)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:David"), vf.createURI("urn:age"), vf.createLiteral(5)), ""));
statements.add(new VisibilityStatement(vf.createStatement(vf.createURI("urn:Eve"), vf.createURI("urn:age"), vf.createLiteral(25)), ""));
// Make the expected results.
final Set<VisibilityBindingSet> expected = new HashSet<>();
MapBindingSet bs = new MapBindingSet();
bs.addBinding("youngest", vf.createLiteral(13));
expected.add(new VisibilityBindingSet(bs, ""));
bs = new MapBindingSet();
bs.addBinding("youngest", vf.createLiteral(7));
expected.add(new VisibilityBindingSet(bs, ""));
bs = new MapBindingSet();
bs.addBinding("youngest", vf.createLiteral(5));
expected.add(new VisibilityBindingSet(bs, ""));
// 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);
// Setup a topology.
final TopologyBuilder builder = new TopologyFactory().build(sparql, statementsTopic, resultsTopic, new RandomUUIDFactory());
// Run the test.
RyaStreamsTestUtil.runStreamProcessingTest(kafka, statementsTopic, resultsTopic, builder, statements, expected, VisibilityBindingSetDeserializer.class);
}
Aggregations