Search in sources :

Example 26 with ExecutionContext

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

Example 27 with ExecutionContext

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

Example 28 with ExecutionContext

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

Example 29 with ExecutionContext

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

Example 30 with ExecutionContext

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

Aggregations

ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)40 Context (org.apache.jena.sparql.util.Context)19 Node (org.apache.jena.graph.Node)14 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)12 Test (org.junit.Test)12 Binding (org.apache.jena.sparql.engine.binding.Binding)11 Triple (org.apache.jena.graph.Triple)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9 Iterator (java.util.Iterator)8 Iter (org.apache.jena.atlas.iterator.Iter)8 Var (org.apache.jena.sparql.core.Var)8 Predicate (java.util.function.Predicate)7 Graph (org.apache.jena.graph.Graph)7 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)6 Function (java.util.function.Function)5 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)5 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Quad (org.apache.jena.sparql.core.Quad)5 Substitute (org.apache.jena.sparql.core.Substitute)5 BindingFactory (org.apache.jena.sparql.engine.binding.BindingFactory)5