Search in sources :

Example 11 with Transaction

use of org.apache.jena.dboe.transaction.txn.Transaction in project jena by apache.

the class TestTransactionLifecycle2 method txn_overlap_RW.

@Test
public void txn_overlap_RW() {
    Transaction txn1 = txnMgr.begin(TxnType.READ, false);
    assertNotNull(txn1);
    Transaction txn2 = txnMgr.begin(TxnType.WRITE, false);
    assertNotNull(txn2);
    txn1.commit();
    txn1.end();
    txn2.abort();
    txn2.end();
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) Test(org.junit.Test)

Example 12 with Transaction

use of org.apache.jena.dboe.transaction.txn.Transaction in project jena by apache.

the class TestTransactionLifecycle2 method txn_promote_deadlock.

// Not a @Test
public void txn_promote_deadlock() {
    Transaction txn1 = txnMgr.begin(TxnType.READ);
    Transaction txn2 = txnMgr.begin(TxnType.WRITE);
    // Deadlock.
    // Promotion waits for the writer to decide whether it is commiting or not.
    // This can't be done on one thread.
    boolean b = txn1.promote();
    assertFalse(b);
    txn1.end();
    txn2.commit();
    txn2.end();
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction)

Example 13 with Transaction

use of org.apache.jena.dboe.transaction.txn.Transaction in project jena by apache.

the class TestTransactionLifecycle2 method txn_promote_thread_writer_4.

@Test
public void txn_promote_thread_writer_4() {
    Transaction txn1 = txnMgr.begin(TxnType.READ_PROMOTE);
    boolean b = txn1.promote();
    assertTrue(b);
    AtomicReference<Transaction> ref = new AtomicReference<>(txn1);
    ThreadLib.syncOtherThread(() -> {
        // Should fail.
        Transaction txn2 = txnMgr.begin(TxnType.WRITE, false);
        ref.set(txn2);
    });
    assertNull(ref.get());
    txn1.abort();
    txn1.end();
    ThreadLib.syncOtherThread(() -> {
        // Should suceed
        Transaction txn2 = txnMgr.begin(TxnType.WRITE, false);
        ref.set(txn2);
        txn2.abort();
        txn2.end();
    });
    assertNotNull(ref.get());
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 14 with Transaction

use of org.apache.jena.dboe.transaction.txn.Transaction in project jena by apache.

the class TestTransactionLifecycle2 method txn_direct_04.

@Test
public void txn_direct_04() {
    Transaction txn1 = txnMgr.begin(TxnType.WRITE);
    // This tests the TransactionCoordinator
    // but the TransactiolComponentLifecycle doesn't support multiple
    // transactions per thread (use of ThreadLocals).
    // To do that, the transaction object would be needed in all
    // component API calls.  Doable but intrusive.
    Transaction txn2 = txnMgr.begin(TxnType.READ);
    txn1.commit();
    txn2.end();
    txn1.end();
    checkClear();
}
Also used : Transaction(org.apache.jena.dboe.transaction.txn.Transaction) Test(org.junit.Test)

Example 15 with Transaction

use of org.apache.jena.dboe.transaction.txn.Transaction in project jena by apache.

the class StoragePrefixesTDB method ensureWriteTxn.

// private void requireTxn() {
// if ( ! txnSystem.isInTransaction() )
// throw new TransactionException("Not on a transaction");
// }
private void ensureWriteTxn() {
    Transaction txn = txnSystem.getThreadTransaction();
    if (txn == null)
        throw new TransactionException("Not in a transaction");
    txn.ensureWriteTxn();
}
Also used : TransactionException(org.apache.jena.dboe.transaction.txn.TransactionException) Transaction(org.apache.jena.dboe.transaction.txn.Transaction)

Aggregations

Transaction (org.apache.jena.dboe.transaction.txn.Transaction)26 Test (org.junit.Test)21 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Tuple (org.apache.jena.atlas.lib.tuple.Tuple)2 TransactionCoordinator (org.apache.jena.dboe.transaction.txn.TransactionCoordinator)2 TransactionException (org.apache.jena.dboe.transaction.txn.TransactionException)2