Search in sources :

Example 16 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern 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)

Example 17 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TestService 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.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)

Example 18 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class FmtTemplate method format.

@Override
public void format(Template template) {
    out.print("{");
    out.incIndent(INDENT);
    out.pad();
    List<Quad> quads = template.getQuads();
    for (Quad quad : quads) {
        BasicPattern bgp = new BasicPattern();
        bgp.add(quad.asTriple());
        out.newline();
        if (!Quad.defaultGraphNodeGenerated.equals(quad.getGraph())) {
            out.print("GRAPH");
            out.print(" ");
            out.print(slotToString(quad.getGraph()));
            out.print(" ");
            out.newline();
            out.incIndent(INDENT);
            out.pad();
            out.print("{");
            out.incIndent(INDENT);
            out.pad();
        }
        formatTriples(bgp);
        if (!Quad.defaultGraphNodeGenerated.equals(quad.getGraph())) {
            out.decIndent(INDENT);
            out.print("}");
            out.decIndent(INDENT);
        }
    }
    out.newline();
    out.decIndent(INDENT);
    out.print("}");
    out.newline();
}
Also used : Quad(org.apache.jena.sparql.core.Quad) BasicPattern(org.apache.jena.sparql.core.BasicPattern)

Example 19 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TestReorder method reorderIndexes1.

@Test
public void reorderIndexes1() {
    ReorderProc proc = new ReorderProcIndexes(new int[] { 0, 1 });
    BasicPattern bgp = bgp("(bgp (:x :p ?v) (:x :q ?w))");
    BasicPattern bgp2 = proc.reorder(bgp);
    assertEquals(bgp, bgp2);
}
Also used : BasicPattern(org.apache.jena.sparql.core.BasicPattern) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 20 with BasicPattern

use of org.apache.jena.sparql.core.BasicPattern in project jena by apache.

the class TestReorder method stats_dft_01.

@Test
public void stats_dft_01() {
    ReorderTransformation transform = ReorderLib.fixed();
    BasicPattern bgp = bgp("(bgp)");
    BasicPattern bgp2 = transform.reorder(bgp);
    assertEquals(bgp2, bgp);
}
Also used : BasicPattern(org.apache.jena.sparql.core.BasicPattern) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Aggregations

BasicPattern (org.apache.jena.sparql.core.BasicPattern)44 Node (org.apache.jena.graph.Node)15 Triple (org.apache.jena.graph.Triple)13 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)13 Op (org.apache.jena.sparql.algebra.Op)11 Test (org.junit.Test)11 Var (org.apache.jena.sparql.core.Var)5 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 ArrayList (java.util.ArrayList)4 BaseTest (org.apache.jena.atlas.junit.BaseTest)4 OpQuadPattern (org.apache.jena.sparql.algebra.op.OpQuadPattern)4 Quad (org.apache.jena.sparql.core.Quad)4 SocketException (java.net.SocketException)3 HashMap (java.util.HashMap)3 ConnectTimeoutException (org.apache.http.conn.ConnectTimeoutException)3 OpService (org.apache.jena.sparql.algebra.op.OpService)3 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)3 Context (org.apache.jena.sparql.util.Context)3 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)2