Search in sources :

Example 6 with QueryIterSort

use of org.apache.jena.sparql.engine.iterator.QueryIterSort 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));
}
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 7 with QueryIterSort

use of org.apache.jena.sparql.engine.iterator.QueryIterSort in project jena by apache.

the class TestQueryIterSort method testCancelClosesSourceIterator.

@Test
public void testCancelClosesSourceIterator() {
    Context context = new Context();
    ExecutionContext ec = new ExecutionContext(context, (Graph) null, (DatasetGraph) null, (OpExecutorFactory) null);
    QueryIterSort qis = new QueryIterSort(iterator, comparator, ec);
    try {
        while (qis.hasNext()) qis.next();
        fail("query should have been cancelled by trigger");
    } catch (QueryCancelledException q) {
        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) QueryCancelledException(org.apache.jena.query.QueryCancelledException) Test(org.junit.Test)

Example 8 with QueryIterSort

use of org.apache.jena.sparql.engine.iterator.QueryIterSort in project jena by apache.

the class TestQueryIterSort method testNoSpill.

@Test
public void testNoSpill() {
    iterator.setCallback(() -> {
    });
    //new Callback() { @Override
    //public void call() { /* do nothing */ } });
    assertEquals(0, iterator.getReturnedElementCount());
    Context context = new Context();
    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(0, DataBagExaminer.countTemporaryFiles(qIter.db));
    } finally {
        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)

Example 9 with QueryIterSort

use of org.apache.jena.sparql.engine.iterator.QueryIterSort 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));
}
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