Txn { public static <T extends Transactional> void exec(T txn, TxnType txnType, Runnable r) { boolean b = txn.isInTransaction() ; if ( b ) TxnOp.compatibleWithPromote(txnType, txn); else txn.begin(txnType) ; try { r.run() ; } catch (Throwable th) { onThrowable(th, txn); throw th ; } if ( !b ) { if ( txn.isInTransaction() ) txn.commit() ; txn.end() ; } }  static void execute(T txn, Runnable r); static X calculate(T txn, Supplier<X> r); static void exec(T txn, TxnType txnType, Runnable r); static X calc(T txn, TxnType txnType, Supplier<X> r); static void executeRead(T txn, Runnable r); static X calculateRead(T txn, Supplier<X> r); static void executeWrite(T txn, Runnable r); static X calculateWrite(T txn, Supplier<X> r);  }
@Test public void txn_nested_01() { Txn.exec(counter, TxnType.READ, ()->{ Txn.exec(counter, TxnType.READ, ()->{}); }); }
@Test public void txn_nested_02() { Txn.exec(counter, TxnType.WRITE, ()->{ Txn.exec(counter, TxnType.READ, ()->{}); }); }
@Test public void txn_nested_03() { Txn.exec(counter, TxnType.READ_PROMOTE, ()->{ Txn.exec(counter, TxnType.READ, ()->{}); }); }
@Test public void txn_nested_04() { Txn.exec(counter, TxnType.READ_COMMITTED_PROMOTE, ()->{ Txn.exec(counter, TxnType.READ, ()->{}); }); }
@Test(expected=JenaTransactionException.class) public void txn_nested_05() { Txn.exec(counter, TxnType.READ, ()->{ Txn.exec(counter, TxnType.WRITE, ()->{}); }); }
@Test public void txn_nested_06() { Txn.exec(counter, TxnType.READ_PROMOTE, ()->{ boolean b = counter.promote(); assertTrue(b); Txn.exec(counter, TxnType.READ_PROMOTE, ()->{}); }); }
@Test public void txn_nested_07() { Txn.exec(counter, TxnType.READ_COMMITTED_PROMOTE, ()->{ boolean b = counter.promote(); assertTrue(b); Txn.exec(counter, TxnType.READ_COMMITTED_PROMOTE, ()->{}); }); }
@Test public void txn_nested_08() { Txn.exec(counter, TxnType.READ_COMMITTED_PROMOTE, ()->{ boolean b = counter.promote(); assertTrue(b); assertEquals(ReadWrite.WRITE, counter.transactionMode()); Txn.exec(counter, TxnType.READ_COMMITTED_PROMOTE, ()->{}); }); }
@Test public void txn_nested_09() { Txn.exec(counter, TxnType.READ_PROMOTE, ()->{ boolean b = counter.promote(); assertTrue(b); assertEquals(ReadWrite.WRITE, counter.transactionMode()); Txn.exec(counter, TxnType.READ_PROMOTE, ()->{}); }); }
@Test public void txn_nested_10() { Txn.exec(counter, TxnType.READ_PROMOTE, ()->{ Txn.exec(counter, TxnType.WRITE, ()->{}); }); }
@Test public void txn_nested_11() { Txn.exec(counter, TxnType.READ_COMMITTED_PROMOTE, ()->{ Txn.exec(counter, TxnType.WRITE, ()->{}); }); }
@Test public void txn_threaded_01() { Txn.exec(counter, TxnType.READ_PROMOTE, ()->{ ThreadAction a = ThreadTxn.threadTxnWrite(counter, ()->{}); a.run(); boolean b = counter.promote(); assertFalse(b); assertEquals(ReadWrite.READ, counter.transactionMode()); }); }
@Test public void txn_threaded_02() { Transactional tx = counter; ThreadAction a = ThreadTxn.threadTxnWrite(tx, ()->{}); Txn.exec(tx, TxnType.READ_PROMOTE, ()->{ a.run(); boolean b = tx.promote(); assertFalse(b); assertEquals(ReadWrite.READ, tx.transactionMode()); }); }
@Test public void txn_threaded_03() { Transactional tx = DatasetGraphFactory.createTxnMem(); ThreadAction a = ThreadTxn.threadTxnWriteAbort(tx, ()->{}); Txn.exec(tx, TxnType.READ_PROMOTE, ()->{ a.run(); boolean b = tx.promote(); assertTrue(b); assertEquals(ReadWrite.WRITE, tx.transactionMode()); }); }