use of org.apache.jena.sparql.engine.iterator.QueryIterSort in project jena by apache.
the class TestQueryIterSort method testCancelInterruptsExternalSortAfterStartingIteration.
@Test(expected = QueryCancelledException.class)
public void testCancelInterruptsExternalSortAfterStartingIteration() {
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));
// throws a QueryCancelledException
qIter.hasNext();
} catch (QueryCancelledException e) {
// expected
assertEquals(26, iterator.getReturnedElementCount());
// This is zero because QueryIteratorBase will call close() before throwing the QueryCancelledException.
// It does this as a failsafe in case the user doesn't close the QueryIterator themselves.
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
throw e;
} finally {
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
use of org.apache.jena.sparql.engine.iterator.QueryIterSort in project jena by apache.
the class TestQueryIterSort method testCloseClosesSourceIterator.
@Test
public void testCloseClosesSourceIterator() {
Context context = new Context();
ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qis = new QueryIterSort(iterator, comparator, ec);
qis.close();
assertTrue("source iterator should have been closed", iterator.isClosed());
}
use of org.apache.jena.sparql.engine.iterator.QueryIterSort in project jena by apache.
the class TestQueryIterSort method testCancelInterruptsInitialisation.
@Test(expected = QueryCancelledException.class)
public void testCancelInterruptsInitialisation() {
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.cancel();
// throws a QueryCancelledException
qIter.hasNext();
} finally {
assertTrue(iterator.isCanceled());
assertEquals(0, iterator.getReturnedElementCount());
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
qIter.close();
}
assertEquals(0, DataBagExaminer.countTemporaryFiles(qIter.db));
}
use of org.apache.jena.sparql.engine.iterator.QueryIterSort in project jena by apache.
the class TestQueryIterSort method testExhaustionClosesSourceIterator.
@Test
public void testExhaustionClosesSourceIterator() {
iterator.setCallback(() -> {
});
Context context = new Context();
ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
QueryIterSort qis = new QueryIterSort(iterator, comparator, ec);
while (qis.hasNext()) qis.next();
assertTrue("source iterator should have been closed", iterator.isClosed());
}
use of org.apache.jena.sparql.engine.iterator.QueryIterSort 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();
}
Aggregations