Skip to content

Commit

Permalink
Include test for no-cache option #371
Browse files Browse the repository at this point in the history
Test caching system #372
  • Loading branch information
luigi-asprino committed Sep 2, 2024
1 parent 9854be4 commit 80ad2af
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ private void createAuditGraph(DatasetGraph dg, Properties p, boolean b) {
graphNodes.add(q.getSubject());
});
for (Node g: graphNodes) {
dg.delete(nodeGraph, g, NodeFactory.createURI(Triplifier.FACADE_X_CACHED_GRAPH), NodeFactory.createLiteralByValue(false));
dg.add(nodeGraph, g, NodeFactory.createURI(Triplifier.FACADE_X_CACHED_GRAPH), NodeFactory.createLiteralByValue(true));
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,51 @@

package io.github.sparqlanything.it;

import com.sun.source.tree.AssertTree;
import io.github.sparqlanything.engine.FacadeX;
import org.apache.jena.query.*;
import org.apache.jena.sparql.engine.main.QC;
import org.junit.Assert;
import org.junit.Test;

public class CacheTest {

@Test
public void test1(){
public void testDefaultSetting(){
Dataset ds = DatasetFactory.createGeneral();
QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory);

String queryStr = "SELECT * { SERVICE <x-sparql-anything:content=abc,txt.split=b,audit=true> {GRAPH ?g { ?s ?p ?o} }}";
String queryStr = "SELECT ?o { SERVICE <x-sparql-anything:content=abc,txt.split=b,audit=true,strategy=0> {GRAPH <http://sparql.xyz/facade-x/data/audit> { ?s <http://sparql.xyz/facade-x/ns/cachedGraph> ?o} }}";
Query query = QueryFactory.create(queryStr);
System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query,ds).execSelect()));
// System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query,ds).execSelect()));
ResultSet rs1 = QueryExecutionFactory.create(query,ds).execSelect();
Assert.assertTrue(rs1.hasNext());
Assert.assertFalse(rs1.next().getLiteral("o").asLiteral().getBoolean());

ResultSet rs2 = QueryExecutionFactory.create(query,ds).execSelect();
Assert.assertTrue(rs2.hasNext());
Assert.assertTrue(rs2.next().getLiteral("o").asLiteral().getBoolean());


}


@Test
public void testNoCache(){
Dataset ds = DatasetFactory.createGeneral();
QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory);

String queryStr = "SELECT ?o { SERVICE <x-sparql-anything:content=abc,txt.split=b,audit=true,strategy=0,no-cache=true> {GRAPH <http://sparql.xyz/facade-x/data/audit> { ?s <http://sparql.xyz/facade-x/ns/cachedGraph> ?o} }}";
Query query = QueryFactory.create(queryStr);
// System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query,ds).execSelect()));
ResultSet rs1 = QueryExecutionFactory.create(query,ds).execSelect();
Assert.assertTrue(rs1.hasNext());
Assert.assertFalse(rs1.next().getLiteral("o").asLiteral().getBoolean());

ResultSet rs2 = QueryExecutionFactory.create(query,ds).execSelect();
Assert.assertTrue(rs2.hasNext());
Assert.assertFalse(rs2.next().getLiteral("o").asLiteral().getBoolean());

System.err.println("--- new exec ---");
System.out.println(ResultSetFormatter.asText(QueryExecutionFactory.create(query,ds).execSelect()));

}
}

0 comments on commit 80ad2af

Please sign in to comment.