Search in sources :

Example 11 with SailConnection

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();
    }
}
Also used : HashMap(java.util.HashMap) Statement(org.eclipse.rdf4j.model.Statement) ValueFactory(org.eclipse.rdf4j.model.ValueFactory) SimpleValueFactory(org.eclipse.rdf4j.model.impl.SimpleValueFactory) SailException(org.eclipse.rdf4j.sail.SailException) SinkRecord(org.apache.kafka.connect.sink.SinkRecord) SailConnection(org.eclipse.rdf4j.sail.SailConnection) Sail(org.eclipse.rdf4j.sail.Sail) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with SailConnection

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();
}
Also used : SailConnection(org.eclipse.rdf4j.sail.SailConnection) ValueFactory(org.eclipse.rdf4j.model.ValueFactory)

Aggregations

SailConnection (org.eclipse.rdf4j.sail.SailConnection)12 Sail (org.eclipse.rdf4j.sail.Sail)11 ValueFactory (org.eclipse.rdf4j.model.ValueFactory)9 Test (org.junit.Test)7 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)5 RyaClient (org.apache.rya.api.client.RyaClient)5 Statement (org.eclipse.rdf4j.model.Statement)5 SailException (org.eclipse.rdf4j.sail.SailException)5 HashSet (java.util.HashSet)4 HashMap (java.util.HashMap)3 SecurityOperations (org.apache.accumulo.core.client.admin.SecurityOperations)3 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)3 SinkRecord (org.apache.kafka.connect.sink.SinkRecord)3 PrecomputedJoinStorage (org.apache.rya.indexing.pcj.storage.PrecomputedJoinStorage)3 SimpleValueFactory (org.eclipse.rdf4j.model.impl.SimpleValueFactory)3 QueryEvaluationException (org.eclipse.rdf4j.query.QueryEvaluationException)3 ArrayList (java.util.ArrayList)2 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)2 RyaClientException (org.apache.rya.api.client.RyaClientException)2 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)2