Search in sources :

Example 6 with Transactional

use of org.apache.jena.dboe.transaction.Transactional in project jena by apache.

the class TestTransBlobPersistent method transBlobFile_2.

@Test
public void transBlobFile_2() throws Exception {
    Journal journal = Journal.create(Location.create(DIR));
    BufferChannel chan = BufferChannelFile.create(DATA);
    ComponentId cid = ComponentId.allocLocal();
    TransBlob transBlob = new TransBlob(cid, chan);
    Transactional transactional = TransactionalFactory.createTransactional(journal, transBlob);
    String str = "Hello1";
    Txn.executeWrite(transactional, () -> {
        transBlob.setString("one");
    });
    Txn.executeWrite(transactional, () -> {
        transBlob.setString("two");
    });
    chan.close();
    journal.close();
    String s = FileUtils.readWholeFileAsUTF8(DATA);
    assertEquals("two", s);
}
Also used : BufferChannel(org.apache.jena.dboe.base.file.BufferChannel) Journal(org.apache.jena.dboe.transaction.txn.journal.Journal) ComponentId(org.apache.jena.dboe.transaction.txn.ComponentId) Transactional(org.apache.jena.dboe.transaction.Transactional)

Example 7 with Transactional

use of org.apache.jena.dboe.transaction.Transactional in project jena by apache.

the class TestBPlusTreeTxn method bptree_txn_03.

// Abort
@Test
public void bptree_txn_03() {
    BPlusTree bpt = createBPTree();
    int outerRootIdx1 = bpt.getRootId();
    Transactional thing = transactional(bpt);
    thing.begin(ReadWrite.WRITE);
    IndexTestLib.add(bpt, 1, 2, 3, 4);
    thing.abort();
    thing.end();
    int outerRootIdx2 = bpt.getRootId();
    assertEquals("After txn", outerRootIdx1, outerRootIdx2);
}
Also used : Transactional(org.apache.jena.dboe.transaction.Transactional) Test(org.junit.Test)

Example 8 with Transactional

use of org.apache.jena.dboe.transaction.Transactional in project jena by apache.

the class TestBPlusTreeTxn method bptree_txn_04.

// Two transactions
@Test
public void bptree_txn_04() {
    BPlusTree bpt = createBPTree();
    int outerRootIdx1 = bpt.getRootId();
    Transactional thing = transactional(bpt);
    Txn.executeWrite(thing, () -> {
        IndexTestLib.add(bpt, 1, 2, 3, 4);
    });
    int outerRootIdx2 = bpt.getRootId();
    assertNotEquals("After txn(1)", outerRootIdx1, outerRootIdx2);
    Txn.executeWrite(thing, () -> {
        IndexTestLib.add(bpt, 5, 6);
    });
    int outerRootIdx3 = bpt.getRootId();
    assertNotEquals("After txn (2)", outerRootIdx1, outerRootIdx3);
    assertNotEquals("After txn (3)", outerRootIdx2, outerRootIdx3);
}
Also used : Transactional(org.apache.jena.dboe.transaction.Transactional) Test(org.junit.Test)

Example 9 with Transactional

use of org.apache.jena.dboe.transaction.Transactional in project jena by apache.

the class TestBPlusTreeTxn method bptree_txn_01.

// Commit
@Test
public void bptree_txn_01() {
    BPlusTree bpt = createBPTree();
    assertNotNull(bpt.getComponentId());
    int outerRootIdx1 = bpt.getRootId();
    Transactional thing = transactional(bpt);
    Txn.executeWrite(thing, () -> {
        IndexTestLib.add(bpt, 1, 2, 3, 4);
    });
    int outerRootIdx2 = bpt.getRootId();
    assertNotEquals("After txn", outerRootIdx1, outerRootIdx2);
}
Also used : Transactional(org.apache.jena.dboe.transaction.Transactional) Test(org.junit.Test)

Example 10 with Transactional

use of org.apache.jena.dboe.transaction.Transactional in project jena by apache.

the class TestBPlusTreeTxn method bptree_txn_10.

// Two trees
@Test
public void bptree_txn_10() {
    BPlusTree bpt1 = createBPTree();
    BPlusTree bpt2 = createBPTree();
    assertNotEquals(bpt1.getComponentId(), bpt2.getComponentId());
    Transactional thing = transactional(bpt1, bpt2);
    Txn.executeWrite(thing, () -> {
        IndexTestLib.add(bpt1, 1, 2, 3);
        IndexTestLib.add(bpt2, 4, 5);
    });
    Txn.executeRead(thing, () -> {
        IndexTestLib.testIndexContents(bpt2, 4, 5);
        IndexTestLib.testIndexContents(bpt1, 1, 2, 3);
    });
}
Also used : Transactional(org.apache.jena.dboe.transaction.Transactional) Test(org.junit.Test)

Aggregations

Transactional (org.apache.jena.dboe.transaction.Transactional)10 Test (org.junit.Test)8 BufferChannel (org.apache.jena.dboe.base.file.BufferChannel)2 ComponentId (org.apache.jena.dboe.transaction.txn.ComponentId)2 Journal (org.apache.jena.dboe.transaction.txn.journal.Journal)2