Txn { public static <T extends Transactional, X> X calculateWrite(T txn, Supplier<X> r) { return calc(txn, TxnType.WRITE, r); }  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_basic_05() { long x = Txn.calculateWrite(counter, () -> { counter.inc() ; assertEquals("In W, value()", 0, counter.value()) ; assertEquals("In W, get()",1, counter.get()) ; return counter.get() ; }) ; assertEquals("Outside W",1, x) ; }
@Test public void txn_write_01() { long x = Txn.calculateWrite(counter, () -> { counter.inc() ; assertEquals("In W, value()", 0, counter.value()) ; assertEquals("In W, get()",1, counter.get()) ; long z = counter.get() ; counter.commit() ; return z ; }) ; assertEquals("Outside W",1, x) ; }
@Test public void txn_write_02() { long x = Txn.calculateWrite(counter, () -> { counter.inc() ; assertEquals("In W, value()", 0, counter.value()) ; assertEquals("In W, get()",1, counter.get()) ; long z = counter.get() ; counter.abort() ; return z ; }) ; assertEquals("Outside W",1, x) ; }