Search in sources :

Example 1 with HttpConnectTimeoutException

use of java.net.http.HttpConnectTimeoutException in project jena by apache.

the class TestServiceSetup method testStringTimeout.

@Test
public void testStringTimeout() {
    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.httpQueryTimeout, "10");
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof HttpConnectTimeoutException || thrown instanceof UnknownHostException) {
        // expected
        } else {
            Assert.fail(String.format("Expected SocketException or HttpConnectTimeoutException, instead got: %s %s", thrown.getClass().getName(), thrown.getMessage()));
        }
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) SocketException(java.net.SocketException) UnknownHostException(java.net.UnknownHostException) 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) HttpConnectTimeoutException(java.net.http.HttpConnectTimeoutException) Test(org.junit.Test)

Example 2 with HttpConnectTimeoutException

use of java.net.http.HttpConnectTimeoutException in project jena by apache.

the class TestServiceSetup 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.httpQueryTimeout, 10);
    try {
        Service.exec(opService, context);
        Assert.fail("Expected QueryExceptionHTTP");
    } catch (QueryExceptionHTTP expected) {
        Throwable thrown = expected.getCause();
        if (thrown instanceof SocketException || thrown instanceof HttpConnectTimeoutException || thrown instanceof UnknownHostException) {
        // 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) UnknownHostException(java.net.UnknownHostException) 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) HttpConnectTimeoutException(java.net.http.HttpConnectTimeoutException) Test(org.junit.Test)

Aggregations

SocketException (java.net.SocketException)2 UnknownHostException (java.net.UnknownHostException)2 HttpConnectTimeoutException (java.net.http.HttpConnectTimeoutException)2 Node (org.apache.jena.graph.Node)2 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)2 OpService (org.apache.jena.sparql.algebra.op.OpService)2 BasicPattern (org.apache.jena.sparql.core.BasicPattern)2 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)2 Context (org.apache.jena.sparql.util.Context)2 Test (org.junit.Test)2