def testGetRef_PASS(self): # No running transaction self.assertRaises(TransactionRetryException, LockingTransaction().getRef, self.refZero) with running_transaction(self): t = LockingTransaction.ensureGet() # Ref has a previously committed value and no in-transaction-value, so check it # Since we're faking this test, we need our read point to be > 0 LockingTransaction.ensureGet()._updateReadPoint(False) LockingTransaction.ensureGet()._updateReadPoint(False) self.assertEqual(t.getRef(self.refZero), 0) # Make sure we unlocked the ref's lock self.assertRaises(Exception, self.refZero._lock.release_shared) # Give the ref some history and see if it still works. Our read point is 1 and our new value was committed at time 3 self.refZero._tvals = TVal(100, 3, time(), self.refZero._tvals) self.assertEqual(t.getRef(self.refZero), 0) # Now we want the latest value LockingTransaction.ensureGet()._updateReadPoint(False) LockingTransaction.ensureGet()._updateReadPoint(False) LockingTransaction.ensureGet()._updateReadPoint(False) self.assertEqual(t.getRef(self.refZero), 100) # Force the oldest val to be too new to get a fault # Now we have a val at history point 2 and 3 self.refZero._tvals.next.point = 2 t._readPoint = 1 # We should retry and update our faults self.assertRaises(TransactionRetryException, t.getRef, self.refZero) self.assertEqual(self.refZero._faults.get(), 1)
def thread_func(testclass, mainTransaction, funcToRun): self.assertIsNone(LockingTransaction.get()) LockingTransaction._transactions.local = LockingTransaction() LockingTransaction._transactions.local._info = Info( TransactionState.Running, LockingTransaction._transactions.local._startPoint) funcToRun(testclass, mainTransaction) LockingTransaction._transactions = thread_local() self.assertIsNone(LockingTransaction.get())
def running_transaction(thetest): # Fake a running transaction LockingTransaction._transactions.local = LockingTransaction() LockingTransaction._transactions.local._info = Info( TransactionState.Running, LockingTransaction._transactions.local._startPoint) LockingTransaction.ensureGet()._readPoint = -1 LockingTransaction.transactionCounter = count() LockingTransaction.ensureGet()._startPoint = time() yield # Clean up and remove LockingTransaction we created LockingTransaction._transactions = thread_local() thetest.assertIsNone(LockingTransaction.get())