Search in sources :

Example 36 with DatasetGraph

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

the class AbstractTestTransPromote method run_03.

private void run_03(boolean readCommitted) {
    Assume.assumeTrue(!readCommitted || supportsReadCommitted());
    setReadCommitted(readCommitted);
    DatasetGraph dsg = create();
    dsg.begin(ReadWrite.WRITE);
    dsg.commit();
    dsg.end();
    dsg.begin(ReadWrite.READ);
    dsg.add(q1);
    dsg.commit();
    dsg.end();
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 37 with DatasetGraph

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

the class TestTransactionDSGWithLockWithAbort method create.

@Override
protected Dataset create() {
    // The tests don't actually add/delete data.
    DatasetGraph dsg = DatasetGraphFactory.createTxnMem();
    DatasetGraphWithLock dsgl = new DatasetGraphWithLock(dsg, true);
    return DatasetFactory.wrap(dsgl);
}
Also used : DatasetGraphWithLock(org.apache.jena.sparql.core.DatasetGraphWithLock) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 38 with DatasetGraph

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

the class AbstractTestTransPromote method run_06.

// Async writer after promotion.
private void run_06(boolean readCommitted) {
    Assume.assumeTrue(!readCommitted || supportsReadCommitted());
    setReadCommitted(readCommitted);
    DatasetGraph dsg = create();
    AtomicInteger a = new AtomicInteger(0);
    Semaphore sema = new Semaphore(0);
    Thread t = new Thread(() -> {
        sema.release();
        Txn.executeWrite(dsg, () -> dsg.add(q3));
        sema.release();
    });
    dsg.begin(ReadWrite.READ);
    // Promote
    dsg.add(q1);
    t.start();
    // First release.
    sema.acquireUninterruptibly();
    // Thread blocked.
    dsg.add(q2);
    dsg.commit();
    dsg.end();
    // Until thread exits.
    sema.acquireUninterruptibly();
    assertCount(3, dsg);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 39 with DatasetGraph

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

the class TestMultipleEmbedded method multiple_01.

// Two servers, same port -> bad.
@Test(expected = FusekiException.class)
public void multiple_01() {
    DatasetGraph dsg = dataset();
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server1 = FusekiEmbeddedServer.create().setPort(port).add("/ds1", dsg).build();
    // Same port - Bbad.
    FusekiEmbeddedServer server2 = FusekiEmbeddedServer.create().setPort(port).add("/ds2", dsg).build();
    server1.start();
    try {
        server2.start();
    } catch (FusekiException ex) {
        assertTrue(ex.getCause() instanceof java.net.BindException);
        throw ex;
    } finally {
        try {
            server1.stop();
        } catch (Exception ex) {
        }
        try {
            server2.stop();
        } catch (Exception ex) {
        }
    }
}
Also used : FusekiException(org.apache.jena.fuseki.FusekiException) FusekiException(org.apache.jena.fuseki.FusekiException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 40 with DatasetGraph

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

the class TestMultipleEmbedded method multiple_04.

// Two servers, one dataset under two names.
@Test
public void multiple_04() {
    DatasetGraph dsg = dataset();
    int port1 = FusekiLib.choosePort();
    FusekiEmbeddedServer server1 = FusekiEmbeddedServer.create().setPort(port1).add("/ds1", dsg).build().start();
    Txn.executeWrite(dsg, () -> dsg.add(q1));
    int port2 = FusekiLib.choosePort();
    FusekiEmbeddedServer server2 = FusekiEmbeddedServer.create().setPort(port2).add("/ds2", dsg).build().start();
    Txn.executeWrite(dsg, () -> dsg.add(q2));
    query("http://localhost:" + port1 + "/ds1", "SELECT * {?s ?p ?o}", qExec -> {
        ResultSet rs = qExec.execSelect();
        int x = ResultSetFormatter.consume(rs);
        assertEquals(2, x);
    });
    query("http://localhost:" + port2 + "/ds2", "SELECT * {?s ?p ?o}", qExec -> {
        ResultSet rs = qExec.execSelect();
        int x = ResultSetFormatter.consume(rs);
        assertEquals(2, x);
    });
    server1.stop();
    server2.stop();
}
Also used : ResultSet(org.apache.jena.query.ResultSet) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Aggregations

DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)222 Test (org.junit.Test)132 BaseTest (org.apache.jena.atlas.junit.BaseTest)59 Quad (org.apache.jena.sparql.core.Quad)47 Node (org.apache.jena.graph.Node)29 Graph (org.apache.jena.graph.Graph)18 StoreConnection (org.apache.jena.tdb.StoreConnection)17 DatasetGraphTxn (org.apache.jena.tdb.transaction.DatasetGraphTxn)15 Model (org.apache.jena.rdf.model.Model)10 IOException (java.io.IOException)7 Triple (org.apache.jena.graph.Triple)7 Dataset (org.apache.jena.query.Dataset)7 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 ResultSet (org.apache.jena.query.ResultSet)5 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)5 Element (org.apache.jena.sparql.syntax.Element)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RiotException (org.apache.jena.riot.RiotException)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4