use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class T_TxnDeadlockTest method test.
//@Test
public void test() {
final StoreConnection storeConnection = StoreConnection.make(Location.mem());
//ExecutorService executor = Executors.newCachedThreadPool() ; // Not seen blocking.
// 4 blocks maybe 1 in 4 times
// 8 blocks (quad core) 2 in 3 times.
ExecutorService executor = Executors.newFixedThreadPool(8);
final AtomicInteger nbQuadruplesAdded = new AtomicInteger();
final CountDownLatch doneSignal = new CountDownLatch(CONCURRENT_RANDOM_OPERATIONS);
for (int i = 0; i < CONCURRENT_RANDOM_OPERATIONS; i++) {
executor.execute(new Runnable() {
@Override
public void run() {
try {
if (numberGenerator.nextInt(2) == 0) {
DatasetGraphTxn txnGraph = storeConnection.begin(ReadWrite.WRITE);
txnGraph.add(new Quad(NodeFactory.createURI("http://jena-example.org/" + numberGenerator.nextInt()), NodeFactory.createURI("http://jena-example.org/" + numberGenerator.nextInt()), NodeFactory.createURI("http://jena-example.org/" + numberGenerator.nextInt()), NodeFactory.createURI("http://jena-example.org/" + numberGenerator.nextInt())));
txnGraph.commit();
txnGraph.end();
nbQuadruplesAdded.incrementAndGet();
} else {
DatasetGraphTxn txnGraph = storeConnection.begin(ReadWrite.READ);
txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
//Iterator<Quad> iter = txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
//Iter.count(iter) ; // Consume
txnGraph.end();
}
} finally {
doneSignal.countDown();
}
}
});
}
// shutdown is orderly so sync'ing up before the shutdown is nice but not needed.
try {
doneSignal.await();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
executor.shutdown();
}
DatasetGraphTxn txnGraph = storeConnection.begin(ReadWrite.READ);
Iterator<Quad> result = txnGraph.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY);
long count = 0;
while (result.hasNext()) {
result.next();
count++;
}
txnGraph.end();
StoreConnection.release(storeConnection.getLocation());
//System.out.println() ;
System.out.println("FINISHED");
// // This is unsafe - the quad adds may generate duplicates (ity's unlikly 4 random number reoccur but it's possible).
// Assert.assertEquals(count, nbQuadruplesAdded.get());
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class Iso method isomorphicQuads.
public static boolean isomorphicQuads(List<Quad> quads1, List<Quad> quads2, NodeIsomorphismMap isoMap) {
if (quads1.size() != quads2.size())
return false;
for (int i = 0; i < quads1.size(); i++) {
Quad q1 = quads1.get(i);
Quad q2 = quads2.get(i);
if (!quadIso(q1, q2, isoMap))
return false;
}
return true;
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestAPI method testARQConstructQuad_Duplicate_1.
// Allow duplicated quads in execConstructQuads()
@Test
public void testARQConstructQuad_Duplicate_1() {
String queryString = "CONSTRUCT { GRAPH ?g1 {?s ?p ?o} } WHERE { ?s ?p ?o. GRAPH ?g1 {?s1 ?p1 ?o1} }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Quad> ts = qExec.execConstructQuads();
long count = 0;
Quad expected = Quad.create(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
while (ts.hasNext()) {
count++;
Quad qd = ts.next();
assertEquals(expected, qd);
}
// 3 duplicated quads
assertEquals(3, count);
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestAPI method testARQConstructQuad_Prefix.
// Allow duplicated template quads in execConstructQuads()
@Test
public void testARQConstructQuad_Prefix() {
String queryString = "PREFIX : <http://example/ns#> CONSTRUCT { GRAPH :g1 { ?s :p ?o} } WHERE { ?s ?p ?o }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Quad> quads = qExec.execConstructQuads();
DatasetGraph result = DatasetGraphFactory.create();
long count = 0;
while (quads.hasNext()) {
count++;
Quad qd = quads.next();
result.add(qd);
}
DatasetGraph expected = DatasetGraphFactory.create();
expected.add(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
assertEquals(1, count);
assertTrue(IsoMatcher.isomorphic(expected, result));
}
use of org.apache.jena.sparql.core.Quad in project jena by apache.
the class TestAPI method testARQConstructQuad_Duplicate_3.
// Allow duplicated template quads in execConstructQuads()
@Test
public void testARQConstructQuad_Duplicate_3() {
String queryString = "CONSTRUCT { GRAPH ?g1 {?s ?p ?o} GRAPH ?g1 {?s ?p ?o} } WHERE { ?s ?p ?o. GRAPH ?g1 {?s1 ?p1 ?o1} }";
Query q = QueryFactory.create(queryString, Syntax.syntaxARQ);
QueryExecution qExec = QueryExecutionFactory.create(q, d);
Iterator<Quad> ts = qExec.execConstructQuads();
long count = 0;
Quad expected = Quad.create(g1.asNode(), s.asNode(), p.asNode(), o.asNode());
while (ts.hasNext()) {
count++;
Quad qd = ts.next();
assertEquals(expected, qd);
}
// 6 duplicated quads
assertEquals(6, count);
}
Aggregations