Search in sources :

Example 6 with Context

use of org.apache.jena.sparql.util.Context 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 7 with Context

use of org.apache.jena.sparql.util.Context 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 8 with Context

use of org.apache.jena.sparql.util.Context in project jena by apache.

the class TestService method query_service_context_application_03.

@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_03() {
    // This test requires us to set some timeouts for the service
    Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap == null) {
        ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
        serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    }
    if (serviceContextMap.get(SERVICE) == null) {
        serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
    }
    Context serviceContext = serviceContextMap.get(SERVICE);
    try {
        serviceContext.put(Service.queryTimeout, "10");
        Query q = QueryFactory.create("ASK { }");
        QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
        Assert.assertNotNull(engine);
        // Check that no settings were changed
        Assert.assertEquals(-1, engine.getTimeout1());
        Assert.assertEquals(10, engine.getTimeout2());
        Assert.assertTrue(engine.getAllowCompression());
        Assert.assertNull(engine.getClient());
    } finally {
        serviceContext.remove(Service.queryTimeout);
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 9 with Context

use of org.apache.jena.sparql.util.Context in project jena by apache.

the class TestService method testStringTimeout2.

@Test
public void testStringTimeout2() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(Triple.ANY);
    Node serviceNode = NodeFactory.createURI(SERVICE);
    OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
    Context context = new Context();
    ARQ.setNormalMode(context);
    context.set(Service.queryTimeout, "10,10000");
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OpService(org.apache.jena.sparql.algebra.op.OpService) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Example 10 with Context

use of org.apache.jena.sparql.util.Context in project jena by apache.

the class TestService method testNumericTimeout.

@Test
public void testNumericTimeout() {
    BasicPattern basicPattern = new BasicPattern();
    basicPattern.add(Triple.ANY);
    Node serviceNode = NodeFactory.createURI(SERVICE);
    OpService opService = new OpService(serviceNode, new OpBGP(basicPattern), false);
    Context context = new Context();
    ARQ.setNormalMode(context);
    context.set(Service.queryTimeout, 10);
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof ConnectTimeoutException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or ConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) Node(org.apache.jena.graph.Node) OpBGP(org.apache.jena.sparql.algebra.op.OpBGP) OpService(org.apache.jena.sparql.algebra.op.OpService) BasicPattern(org.apache.jena.sparql.core.BasicPattern) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) Test(org.junit.Test)

Aggregations

Context (org.apache.jena.sparql.util.Context)52 Test (org.junit.Test)36 ExecutionContext (org.apache.jena.sparql.engine.ExecutionContext)15 Map (java.util.Map)11 BaseTest (org.apache.jena.atlas.junit.BaseTest)11 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)11 HashMap (java.util.HashMap)10 QueryIterSort (org.apache.jena.sparql.engine.iterator.QueryIterSort)9 HttpClient (org.apache.http.client.HttpClient)7 QueryEngineHTTP (org.apache.jena.sparql.engine.http.QueryEngineHTTP)7 Query (org.apache.jena.query.Query)5 QueryCancelledException (org.apache.jena.query.QueryCancelledException)4 SocketException (java.net.SocketException)3 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 HttpContext (org.apache.http.protocol.HttpContext)3 JsonObject (org.apache.jena.atlas.json.JsonObject)3 JsonString (org.apache.jena.atlas.json.JsonString)3 Node (org.apache.jena.graph.Node)3 Model (org.apache.jena.rdf.model.Model)3 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)3