Search in sources :

Example 1 with NodeTableTrans

use of org.apache.jena.tdb.transaction.NodeTableTrans in project jena by apache.

the class AbstractTestNodeTableTrans method nodetrans_06.

@Test
public void nodetrans_06() {
    // 2 transactions - blocking reader - create a second NodeTableTrans
    Transaction txn1 = createTxn(11);
    NodeTableTrans ntt1 = create(txn1, node1);
    NodeId nodeId1 = ntt1.getBaseNodeTable().getNodeIdForNode(node1);
    ntt1.begin(txn1);
    NodeId nodeId2 = ntt1.getAllocateNodeId(node2);
    ntt1.commitPrepare(txn1);
    // READ - don't enact
    Transaction txn2 = createTxn(12);
    NodeTableTrans ntt2 = create(txn2, ntt1.getBaseNodeTable());
    ntt2.begin(txn2);
    assertEquals(nodeId1, ntt2.getNodeIdForNode(node1));
    assertEquals(nodeId2, ntt2.getNodeIdForNode(node2));
    NodeId nodeId3 = ntt2.getAllocateNodeId(node3);
    assertEquals(nodeId3, ntt2.getNodeIdForNode(node3));
    ntt2.commitPrepare(txn2);
    // READ ends.
    ntt1.commitEnact(txn1);
    ntt1.commitClearup(txn1);
    ntt2.commitEnact(txn2);
    ntt2.commitClearup(txn2);
    assertEquals(nodeId1, ntt1.getBaseNodeTable().getNodeIdForNode(node1));
    assertEquals(nodeId2, ntt1.getBaseNodeTable().getNodeIdForNode(node2));
    assertEquals(nodeId3, ntt1.getBaseNodeTable().getNodeIdForNode(node3));
}
Also used : NodeTableTrans(org.apache.jena.tdb.transaction.NodeTableTrans) Transaction(org.apache.jena.tdb.transaction.Transaction) NodeId(org.apache.jena.tdb.store.NodeId) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 2 with NodeTableTrans

use of org.apache.jena.tdb.transaction.NodeTableTrans in project jena by apache.

the class AbstractTestNodeTableTrans method nodetrans_07.

@Test
public void nodetrans_07() {
    Transaction txn = createTxn(13);
    NodeTableTrans ntt = create(txn);
    ntt.begin(txn);
    assertEquals(NodeId.NodeIdAny, ntt.getNodeIdForNode(Node.ANY));
    assertEquals(Node.ANY, ntt.getNodeForNodeId(NodeId.NodeIdAny));
    assertTrue(ntt.isEmpty());
    ntt.commitPrepare(txn);
    ntt.commitEnact(txn);
    ntt.commitClearup(txn);
}
Also used : NodeTableTrans(org.apache.jena.tdb.transaction.NodeTableTrans) Transaction(org.apache.jena.tdb.transaction.Transaction) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 3 with NodeTableTrans

use of org.apache.jena.tdb.transaction.NodeTableTrans in project jena by apache.

the class AbstractTestNodeTableTrans method nodetrans_05.

@Test
public void nodetrans_05() {
    // 2 transactions - no blocking reader - create a second NodeTableTrans
    Transaction txn1 = createTxn(11);
    NodeTableTrans ntt1 = create(txn1, node1);
    NodeId nodeId1 = ntt1.getBaseNodeTable().getNodeIdForNode(node1);
    ntt1.begin(txn1);
    NodeId nodeId2 = ntt1.getAllocateNodeId(node2);
    ntt1.commitPrepare(txn1);
    ntt1.commitEnact(txn1);
    ntt1.commitClearup(txn1);
    Transaction txn2 = createTxn(12);
    NodeTableTrans ntt2 = create(txn2, ntt1.getBaseNodeTable());
    ntt2.begin(txn2);
    assertEquals(nodeId1, ntt2.getNodeIdForNode(node1));
    assertEquals(nodeId2, ntt2.getNodeIdForNode(node2));
    NodeId nodeId3 = ntt2.getAllocateNodeId(node3);
    assertEquals(nodeId3, ntt2.getNodeIdForNode(node3));
    ntt2.commitPrepare(txn2);
    ntt2.commitEnact(txn2);
    ntt2.commitClearup(txn2);
    assertEquals(nodeId1, ntt1.getBaseNodeTable().getNodeIdForNode(node1));
    assertEquals(nodeId2, ntt1.getBaseNodeTable().getNodeIdForNode(node2));
    assertEquals(nodeId3, ntt1.getBaseNodeTable().getNodeIdForNode(node3));
}
Also used : NodeTableTrans(org.apache.jena.tdb.transaction.NodeTableTrans) Transaction(org.apache.jena.tdb.transaction.Transaction) NodeId(org.apache.jena.tdb.store.NodeId) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 4 with NodeTableTrans

use of org.apache.jena.tdb.transaction.NodeTableTrans in project jena by apache.

the class AbstractTestNodeTableTrans method nodetrans_01.

@Test
public void nodetrans_01() {
    Transaction txn = createTxn(11);
    NodeTableTrans ntt = create(txn);
    ntt.begin(txn);
    ntt.abort(txn);
}
Also used : NodeTableTrans(org.apache.jena.tdb.transaction.NodeTableTrans) Transaction(org.apache.jena.tdb.transaction.Transaction) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Example 5 with NodeTableTrans

use of org.apache.jena.tdb.transaction.NodeTableTrans in project jena by apache.

the class AbstractTestNodeTableTrans method nodetrans_02.

@Test
public void nodetrans_02() {
    Transaction txn = createTxn(11);
    NodeTableTrans ntt = create(txn);
    NodeTable nt0 = ntt.getBaseNodeTable();
    ntt.begin(txn);
    // Add a node
    NodeId nodeId = ntt.getAllocateNodeId(node1);
    // Check not in the base.
    assertNull(nt0.getNodeForNodeId(nodeId));
    // Check is in the transaction node table.
    assertEquals(NodeId.NodeDoesNotExist, nt0.getNodeIdForNode(node1));
    assertEquals(node1, ntt.getNodeForNodeId(nodeId));
    ntt.commitPrepare(txn);
    ntt.commitEnact(txn);
    // Check it is now in the base.
    assertEquals(node1, nt0.getNodeForNodeId(nodeId));
    assertEquals(nodeId, nt0.getNodeIdForNode(node1));
    ntt.commitClearup(txn);
}
Also used : NodeTableTrans(org.apache.jena.tdb.transaction.NodeTableTrans) Transaction(org.apache.jena.tdb.transaction.Transaction) NodeId(org.apache.jena.tdb.store.NodeId) NodeTable(org.apache.jena.tdb.store.nodetable.NodeTable) Test(org.junit.Test) BaseTest(org.apache.jena.atlas.junit.BaseTest)

Aggregations

NodeTableTrans (org.apache.jena.tdb.transaction.NodeTableTrans)8 BaseTest (org.apache.jena.atlas.junit.BaseTest)7 Transaction (org.apache.jena.tdb.transaction.Transaction)7 Test (org.junit.Test)7 NodeId (org.apache.jena.tdb.store.NodeId)5 NodeTable (org.apache.jena.tdb.store.nodetable.NodeTable)3 ObjectFile (org.apache.jena.tdb.base.objectfile.ObjectFile)1 RecordFactory (org.apache.jena.tdb.base.record.RecordFactory)1 Index (org.apache.jena.tdb.index.Index)1 IndexMap (org.apache.jena.tdb.index.IndexMap)1