def testRun_PASS(self): # Now we'll run a transaction ourselves self.refOne = Ref(111, None) self.refTwo = Ref(222, None) # Our transaction body will do a ref-set and an alter (increment a ref by 1) def body(): # Body of the transaction! self.refZero.refSet(999) def incr(val): return val + 1 self.refOne.alter(incr, []) # Test our transaction actually made the changes it should have LockingTransaction.runInTransaction(body) self.assertEqual(self.refZero.deref(), 999) self.assertEqual(self.refOne.deref(), 112) self.assertEqual(self.refTwo.deref(), 222) # Test that the transaction ended properly self.assertRaises(IllegalStateException, self.refZero.refSet, 999)
def testRun_PASS(self): # Now we'll run a transaction ourselves self.refOne = Ref(111, None) self.refTwo = Ref(222, None) # Our transaction body will do a ref-set and an alter (increment a ref by 1) def body(): # Body of the transaction! self.refZero.refSet(999) def incr(val): return val + 1 self.refOne.alter(incr, []) # Test our transaction actually made the changes it should have LockingTransaction.runInTransaction(body) self.assertEqual(self.refZero.deref(), 999) self.assertEqual(self.refOne.deref(), 112) self.assertEqual(self.refTwo.deref(), 222) # Test that the transaction ended properly self.assertRaises(IllegalStateException, self.refZero.refSet, 999)
def thread_func(transaction_func, postcommit_func): self.first_run.data = True LockingTransaction.runInTransaction(transaction_func) if postcommit_func: postcommit_func()