SPARQL Integration tests with SolRDF

SPARQL Integration tests with SolRDF

In 2014 I got a chance to give a contribution to a great project, CumulusRDF, an RDF store on a cloud-based architecture. The project Integration Test Suite was definitely a challenging task.

I used JUnit for running some examples coming from Learning SPARQL by Bob DuCharme (O’Reilly, 2013). Both O’Reilly and the Author (BTW, thanks a lot) gave me permission to do that in the project.

So, when I set up the first prototype of SolRDF, I wondered how I could create a complete (integration) test suite for doing more or less the same thing…and I came to the obvious conclusion that something of that work could be reused.

Something had to be changed. That is mainly because CumulusRDF uses Sesame as the underlying RDF framework, while SolRDF uses Apache Jena…in the end, it was a minor change…they are both valid, easy, and powerful.

So, in LearningSPARQL_ITCase we have:

  • a setup method for loading the example data;
  • a teardown method for cleaning up the store;

The example data is provided, on the LearningSPARQL website, in several files. Each file can contain a small dataset or a query, or an expected result (in tabular format). Returning to the test suite, the flow should load the small dataset, X, run the query Y and verify the results, Z.

Although in a previous post, we described how to load a sample dataset in SolRDF, this is something that you can do from the command line and not in a JUnit test. Instead, using Jena, we can automatize the data loading in SolRDF using these few lines.

Great, data has been loaded! In another post I will explain what I did, in SolRDF, for supporting the SPARQL 1.1 Graph Store HTTP Protocol.

It’s time to run some query in order to assert and check the corresponding results. As you can see the tests execute the same query twice: the first is against a memory model, the second towards SolRDF. In this way, assuming the Jena memory model behaviour as a ground truth, each test will be able to check and compare results coming from SolRDF:

Last but not least, the RDF store needs to be cleared after each test. Although the Graph Store protocol would be very useful for such purpose, it cannot be implemented in Solr because some HTTP methods (i.e. PUT and DELETE) cannot be used in RequestHandlers: Solr allows those methods only for /schema and /config requests. So while a clean up could be easily done using something like this:

Or, in HTTP:

It’s not possible to implement it so the only remaining approach is a Solr plain way to do that:

That has nothing to do with RDF and with the Graph Store protocol, but for such purpose (specifically test-scoped) it sounds like a good compromise.

That’s all! I just merged all those stuff in the master so feel free to have a look. If you want to run the integration test suite you can do that from command line:

or in Eclipse, using the predefined Maven launch configuration 


Just right-click on that file e choose “Run as…”. After starting the suite, you can see these messages:

Share this post

Leave a Reply