Search in sources :

Example 1 with QueryIterSort

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));
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterSort(org.apache.jena.sparql.engine.iterator.QueryIterSort) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryCancelledException(org.apache.jena.query.QueryCancelledException) Test(org.junit.Test)

Example 2 with QueryIterSort

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());
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterSort(org.apache.jena.sparql.engine.iterator.QueryIterSort) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Example 3 with QueryIterSort

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));
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterSort(org.apache.jena.sparql.engine.iterator.QueryIterSort) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Example 4 with QueryIterSort

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());
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterSort(org.apache.jena.sparql.engine.iterator.QueryIterSort) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Example 5 with QueryIterSort

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();
}
Also used : Context(org.apache.jena.sparql.util.Context) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) QueryIterSort(org.apache.jena.sparql.engine.iterator.QueryIterSort) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Test(org.junit.Test)

Aggregations

ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)9 QueryIterSort (org.apache.jena.sparql.engine.iterator.QueryIterSort)9 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)9 Context (org.apache.jena.sparql.util.Context)9 Test (org.junit.Test)9 QueryCancelledException (org.apache.jena.query.QueryCancelledException)2