use of org.eclipse.rdf4j.sail.SailConnection in project incubator-rya by apache.
the class RyaSinkTaskTest method singleRecord.
@Test
public void singleRecord() {
// Create the Statements that will be put by the task.
final ValueFactory vf = SimpleValueFactory.getInstance();
final Set<Statement> statements = Sets.newHashSet(vf.createStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:WorksAt"), vf.createIRI("urn:Taco Shop"), vf.createIRI("urn:graph1")), vf.createStatement(vf.createIRI("urn:Bob"), vf.createIRI("urn:TalksTo"), vf.createIRI("urn:Charlie"), vf.createIRI("urn:graph2")), vf.createStatement(vf.createIRI("urn:Eve"), vf.createIRI("urn:ListensTo"), vf.createIRI("urn:Alice"), vf.createIRI("urn:graph1")));
// Create the task that will be tested.
final InMemoryRyaSinkTask task = new InMemoryRyaSinkTask();
// Setup the properties that will be used to configure the task. We don't actually need to set anything
// here since we're always returning true for ryaInstanceExists(...) and use an in memory RDF store.
final Map<String, String> props = new HashMap<>();
try {
// Start the task.
task.start(props);
// Put the statements as a SinkRecord.
task.put(Collections.singleton(new SinkRecord("topic", 1, null, "key", null, statements, 0)));
// Flush the statements.
task.flush(new HashMap<>());
// Fetch the stored Statements to show they match the original set.
final Set<Statement> fetched = new HashSet<>();
final Sail sail = task.makeSail(props);
try (SailConnection conn = sail.getConnection();
CloseableIteration<? extends Statement, SailException> it = conn.getStatements(null, null, null, false)) {
while (it.hasNext()) {
fetched.add(it.next());
}
}
assertEquals(statements, fetched);
} finally {
// Stop the task.
task.stop();
}
}
use of org.eclipse.rdf4j.sail.SailConnection in project incubator-rya by apache.
the class QueryBenchmarkRunIT method loadTestStatements.
private static void loadTestStatements() throws Exception {
final ValueFactory vf = sail.getValueFactory();
final SailConnection sailConn = sail.getConnection();
sailConn.begin();
sailConn.addStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:Bob"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:Charlie"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:David"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:Eve"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:Frank"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:George"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:Hillary"), vf.createIRI("urn:likes"), vf.createIRI("urn:icecream"));
sailConn.addStatement(vf.createIRI("urn:Alice"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:blue"));
sailConn.addStatement(vf.createIRI("urn:Bob"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:blue"));
sailConn.addStatement(vf.createIRI("urn:Charlie"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:blue"));
sailConn.addStatement(vf.createIRI("urn:David"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:blue"));
sailConn.addStatement(vf.createIRI("urn:Eve"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:blue"));
sailConn.addStatement(vf.createIRI("urn:Frank"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:blue"));
sailConn.addStatement(vf.createIRI("urn:George"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:green"));
sailConn.addStatement(vf.createIRI("urn:Hillary"), vf.createIRI("urn:hasEyeColor"), vf.createIRI("urn:brown"));
sailConn.commit();
sailConn.close();
}
Aggregations