use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testCancelInterruptsExternalSortAtStartOfIteration.
@Test(expected = QueryCancelledException.class)
public void testCancelInterruptsExternalSortAtStartOfIteration() {
iterator = new CallbackIterator(unsorted.iterator(), 25, null);
iterator.setCallback(() -> {
});
assertEquals(0, iterator.getReturnedElementCount());
Context context = new Context();
context.set(ARQ.spillToDiskThreshold, 10L);
ExecutionContext executionContext = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qIter = new QueryIterSort(iterator, comparator, executionContext);
try {
assertTrue(qIter.hasNext());
assertEquals(49, DataBagExaminer.countTemporaryFiles(qIter.db));
assertNotNull(qIter.next());
assertTrue(qIter.hasNext());
qIter.cancel();
// throws a QueryCancelledException
qIter.hasNext();
} finally {
// assertTrue(iterator.isCanceled()) ;
assertEquals(500, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testCleanAfterClose.
@Test
public void testCleanAfterClose() {
// Do nothing.
iterator.setCallback(() -> {
});
assertEquals(0, iterator.getReturnedElementCount());
Context context = new Context();
context.set(ARQ.spillToDiskThreshold, 10L);
ExecutionContext executionContext = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qIter = new QueryIterSort(iterator, comparator, executionContext);
try {
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.hasNext();
assertEquals(500, iterator.getReturnedElementCount());
assertEquals(49, DataBagExaminer.countTemporaryFiles(qIter.db));
} finally {
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testCleanAfterExhaustion.
@Test
public void testCleanAfterExhaustion() {
iterator.setCallback(() -> {
});
assertEquals(0, iterator.getReturnedElementCount());
Context context = new Context();
context.set(ARQ.spillToDiskThreshold, 10L);
ExecutionContext executionContext = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qIter = new QueryIterSort(iterator, comparator, executionContext);
// Usually qIter should be in a try/finally block, but we are testing the case that the user forgot to do that.
// As a failsafe, QueryIteratorBase should close it when the iterator is exhausted.
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.hasNext();
assertEquals(500, iterator.getReturnedElementCount());
assertEquals(49, DataBagExaminer.countTemporaryFiles(qIter.db));
while (qIter.hasNext()) qIter.next();
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.close();
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testTopNCloseClosesSource.
@Test
public void testTopNCloseClosesSource() {
long numItems = 3;
boolean distinct = false;
Context context = new Context();
ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterTopN tn = new QueryIterTopN(iterator, comparator, numItems, distinct, ec);
tn.close();
assertTrue(iterator.isClosed());
}
use of org.apache.jena.sparql.engine.ExecutionContext in project jena by apache.
the class TestQueryIterSort method testTopNExhaustionClosesSource.
@Test
public void testTopNExhaustionClosesSource() {
iterator.setCallback(() -> {
});
long numItems = 3;
boolean distinct = false;
Context context = new Context();
ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterTopN tn = new QueryIterTopN(iterator, comparator, numItems, distinct, ec);
while (tn.hasNext()) tn.next();
assertTrue(iterator.isClosed());
}
Aggregations