use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class MongoDbRyaSailFactoryLoadFilesIT method testFileLoading.
@Test
public void testFileLoading() throws Exception {
log.info("Starting file loading test...");
final String query = "SELECT * WHERE { ?s ?p ?o . }";
final String deleteQuery = "DELETE WHERE { ?s ?p ?o . }";
for (final TestFile testFile : TestFileUtils.TEST_FILES) {
final String testFilePath = testFile.getPath();
final RDFFormat rdfFormat = RdfFormatUtils.forFileName(testFilePath, null);
log.info("Loading file \"" + testFilePath + "\" with RDFFormat: " + rdfFormat.getName());
try (final InputStream rdfContent = getClass().getResourceAsStream(testFilePath)) {
addTriples(ryaRepository, rdfContent, rdfFormat);
}
SailRepositoryConnection queryConn = null;
try {
log.info("Querying for triples in the repository from the " + rdfFormat.getName() + " file.");
queryConn = ryaRepository.getConnection();
final int count = performTupleQuery(query, queryConn);
assertEquals("Expected number of triples not found in: " + testFilePath, testFile.getExpectedCount(), count);
} finally {
closeQuietly(queryConn);
}
SailRepositoryConnection deleteConn = null;
try {
log.info("Deleting triples in the repository from the " + rdfFormat.getName() + " file.");
deleteConn = ryaRepository.getConnection();
final Update update = deleteConn.prepareUpdate(QueryLanguage.SPARQL, deleteQuery);
update.execute();
} finally {
closeQuietly(deleteConn);
}
}
log.info("File loading test finished.");
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class RyaMongoDbSailFactoryTest method testCreateMongoDbSail.
@Test
public void testCreateMongoDbSail() throws Exception {
Sail sail = null;
SailRepository repo = null;
SailRepositoryConnection conn = null;
try {
sail = RyaSailFactory.getInstance(conf);
repo = new SailRepository(sail);
conn = repo.getConnection();
} finally {
if (conn != null) {
conn.close();
}
if (repo != null) {
repo.shutDown();
}
if (sail != null) {
sail.shutDown();
}
}
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class RyaMongoDbSailFactoryTest method testAddStatement.
@Test
public void testAddStatement() throws Exception {
Sail sail = null;
SailRepository repo = null;
SailRepositoryConnection conn = null;
try {
sail = RyaSailFactory.getInstance(conf);
repo = new SailRepository(sail);
conn = repo.getConnection();
final ValueFactory vf = conn.getValueFactory();
final Statement s = vf.createStatement(vf.createIRI("u:a"), vf.createIRI("u:b"), vf.createIRI("u:c"));
assertFalse(conn.hasStatement(s, false));
conn.add(s);
Assert.assertTrue(conn.hasStatement(s, false));
} finally {
if (conn != null) {
conn.close();
}
if (repo != null) {
repo.shutDown();
}
if (sail != null) {
sail.shutDown();
}
}
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class RyaMongoDbSailFactoryTest method testReuseSail.
@Test
public void testReuseSail() throws Exception {
Sail sail = null;
SailRepository repo = null;
SailRepositoryConnection conn = null;
try {
sail = RyaSailFactory.getInstance(conf);
repo = new SailRepository(sail);
conn = repo.getConnection();
final ValueFactory vf = conn.getValueFactory();
final Statement s = vf.createStatement(vf.createIRI("u:a"), vf.createIRI("u:b"), vf.createIRI("u:c"));
assertFalse(conn.hasStatement(s, false));
conn.add(s);
Assert.assertTrue(conn.hasStatement(s, false));
conn.remove(s);
Assert.assertFalse(conn.hasStatement(s, false));
} finally {
if (conn != null) {
conn.close();
}
if (repo != null) {
repo.shutDown();
}
if (sail != null) {
sail.shutDown();
}
}
// Reuse Sail after shutdown
try {
sail = RyaSailFactory.getInstance(conf);
repo = new SailRepository(sail);
conn = repo.getConnection();
final ValueFactory vf = conn.getValueFactory();
final Statement s = vf.createStatement(vf.createIRI("u:a"), vf.createIRI("u:b"), vf.createIRI("u:c"));
assertFalse(conn.hasStatement(s, false));
conn.add(s);
Assert.assertTrue(conn.hasStatement(s, false));
} finally {
if (conn != null) {
conn.close();
}
if (repo != null) {
repo.shutDown();
}
if (sail != null) {
sail.shutDown();
}
}
}
use of org.eclipse.rdf4j.repository.sail.SailRepositoryConnection in project incubator-rya by apache.
the class MongoPcjIntegrationTest method testEvaluateOneIndex.
// TODO Fix this. It's been broken for awhile
@Ignore
@Test
public void testEvaluateOneIndex() throws Exception {
final Sail nonPcjSail = RyaSailFactory.getInstance(conf);
final MongoDBRdfConfiguration pcjConf = conf.clone();
pcjConf.setBoolean(ConfigUtils.USE_PCJ, true);
final Sail pcjSail = RyaSailFactory.getInstance(pcjConf);
final SailRepositoryConnection conn = new SailRepository(nonPcjSail).getConnection();
final SailRepositoryConnection pcjConn = new SailRepository(pcjSail).getConnection();
addPCJS(pcjConn);
try {
final IRI superclass = VF.createIRI("uri:superclass");
final IRI superclass2 = VF.createIRI("uri:superclass2");
conn.add(subclass, RDF.TYPE, superclass);
conn.add(subclass2, RDF.TYPE, superclass2);
conn.add(obj, RDFS.LABEL, VF.createLiteral("label"));
conn.add(obj2, RDFS.LABEL, VF.createLiteral("label2"));
final String indexSparqlString = //
"" + //
"SELECT ?dog ?pig ?duck " + //
"{" + //
" ?pig a ?dog . " + //
" ?pig <http://www.w3.org/2000/01/rdf-schema#label> ?duck " + //
"}";
final CountingResultHandler crh1 = new CountingResultHandler();
final CountingResultHandler crh2 = new CountingResultHandler();
PcjIntegrationTestingUtil.createAndPopulatePcj(conn, getMongoClient(), conf.getMongoDBName() + 1, conf.getRyaInstanceName(), indexSparqlString);
conn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh1);
PcjIntegrationTestingUtil.deleteCoreRyaTables(getMongoClient(), conf.getRyaInstanceName(), conf.getTriplesCollectionName());
pcjConn.prepareTupleQuery(QueryLanguage.SPARQL, indexSparqlString).evaluate(crh2);
assertEquals(crh1.count, crh2.count);
} finally {
conn.close();
pcjConn.close();
nonPcjSail.shutDown();
pcjSail.shutDown();
}
}
Aggregations