Commit a0972725 authored by Jeremy Hylton's avatar Jeremy Hylton

Replace use of builtin get_transaction() with explicit transaction module.

parent 62447db4
...@@ -20,9 +20,9 @@ def convert(old, new, threshold=200, f=None): ...@@ -20,9 +20,9 @@ def convert(old, new, threshold=200, f=None):
new[k]=v new[k]=v
n=n+1 n=n+1
if n > threshold: if n > threshold:
get_transaction().commit(1) transaction.commit(1)
old._p_jar.cacheMinimize() old._p_jar.cacheMinimize()
n=0 n=0
get_transaction().commit(1) transaction.commit(1)
old._p_jar.cacheMinimize() old._p_jar.cacheMinimize()
...@@ -21,6 +21,7 @@ from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet ...@@ -21,6 +21,7 @@ from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
from BTrees.check import check from BTrees.check import check
import transaction
from ZODB import DB from ZODB import DB
from ZODB.MappingStorage import MappingStorage from ZODB.MappingStorage import MappingStorage
...@@ -56,7 +57,7 @@ class Base(TestCase): ...@@ -56,7 +57,7 @@ class Base(TestCase):
root = None root = None
root = self._getRoot() root = self._getRoot()
root[i] = t root[i] = t
get_transaction().commit() transaction.commit()
root2 = self._getRoot() root2 = self._getRoot()
if hasattr(t, 'items'): if hasattr(t, 'items'):
...@@ -73,11 +74,11 @@ class Base(TestCase): ...@@ -73,11 +74,11 @@ class Base(TestCase):
self._populate(t, i) self._populate(t, i)
root = self._getRoot() root = self._getRoot()
root[i] = t root[i] = t
get_transaction().commit() transaction.commit()
root2 = self._getRoot() root2 = self._getRoot()
root2[i]._p_deactivate() root2[i]._p_deactivate()
get_transaction().commit() transaction.commit()
if hasattr(t, 'items'): if hasattr(t, 'items'):
self.assertEqual(list(root2[i].items()) , list(t.items())) self.assertEqual(list(root2[i].items()) , list(t.items()))
else: else:
......
...@@ -19,6 +19,7 @@ from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet ...@@ -19,6 +19,7 @@ from BTrees.IOBTree import IOBTree, IOBucket, IOSet, IOTreeSet
from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet from BTrees.IIBTree import IIBTree, IIBucket, IISet, IITreeSet
from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet from BTrees.OIBTree import OIBTree, OIBucket, OISet, OITreeSet
import transaction
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
class Base: class Base:
...@@ -27,7 +28,7 @@ class Base: ...@@ -27,7 +28,7 @@ class Base:
storage = None storage = None
def tearDown(self): def tearDown(self):
get_transaction().abort() transaction.abort()
del self.t del self.t
if self.storage is not None: if self.storage is not None:
self.storage.close() self.storage.close()
...@@ -75,7 +76,7 @@ class MappingBase(Base): ...@@ -75,7 +76,7 @@ class MappingBase(Base):
r1 = self.db.open().root() r1 = self.db.open().root()
r1["t"] = self.t r1["t"] = self.t
get_transaction().commit() transaction.commit()
r2 = self.db.open().root() r2 = self.db.open().root()
copy = r2["t"] copy = r2["t"]
...@@ -84,10 +85,10 @@ class MappingBase(Base): ...@@ -84,10 +85,10 @@ class MappingBase(Base):
self.assertEqual(self.t._p_serial, copy._p_serial) self.assertEqual(self.t._p_serial, copy._p_serial)
self.t.update({1:2, 2:3}) self.t.update({1:2, 2:3})
get_transaction().commit() transaction.commit()
copy.update({3:4}) copy.update({3:4})
get_transaction().commit() transaction.commit()
def testMergeDelete(self): def testMergeDelete(self):
...@@ -427,7 +428,7 @@ class NastyConfict(Base, TestCase): ...@@ -427,7 +428,7 @@ class NastyConfict(Base, TestCase):
r1 = self.db.open().root() r1 = self.db.open().root()
r1["t"] = self.t r1["t"] = self.t
get_transaction().commit() transaction.commit()
r2 = self.db.open().root() r2 = self.db.open().root()
copy = r2["t"] copy = r2["t"]
...@@ -437,10 +438,10 @@ class NastyConfict(Base, TestCase): ...@@ -437,10 +438,10 @@ class NastyConfict(Base, TestCase):
self.assertEqual(self.t._p_serial, copy._p_serial) self.assertEqual(self.t._p_serial, copy._p_serial)
self.t.update({1:2, 2:3}) self.t.update({1:2, 2:3})
get_transaction().commit() transaction.commit()
copy.update({3:4}) copy.update({3:4})
get_transaction().commit() # if this doesn't blow up transaction.commit() # if this doesn't blow up
list(copy.values()) # and this doesn't either, then fine list(copy.values()) # and this doesn't either, then fine
def testBucketSplitConflict(self): def testBucketSplitConflict(self):
...@@ -467,7 +468,7 @@ class NastyConfict(Base, TestCase): ...@@ -467,7 +468,7 @@ class NastyConfict(Base, TestCase):
r1 = self.db.open().root() r1 = self.db.open().root()
r1["t"] = self.t r1["t"] = self.t
get_transaction().commit() transaction.commit()
r2 = self.db.open(synch=False).root() r2 = self.db.open(synch=False).root()
copy = r2["t"] copy = r2["t"]
...@@ -499,7 +500,7 @@ class NastyConfict(Base, TestCase): ...@@ -499,7 +500,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][3], 75) self.assertEqual(state[0][3], 75)
self.assertEqual(state[0][5], 120) self.assertEqual(state[0][5], 120)
get_transaction().commit() transaction.commit()
# In the other transaction, add 3 values near the tail end of bucket1. # In the other transaction, add 3 values near the tail end of bucket1.
# This doesn't cause a split. # This doesn't cause a split.
...@@ -517,8 +518,8 @@ class NastyConfict(Base, TestCase): ...@@ -517,8 +518,8 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][1], 60) self.assertEqual(state[0][1], 60)
self.assertEqual(state[0][3], 120) self.assertEqual(state[0][3], 120)
self.assertRaises(ConflictError, get_transaction().commit) self.assertRaises(ConflictError, transaction.commit)
get_transaction().abort() # horrible things happen w/o this transaction.abort() # horrible things happen w/o this
def testEmptyBucketConflict(self): def testEmptyBucketConflict(self):
# Tests that an emptied bucket *created by* conflict resolution is # Tests that an emptied bucket *created by* conflict resolution is
...@@ -544,7 +545,7 @@ class NastyConfict(Base, TestCase): ...@@ -544,7 +545,7 @@ class NastyConfict(Base, TestCase):
r1 = self.db.open().root() r1 = self.db.open().root()
r1["t"] = self.t r1["t"] = self.t
get_transaction().commit() transaction.commit()
r2 = self.db.open(synch=False).root() r2 = self.db.open(synch=False).root()
copy = r2["t"] copy = r2["t"]
...@@ -568,7 +569,7 @@ class NastyConfict(Base, TestCase): ...@@ -568,7 +569,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][1], 60) self.assertEqual(state[0][1], 60)
self.assertEqual(state[0][3], 120) self.assertEqual(state[0][3], 120)
get_transaction().commit() transaction.commit()
# In the other transaction, delete the other half of bucket 1. # In the other transaction, delete the other half of bucket 1.
b = copy b = copy
...@@ -589,8 +590,8 @@ class NastyConfict(Base, TestCase): ...@@ -589,8 +590,8 @@ class NastyConfict(Base, TestCase):
# create an "insane" BTree (a legit BTree cannot contain an empty # create an "insane" BTree (a legit BTree cannot contain an empty
# bucket -- it contains NULL pointers the BTree code doesn't # bucket -- it contains NULL pointers the BTree code doesn't
# expect, and segfaults result). # expect, and segfaults result).
self.assertRaises(ConflictError, get_transaction().commit) self.assertRaises(ConflictError, transaction.commit)
get_transaction().abort() # horrible things happen w/o this transaction.abort() # horrible things happen w/o this
def testEmptyBucketNoConflict(self): def testEmptyBucketNoConflict(self):
...@@ -616,7 +617,7 @@ class NastyConfict(Base, TestCase): ...@@ -616,7 +617,7 @@ class NastyConfict(Base, TestCase):
r1 = self.db.open().root() r1 = self.db.open().root()
r1["t"] = self.t r1["t"] = self.t
get_transaction().commit() transaction.commit()
r2 = self.db.open().root() r2 = self.db.open().root()
copy = r2["t"] copy = r2["t"]
...@@ -639,7 +640,7 @@ class NastyConfict(Base, TestCase): ...@@ -639,7 +640,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][1], 60) self.assertEqual(state[0][1], 60)
self.assertEqual(state[0][3], 120) self.assertEqual(state[0][3], 120)
get_transaction().commit() transaction.commit()
# In the other transaction, delete bucket 2. # In the other transaction, delete bucket 2.
b = copy b = copy
...@@ -655,7 +656,7 @@ class NastyConfict(Base, TestCase): ...@@ -655,7 +656,7 @@ class NastyConfict(Base, TestCase):
self.assertEqual(state[0][1], 60) self.assertEqual(state[0][1], 60)
# This shouldn't create a ConflictError. # This shouldn't create a ConflictError.
get_transaction().commit() transaction.commit()
# And the resulting BTree shouldn't have internal damage. # And the resulting BTree shouldn't have internal damage.
b._check() b._check()
...@@ -685,7 +686,7 @@ class NastyConfict(Base, TestCase): ...@@ -685,7 +686,7 @@ class NastyConfict(Base, TestCase):
self.openDB() self.openDB()
r1 = self.db.open().root() r1 = self.db.open().root()
r1["t"] = self.t r1["t"] = self.t
get_transaction().commit() transaction.commit()
r2 = self.db.open(synch=False).root() r2 = self.db.open(synch=False).root()
copy = r2["t"] copy = r2["t"]
...@@ -699,16 +700,16 @@ class NastyConfict(Base, TestCase): ...@@ -699,16 +700,16 @@ class NastyConfict(Base, TestCase):
for k in range(200, 300, 4): for k in range(200, 300, 4):
self.t[k] = k self.t[k] = k
get_transaction().commit() transaction.commit()
for k in range(0, 60, 4): for k in range(0, 60, 4):
del copy[k] del copy[k]
try: try:
get_transaction().commit() transaction.commit()
except ConflictError, detail: except ConflictError, detail:
self.assert_(str(detail).startswith('database conflict error')) self.assert_(str(detail).startswith('database conflict error'))
get_transaction().abort() transaction.abort()
else: else:
self.fail("expected ConflictError") self.fail("expected ConflictError")
......
...@@ -15,11 +15,12 @@ ...@@ -15,11 +15,12 @@
import unittest import unittest
from BTrees.OOBTree import OOBucket as Bucket, OOSet as Set
import transaction
from ZODB.MappingStorage import MappingStorage from ZODB.MappingStorage import MappingStorage
from ZODB.DB import DB from ZODB.DB import DB
from BTrees.OOBTree import OOBucket as Bucket, OOSet as Set
class CompareTest(unittest.TestCase): class CompareTest(unittest.TestCase):
s = "A string with hi-bit-set characters: \700\701" s = "A string with hi-bit-set characters: \700\701"
...@@ -35,7 +36,7 @@ class CompareTest(unittest.TestCase): ...@@ -35,7 +36,7 @@ class CompareTest(unittest.TestCase):
root = self.db.open().root() root = self.db.open().root()
self.bucket = root["bucket"] = Bucket() self.bucket = root["bucket"] = Bucket()
self.set = root["set"] = Set() self.set = root["set"] = Set()
get_transaction().commit() transaction.commit()
def tearDown(self): def tearDown(self):
self.assert_(self.bucket._p_changed != 2) self.assert_(self.bucket._p_changed != 2)
......
...@@ -39,7 +39,7 @@ from ZODB.POSException \ ...@@ -39,7 +39,7 @@ from ZODB.POSException \
# of obscure timing-related bugs in cache consistency logic, revealed # of obscure timing-related bugs in cache consistency logic, revealed
# by failure of the BTree to pass internal consistency checks at the end, # by failure of the BTree to pass internal consistency checks at the end,
# and/or by failure of the BTree to contain all the keys the threads # and/or by failure of the BTree to contain all the keys the threads
# thought they added (i.e., the keys for which get_transaction().commit() # thought they added (i.e., the keys for which transaction.commit()
# did not raise any exception). # did not raise any exception).
class FailableThread(TestThread): class FailableThread(TestThread):
...@@ -151,19 +151,19 @@ class StressThread(FailableThread): ...@@ -151,19 +151,19 @@ class StressThread(FailableThread):
tree = cn.root()["tree"] tree = cn.root()["tree"]
break break
except (ConflictError, KeyError): except (ConflictError, KeyError):
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
key = self.startnum key = self.startnum
while not self.stop.isSet(): while not self.stop.isSet():
try: try:
tree[key] = self.threadnum tree[key] = self.threadnum
get_transaction().note("add key %s" % key) transaction.get().note("add key %s" % key)
get_transaction().commit() transaction.commit()
self.commitdict[self] = 1 self.commitdict[self] = 1
if self.sleep: if self.sleep:
time.sleep(self.sleep) time.sleep(self.sleep)
except (ReadConflictError, ConflictError), msg: except (ReadConflictError, ConflictError), msg:
get_transaction().abort() transaction.abort()
# sync() is necessary here to process invalidations # sync() is necessary here to process invalidations
# if we get a read conflict. In the read conflict case, # if we get a read conflict. In the read conflict case,
# no objects were modified so cn never got registered # no objects were modified so cn never got registered
...@@ -209,7 +209,7 @@ class LargeUpdatesThread(FailableThread): ...@@ -209,7 +209,7 @@ class LargeUpdatesThread(FailableThread):
break break
except (ConflictError, KeyError): except (ConflictError, KeyError):
# print "%d getting tree abort" % self.threadnum # print "%d getting tree abort" % self.threadnum
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
keys_added = {} # set of keys we commit keys_added = {} # set of keys we commit
...@@ -231,20 +231,20 @@ class LargeUpdatesThread(FailableThread): ...@@ -231,20 +231,20 @@ class LargeUpdatesThread(FailableThread):
tree[key] = self.threadnum tree[key] = self.threadnum
except (ReadConflictError, ConflictError), msg: except (ReadConflictError, ConflictError), msg:
# print "%d setting key %s" % (self.threadnum, msg) # print "%d setting key %s" % (self.threadnum, msg)
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
break break
else: else:
# print "%d set #%d" % (self.threadnum, len(keys)) # print "%d set #%d" % (self.threadnum, len(keys))
get_transaction().note("keys %s" % ", ".join(map(str, keys))) transaction.get().note("keys %s" % ", ".join(map(str, keys)))
try: try:
get_transaction().commit() transaction.commit()
self.commitdict[self] = 1 self.commitdict[self] = 1
if self.sleep: if self.sleep:
time.sleep(self.sleep) time.sleep(self.sleep)
except ConflictError, msg: except ConflictError, msg:
# print "%d commit %s" % (self.threadnum, msg) # print "%d commit %s" % (self.threadnum, msg)
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
continue continue
for k in keys: for k in keys:
...@@ -304,17 +304,17 @@ class VersionStressThread(FailableThread): ...@@ -304,17 +304,17 @@ class VersionStressThread(FailableThread):
tree = cn.root()["tree"] tree = cn.root()["tree"]
break break
except (ConflictError, KeyError): except (ConflictError, KeyError):
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
while not self.stop.isSet(): while not self.stop.isSet():
try: try:
tree[key] = self.threadnum tree[key] = self.threadnum
get_transaction().commit() transaction.commit()
if self.sleep: if self.sleep:
time.sleep(self.sleep) time.sleep(self.sleep)
break break
except (VersionLockError, ReadConflictError, ConflictError), msg: except (VersionLockError, ReadConflictError, ConflictError), msg:
get_transaction().abort() transaction.abort()
# sync() is necessary here to process invalidations # sync() is necessary here to process invalidations
# if we get a read conflict. In the read conflict case, # if we get a read conflict. In the read conflict case,
# no objects were modified so cn never got registered # no objects were modified so cn never got registered
...@@ -327,16 +327,16 @@ class VersionStressThread(FailableThread): ...@@ -327,16 +327,16 @@ class VersionStressThread(FailableThread):
try: try:
if commit: if commit:
self.db.commitVersion(version) self.db.commitVersion(version)
get_transaction().note("commit version %s" % version) transaction.get().note("commit version %s" % version)
else: else:
self.db.abortVersion(version) self.db.abortVersion(version)
get_transaction().note("abort version %s" % version) transaction.get().note("abort version %s" % version)
get_transaction().commit() transaction.commit()
if self.sleep: if self.sleep:
time.sleep(self.sleep) time.sleep(self.sleep)
return commit return commit
except ConflictError, msg: except ConflictError, msg:
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
finally: finally:
cn.close() cn.close()
...@@ -368,7 +368,7 @@ class InvalidationTests: ...@@ -368,7 +368,7 @@ class InvalidationTests:
tree._check() tree._check()
except ReadConflictError: except ReadConflictError:
if retries: if retries:
get_transaction().abort() transaction.abort()
cn.sync() cn.sync()
else: else:
raise raise
...@@ -427,7 +427,7 @@ class InvalidationTests: ...@@ -427,7 +427,7 @@ class InvalidationTests:
cn = db1.open() cn = db1.open()
tree = cn.root()["tree"] = OOBTree() tree = cn.root()["tree"] = OOBTree()
get_transaction().commit() transaction.commit()
# DM: allow time for invalidations to come in and process them # DM: allow time for invalidations to come in and process them
time.sleep(0.1) time.sleep(0.1)
...@@ -453,7 +453,7 @@ class InvalidationTests: ...@@ -453,7 +453,7 @@ class InvalidationTests:
cn = db1.open() cn = db1.open()
tree = cn.root()["tree"] = OOBTree() tree = cn.root()["tree"] = OOBTree()
get_transaction().commit() transaction.commit()
cn.close() cn.close()
# Run two threads that update the BTree # Run two threads that update the BTree
...@@ -482,7 +482,7 @@ class InvalidationTests: ...@@ -482,7 +482,7 @@ class InvalidationTests:
cn = db1.open() cn = db1.open()
tree = cn.root()["tree"] = OOBTree() tree = cn.root()["tree"] = OOBTree()
get_transaction().commit() transaction.commit()
cn.close() cn.close()
# Run two threads that update the BTree # Run two threads that update the BTree
...@@ -507,7 +507,7 @@ class InvalidationTests: ...@@ -507,7 +507,7 @@ class InvalidationTests:
cn = db1.open() cn = db1.open()
tree = cn.root()["tree"] = OOBTree() tree = cn.root()["tree"] = OOBTree()
get_transaction().commit() transaction.commit()
cn.close() cn.close()
# Run three threads that update the BTree. # Run three threads that update the BTree.
...@@ -543,7 +543,7 @@ class InvalidationTests: ...@@ -543,7 +543,7 @@ class InvalidationTests:
cn = db1.open() cn = db1.open()
tree = cn.root()["tree"] = OOBTree() tree = cn.root()["tree"] = OOBTree()
get_transaction().commit() transaction.commit()
cn.close() cn.close()
# Run three threads that update the BTree. # Run three threads that update the BTree.
...@@ -582,7 +582,7 @@ class InvalidationTests: ...@@ -582,7 +582,7 @@ class InvalidationTests:
tree = cn.root()["tree"] = OOBTree() tree = cn.root()["tree"] = OOBTree()
for i in range(0, 3000, 2): for i in range(0, 3000, 2):
tree[i] = 0 tree[i] = 0
get_transaction().commit() transaction.commit()
cn.close() cn.close()
# Run three threads that update the BTree. # Run three threads that update the BTree.
...@@ -608,7 +608,7 @@ class InvalidationTests: ...@@ -608,7 +608,7 @@ class InvalidationTests:
losers = [k for k, v in tree.items() if v == 0] losers = [k for k, v in tree.items() if v == 0]
for k in losers: for k in losers:
del tree[k] del tree[k]
get_transaction().commit() transaction.commit()
self._check_threads(tree, t1, t2, t3) self._check_threads(tree, t1, t2, t3)
......
...@@ -25,7 +25,7 @@ def main(): ...@@ -25,7 +25,7 @@ def main():
update(r1, r2) update(r1, r2)
except ConflictError, msg: except ConflictError, msg:
print msg print msg
get_transaction().abort() transaction.abort()
c1.sync() c1.sync()
c2.sync() c2.sync()
except (ClientDisconnected, DisconnectedError), err: except (ClientDisconnected, DisconnectedError), err:
...@@ -41,7 +41,7 @@ def update(r1, r2): ...@@ -41,7 +41,7 @@ def update(r1, r2):
random.shuffle(updates) random.shuffle(updates)
for key, root in updates: for key, root in updates:
root[key] = time.time() root[key] = time.time()
get_transaction().commit() transaction.commit()
print os.getpid(), k1, k2 print os.getpid(), k1, k2
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import ZODB, ZODB.DB, ZODB.FileStorage, ZODB.POSException import ZODB, ZODB.DB, ZODB.FileStorage, ZODB.POSException
import persistent import persistent
import persistent.mapping import persistent.mapping
import transaction
from ZEO.tests import forker from ZEO.tests import forker
import os import os
...@@ -57,7 +58,7 @@ def init_storage(): ...@@ -57,7 +58,7 @@ def init_storage():
db = ZODB.DB(fs) db = ZODB.DB(fs)
root = db.open().root() root = db.open().root()
root["multi"] = persistent.mapping.PersistentMapping() root["multi"] = persistent.mapping.PersistentMapping()
get_transaction().commit() transaction.commit()
return fs return fs
...@@ -95,9 +96,9 @@ def run(storage): ...@@ -95,9 +96,9 @@ def run(storage):
while 1: while 1:
try: try:
s = root[pid] = Stats() s = root[pid] = Stats()
get_transaction().commit() transaction.commit()
except ZODB.POSException.ConflictError: except ZODB.POSException.ConflictError:
get_transaction().abort() transaction.abort()
time.sleep(CONFLICT_DELAY) time.sleep(CONFLICT_DELAY)
else: else:
break break
...@@ -111,16 +112,16 @@ def run(storage): ...@@ -111,16 +112,16 @@ def run(storage):
r = dict[size] = Record(pid, size) r = dict[size] = Record(pid, size)
if prev: if prev:
prev.set_next(r) prev.set_next(r)
get_transaction().commit() transaction.commit()
except ZODB.POSException.ConflictError, err: except ZODB.POSException.ConflictError, err:
get_transaction().abort() transaction.abort()
time.sleep(CONFLICT_DELAY) time.sleep(CONFLICT_DELAY)
else: else:
i = i + 1 i = i + 1
if VERBOSE and (i < 5 or i % 10 == 0): if VERBOSE and (i < 5 or i % 10 == 0):
print "Client %s: %s of %s" % (pid, i, RECORDS_PER_CLIENT) print "Client %s: %s of %s" % (pid, i, RECORDS_PER_CLIENT)
s.done() s.done()
get_transaction().commit() transaction.commit()
print "Client completed:", pid print "Client completed:", pid
......
...@@ -45,10 +45,11 @@ import asyncore ...@@ -45,10 +45,11 @@ import asyncore
import sys, os, getopt, time import sys, os, getopt, time
##sys.path.insert(0, os.getcwd()) ##sys.path.insert(0, os.getcwd())
import ZODB
import persistent import persistent
from ZEO.tests import forker import transaction
import ZODB
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
from ZEO.tests import forker
class P(persistent.Persistent): class P(persistent.Persistent):
pass pass
...@@ -84,7 +85,7 @@ def work(db, results, nrep, compress, data, detailed, minimize, threadno=None): ...@@ -84,7 +85,7 @@ def work(db, results, nrep, compress, data, detailed, minimize, threadno=None):
jar = db.open() jar = db.open()
while 1: while 1:
try: try:
get_transaction().begin() transaction.begin()
rt = jar.root() rt = jar.root()
key = 's%s' % r key = 's%s' % r
if rt.has_key(key): if rt.has_key(key):
...@@ -98,7 +99,7 @@ def work(db, results, nrep, compress, data, detailed, minimize, threadno=None): ...@@ -98,7 +99,7 @@ def work(db, results, nrep, compress, data, detailed, minimize, threadno=None):
else: else:
v.d = data v.d = data
setattr(p, str(i), v) setattr(p, str(i), v)
get_transaction().commit() transaction.commit()
except ConflictError: except ConflictError:
conflicts = conflicts + 1 conflicts = conflicts + 1
else: else:
......
...@@ -18,11 +18,12 @@ multiple connections. ...@@ -18,11 +18,12 @@ multiple connections.
""" """
# XXX This code is currently broken. # XXX This code is currently broken.
import transaction
import ZODB import ZODB
from ZEO.ClientStorage import ClientStorage
from ZODB.MappingStorage import MappingStorage from ZODB.MappingStorage import MappingStorage
from ZEO.tests import forker
from ZODB.tests import MinPO from ZODB.tests import MinPO
from ZEO.ClientStorage import ClientStorage
from ZEO.tests import forker
import os import os
import random import random
...@@ -59,7 +60,7 @@ def setup(cn): ...@@ -59,7 +60,7 @@ def setup(cn):
o = MinPO.MinPO(prev) o = MinPO.MinPO(prev)
prev = o prev = o
root[an_object()] = o root[an_object()] = o
get_transaction().commit() transaction.commit()
cn.close() cn.close()
def work(cn): def work(cn):
...@@ -71,7 +72,7 @@ def work(cn): ...@@ -71,7 +72,7 @@ def work(cn):
while not isinstance(obj.value, types.StringType): while not isinstance(obj.value, types.StringType):
obj = obj.value obj = obj.value
obj.value = an_object() obj.value = an_object()
get_transaction().commit() transaction.commit()
def main(): def main():
# Yuck! Need to cleanup forker so that the API is consistent # Yuck! Need to cleanup forker so that the API is consistent
......
...@@ -55,7 +55,8 @@ class BasicStorage: ...@@ -55,7 +55,8 @@ class BasicStorage:
assert 0, "Should have failed, invalid transaction." assert 0, "Should have failed, invalid transaction."
try: try:
self._storage.commitVersion('dummy', 'dummer', transaction.Transaction()) self._storage.commitVersion('dummy', 'dummer',
transaction.Transaction())
except (POSException.StorageTransactionError, except (POSException.StorageTransactionError,
POSException.VersionCommitError): POSException.VersionCommitError):
pass # test passed ;) pass # test passed ;)
......
...@@ -72,7 +72,7 @@ class ZODBClientThread(TestThread): ...@@ -72,7 +72,7 @@ class ZODBClientThread(TestThread):
def commit(self, d, num): def commit(self, d, num):
d[num] = time.time() d[num] = time.time()
time.sleep(self.delay) time.sleep(self.delay)
get_transaction().commit() transaction.commit()
time.sleep(self.delay) time.sleep(self.delay)
def get_thread_dict(self, root): def get_thread_dict(self, root):
...@@ -82,16 +82,16 @@ class ZODBClientThread(TestThread): ...@@ -82,16 +82,16 @@ class ZODBClientThread(TestThread):
try: try:
m = PersistentMapping() m = PersistentMapping()
root[name] = m root[name] = m
get_transaction().commit() transaction.commit()
break break
except ConflictError, err: except ConflictError, err:
get_transaction().abort() transaction.abort()
root._p_jar.sync() root._p_jar.sync()
for i in range(10): for i in range(10):
try: try:
return root.get(name) return root.get(name)
except ConflictError: except ConflictError:
get_transaction().abort() transaction.abort()
class StorageClientThread(TestThread): class StorageClientThread(TestThread):
......
...@@ -27,9 +27,10 @@ except ImportError: ...@@ -27,9 +27,10 @@ except ImportError:
import time import time
from ZODB import DB
from persistent import Persistent from persistent import Persistent
from persistent.mapping import PersistentMapping from persistent.mapping import PersistentMapping
import transaction
from ZODB import DB
from ZODB.serialize import referencesf from ZODB.serialize import referencesf
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import snooze from ZODB.tests.StorageTestBase import snooze
...@@ -164,7 +165,7 @@ class PackableStorage(PackableStorageBase): ...@@ -164,7 +165,7 @@ class PackableStorage(PackableStorageBase):
for i in range(10): for i in range(10):
root[i] = MinPO(i) root[i] = MinPO(i)
get_transaction().commit() transaction.commit()
snooze() snooze()
packt = time.time() packt = time.time()
...@@ -173,7 +174,7 @@ class PackableStorage(PackableStorageBase): ...@@ -173,7 +174,7 @@ class PackableStorage(PackableStorageBase):
for dummy in choices: for dummy in choices:
for i in choices: for i in choices:
root[i].value = MinPO(i) root[i].value = MinPO(i)
get_transaction().commit() transaction.commit()
# How many client threads should we run, and how long should we # How many client threads should we run, and how long should we
# wait for them to finish? Hard to say. Running 4 threads and # wait for them to finish? Hard to say. Running 4 threads and
...@@ -274,7 +275,7 @@ class PackableStorage(PackableStorageBase): ...@@ -274,7 +275,7 @@ class PackableStorage(PackableStorageBase):
choices = range(10) choices = range(10)
for i in choices: for i in choices:
root[i] = MinPO(i) root[i] = MinPO(i)
get_transaction().commit() transaction.commit()
snooze() snooze()
packt = time.time() packt = time.time()
...@@ -282,7 +283,7 @@ class PackableStorage(PackableStorageBase): ...@@ -282,7 +283,7 @@ class PackableStorage(PackableStorageBase):
for dummy in choices: for dummy in choices:
for i in choices: for i in choices:
root[i].value = MinPO(i) root[i].value = MinPO(i)
get_transaction().commit() transaction.commit()
NUM_LOOP_TRIP = 100 NUM_LOOP_TRIP = 100
timer = ElapsedTimer(time.time()) timer = ElapsedTimer(time.time())
...@@ -500,7 +501,7 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -500,7 +501,7 @@ class PackableUndoStorage(PackableStorageBase):
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
txn = get_transaction() txn = transaction.get()
txn.note('root') txn.note('root')
txn.commit() txn.commit()
...@@ -512,12 +513,12 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -512,12 +513,12 @@ class PackableUndoStorage(PackableStorageBase):
obj.value = 7 obj.value = 7
root['obj'] = obj root['obj'] = obj
txn = get_transaction() txn = transaction.get()
txn.note('root -> o1') txn.note('root -> o1')
txn.commit() txn.commit()
del root['obj'] del root['obj']
txn = get_transaction() txn = transaction.get()
txn.note('root -x-> o1') txn.note('root -x-> o1')
txn.commit() txn.commit()
...@@ -526,7 +527,7 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -526,7 +527,7 @@ class PackableUndoStorage(PackableStorageBase):
log = self._storage.undoLog() log = self._storage.undoLog()
tid = log[0]['id'] tid = log[0]['id']
db.undo(tid) db.undo(tid)
txn = get_transaction() txn = transaction.get()
txn.note('undo root -x-> o1') txn.note('undo root -x-> o1')
txn.commit() txn.commit()
...@@ -552,19 +553,19 @@ class PackableUndoStorage(PackableStorageBase): ...@@ -552,19 +553,19 @@ class PackableUndoStorage(PackableStorageBase):
root = conn.root() root = conn.root()
root["d"] = d = PersistentMapping() root["d"] = d = PersistentMapping()
get_transaction().commit() transaction.commit()
snooze() snooze()
obj = d["obj"] = C() obj = d["obj"] = C()
obj.value = 1 obj.value = 1
get_transaction().commit() transaction.commit()
snooze() snooze()
packt1 = time.time() packt1 = time.time()
lost_oid = obj._p_oid lost_oid = obj._p_oid
obj = d["anotherobj"] = C() obj = d["anotherobj"] = C()
obj.value = 2 obj.value = 2
get_transaction().commit() transaction.commit()
snooze() snooze()
packt2 = time.time() packt2 = time.time()
...@@ -682,13 +683,13 @@ class ClientThread(TestThread): ...@@ -682,13 +683,13 @@ class ClientThread(TestThread):
alist.extend([self.millis(), index]) alist.extend([self.millis(), index])
self.root[index].value = MinPO(j) self.root[index].value = MinPO(j)
assign_worked = True assign_worked = True
get_transaction().commit() transaction.commit()
alist.append(self.millis()) alist.append(self.millis())
alist.append('OK') alist.append('OK')
except ConflictError: except ConflictError:
alist.append(self.millis()) alist.append(self.millis())
alist.append('Conflict') alist.append('Conflict')
get_transaction().abort() transaction.abort()
alist.append(assign_worked) alist.append(assign_worked)
class ElapsedTimer: class ElapsedTimer:
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
############################################################################## ##############################################################################
"""More recovery and iterator tests.""" """More recovery and iterator tests."""
import transaction
from transaction import Transaction from transaction import Transaction
from ZODB.tests.IteratorStorage import IteratorDeepCompare from ZODB.tests.IteratorStorage import IteratorDeepCompare
from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle, snooze from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle, snooze
...@@ -134,9 +135,9 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -134,9 +135,9 @@ class RecoveryStorage(IteratorDeepCompare):
c = db.open() c = db.open()
r = c.root() r = c.root()
obj = r["obj1"] = MinPO(1) obj = r["obj1"] = MinPO(1)
get_transaction().commit() transaction.commit()
obj = r["obj2"] = MinPO(1) obj = r["obj2"] = MinPO(1)
get_transaction().commit() transaction.commit()
self._dst.copyTransactionsFrom(self._storage) self._dst.copyTransactionsFrom(self._storage)
self._dst.pack(time.time(), referencesf) self._dst.pack(time.time(), referencesf)
...@@ -161,15 +162,15 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -161,15 +162,15 @@ class RecoveryStorage(IteratorDeepCompare):
conn = db.open() conn = db.open()
root = conn.root() root = conn.root()
root.obj = obj1 = MinPO(1) root.obj = obj1 = MinPO(1)
txn = get_transaction() txn = transaction.get()
txn.note('root -> obj') txn.note('root -> obj')
txn.commit() txn.commit()
root.obj.obj = obj2 = MinPO(2) root.obj.obj = obj2 = MinPO(2)
txn = get_transaction() txn = transaction.get()
txn.note('root -> obj -> obj') txn.note('root -> obj -> obj')
txn.commit() txn.commit()
del root.obj del root.obj
txn = get_transaction() txn = transaction.get()
txn.note('root -X->') txn.note('root -X->')
txn.commit() txn.commit()
# Now copy the transactions to the destination # Now copy the transactions to the destination
......
...@@ -20,6 +20,7 @@ import time ...@@ -20,6 +20,7 @@ import time
import types import types
from persistent import Persistent from persistent import Persistent
import transaction
from transaction import Transaction from transaction import Transaction
from ZODB import POSException from ZODB import POSException
...@@ -468,7 +469,7 @@ class TransactionalUndoStorage: ...@@ -468,7 +469,7 @@ class TransactionalUndoStorage:
o2 = C() o2 = C()
root['obj'] = o1 root['obj'] = o1
o1.obj = o2 o1.obj = o2
txn = get_transaction() txn = transaction.get()
txn.note('o1 -> o2') txn.note('o1 -> o2')
txn.commit() txn.commit()
now = packtime = time.time() now = packtime = time.time()
...@@ -477,12 +478,12 @@ class TransactionalUndoStorage: ...@@ -477,12 +478,12 @@ class TransactionalUndoStorage:
o3 = C() o3 = C()
o2.obj = o3 o2.obj = o3
txn = get_transaction() txn = transaction.get()
txn.note('o1 -> o2 -> o3') txn.note('o1 -> o2 -> o3')
txn.commit() txn.commit()
o1.obj = o3 o1.obj = o3
txn = get_transaction() txn = transaction.get()
txn.note('o1 -> o3') txn.note('o1 -> o3')
txn.commit() txn.commit()
...@@ -500,7 +501,7 @@ class TransactionalUndoStorage: ...@@ -500,7 +501,7 @@ class TransactionalUndoStorage:
tid = log[0]['id'] tid = log[0]['id']
db.undo(tid) db.undo(tid)
txn = get_transaction() txn = transaction.get()
txn.note('undo') txn.note('undo')
txn.commit() txn.commit()
# undo does a txn-undo, but doesn't invalidate # undo does a txn-undo, but doesn't invalidate
...@@ -527,14 +528,14 @@ class TransactionalUndoStorage: ...@@ -527,14 +528,14 @@ class TransactionalUndoStorage:
root["key0"] = MinPO(0) root["key0"] = MinPO(0)
root["key1"] = MinPO(1) root["key1"] = MinPO(1)
root["key2"] = MinPO(2) root["key2"] = MinPO(2)
txn = get_transaction() txn = transaction.get()
txn.note("create 3 keys") txn.note("create 3 keys")
txn.commit() txn.commit()
set_pack_time() set_pack_time()
del root["key1"] del root["key1"]
txn = get_transaction() txn = transaction.get()
txn.note("delete 1 key") txn.note("delete 1 key")
txn.commit() txn.commit()
...@@ -546,7 +547,7 @@ class TransactionalUndoStorage: ...@@ -546,7 +547,7 @@ class TransactionalUndoStorage:
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = get_transaction() txn = transaction.get()
txn.note("undo deletion") txn.note("undo deletion")
txn.commit() txn.commit()
...@@ -574,11 +575,11 @@ class TransactionalUndoStorage: ...@@ -574,11 +575,11 @@ class TransactionalUndoStorage:
rt = cn.root() rt = cn.root()
rt["test"] = MinPO(1) rt["test"] = MinPO(1)
get_transaction().commit() transaction.commit()
rt["test2"] = MinPO(2) rt["test2"] = MinPO(2)
get_transaction().commit() transaction.commit()
rt["test"] = MinPO(3) rt["test"] = MinPO(3)
txn = get_transaction() txn = transaction.get()
txn.note("root of undo") txn.note("root of undo")
txn.commit() txn.commit()
...@@ -586,7 +587,7 @@ class TransactionalUndoStorage: ...@@ -586,7 +587,7 @@ class TransactionalUndoStorage:
for i in range(10): for i in range(10):
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = get_transaction() txn = transaction.get()
txn.note("undo %d" % i) txn.note("undo %d" % i)
txn.commit() txn.commit()
rt._p_deactivate() rt._p_deactivate()
...@@ -706,7 +707,7 @@ class TransactionalUndoStorage: ...@@ -706,7 +707,7 @@ class TransactionalUndoStorage:
def checkUndoLogMetadata(self): def checkUndoLogMetadata(self):
# test that the metadata is correct in the undo log # test that the metadata is correct in the undo log
t = get_transaction() t = transaction.get()
t.note('t1') t.note('t1')
t.setExtendedInfo('k2','this is transaction metadata') t.setExtendedInfo('k2','this is transaction metadata')
t.setUser('u3',path='p3') t.setUser('u3',path='p3')
...@@ -715,7 +716,7 @@ class TransactionalUndoStorage: ...@@ -715,7 +716,7 @@ class TransactionalUndoStorage:
root = conn.root() root = conn.root()
o1 = C() o1 = C()
root['obj'] = o1 root['obj'] = o1
txn = get_transaction() txn = transaction.get()
txn.commit() txn.commit()
l = self._storage.undoLog() l = self._storage.undoLog()
self.assertEqual(len(l),2) self.assertEqual(len(l),2)
......
...@@ -18,6 +18,7 @@ Any storage that supports versions should be able to pass all these tests. ...@@ -18,6 +18,7 @@ Any storage that supports versions should be able to pass all these tests.
import time import time
import transaction
from transaction import Transaction from transaction import Transaction
from ZODB import POSException from ZODB import POSException
...@@ -394,12 +395,12 @@ class VersionStorage: ...@@ -394,12 +395,12 @@ class VersionStorage:
obj = root["obj"] = MinPO("obj") obj = root["obj"] = MinPO("obj")
root["obj2"] = MinPO("obj2") root["obj2"] = MinPO("obj2")
txn = get_transaction() txn = transaction.get()
txn.note("create 2 objs in version") txn.note("create 2 objs in version")
txn.commit() txn.commit()
obj.value = "77" obj.value = "77"
txn = get_transaction() txn = transaction.get()
txn.note("modify obj in version") txn.note("modify obj in version")
txn.commit() txn.commit()
...@@ -407,7 +408,7 @@ class VersionStorage: ...@@ -407,7 +408,7 @@ class VersionStorage:
# and versions for pack to chase # and versions for pack to chase
info = db.undoInfo() info = db.undoInfo()
db.undo(info[0]["id"]) db.undo(info[0]["id"])
txn = get_transaction() txn = transaction.get()
txn.note("undo modification") txn.note("undo modification")
txn.commit() txn.commit()
...@@ -415,7 +416,7 @@ class VersionStorage: ...@@ -415,7 +416,7 @@ class VersionStorage:
self._storage.pack(time.time(), referencesf) self._storage.pack(time.time(), referencesf)
db.commitVersion("testversion") db.commitVersion("testversion")
txn = get_transaction() txn = transaction.get()
txn.note("commit version") txn.note("commit version")
txn.commit() txn.commit()
...@@ -423,7 +424,7 @@ class VersionStorage: ...@@ -423,7 +424,7 @@ class VersionStorage:
root = cn.root() root = cn.root()
root["obj"] = "no version" root["obj"] = "no version"
txn = get_transaction() txn = transaction.get()
txn.note("modify obj") txn.note("modify obj")
txn.commit() txn.commit()
...@@ -436,12 +437,12 @@ class VersionStorage: ...@@ -436,12 +437,12 @@ class VersionStorage:
obj = root["obj"] = MinPO("obj") obj = root["obj"] = MinPO("obj")
root["obj2"] = MinPO("obj2") root["obj2"] = MinPO("obj2")
txn = get_transaction() txn = transaction.get()
txn.note("create 2 objs in version") txn.note("create 2 objs in version")
txn.commit() txn.commit()
obj.value = "77" obj.value = "77"
txn = get_transaction() txn = transaction.get()
txn.note("modify obj in version") txn.note("modify obj in version")
txn.commit() txn.commit()
...@@ -452,14 +453,14 @@ class VersionStorage: ...@@ -452,14 +453,14 @@ class VersionStorage:
# and versions for pack to chase # and versions for pack to chase
info = db.undoInfo() info = db.undoInfo()
db.undo(info[0]["id"]) db.undo(info[0]["id"])
txn = get_transaction() txn = transaction.get()
txn.note("undo modification") txn.note("undo modification")
txn.commit() txn.commit()
self._storage.pack(t0, referencesf) self._storage.pack(t0, referencesf)
db.commitVersion("testversion") db.commitVersion("testversion")
txn = get_transaction() txn = transaction.get()
txn.note("commit version") txn.note("commit version")
txn.commit() txn.commit()
...@@ -467,7 +468,7 @@ class VersionStorage: ...@@ -467,7 +468,7 @@ class VersionStorage:
root = cn.root() root = cn.root()
root["obj"] = "no version" root["obj"] = "no version"
txn = get_transaction() txn = transaction.get()
txn.note("modify obj") txn.note("modify obj")
txn.commit() txn.commit()
...@@ -482,18 +483,18 @@ class VersionStorage: ...@@ -482,18 +483,18 @@ class VersionStorage:
for name in names: for name in names:
root[name] = MinPO(name) root[name] = MinPO(name)
get_transaction().commit() transaction.commit()
for name in names: for name in names:
cn2 = db.open(version=name) cn2 = db.open(version=name)
rt2 = cn2.root() rt2 = cn2.root()
obj = rt2[name] obj = rt2[name]
obj.value = MinPO("version") obj.value = MinPO("version")
get_transaction().commit() transaction.commit()
cn2.close() cn2.close()
root["d"] = MinPO("d") root["d"] = MinPO("d")
get_transaction().commit() transaction.commit()
snooze() snooze()
self._storage.pack(time.time(), referencesf) self._storage.pack(time.time(), referencesf)
...@@ -511,11 +512,11 @@ class VersionStorage: ...@@ -511,11 +512,11 @@ class VersionStorage:
obj = rt2[name].value obj = rt2[name].value
self.assertEqual(obj.value, "version") self.assertEqual(obj.value, "version")
obj.value = "still version" obj.value = "still version"
get_transaction().commit() transaction.commit()
cn2.close() cn2.close()
db.abortVersion("b") db.abortVersion("b")
txn = get_transaction() txn = transaction.get()
txn.note("abort version b") txn.note("abort version b")
txn.commit() txn.commit()
...@@ -524,7 +525,7 @@ class VersionStorage: ...@@ -524,7 +525,7 @@ class VersionStorage:
L = db.undoInfo() L = db.undoInfo()
db.undo(L[0]["id"]) db.undo(L[0]["id"])
txn = get_transaction() txn = transaction.get()
txn.note("undo abort") txn.note("undo abort")
txn.commit() txn.commit()
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
import time import time
import transaction
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB import DB from ZODB import DB
...@@ -30,20 +31,20 @@ def create_dangling_ref(db): ...@@ -30,20 +31,20 @@ def create_dangling_ref(db):
rt = db.open().root() rt = db.open().root()
rt[1] = o1 = P() rt[1] = o1 = P()
get_transaction().note("create o1") transaction.get().note("create o1")
get_transaction().commit() transaction.commit()
rt[2] = o2 = P() rt[2] = o2 = P()
get_transaction().note("create o2") transaction.get().note("create o2")
get_transaction().commit() transaction.commit()
c = o1.child = P() c = o1.child = P()
get_transaction().note("set child on o1") transaction.get().note("set child on o1")
get_transaction().commit() transaction.commit()
o1.child = P() o1.child = P()
get_transaction().note("replace child on o1") transaction.get().note("replace child on o1")
get_transaction().commit() transaction.commit()
time.sleep(2) time.sleep(2)
# The pack should remove the reference to c, because it is no # The pack should remove the reference to c, because it is no
...@@ -53,8 +54,8 @@ def create_dangling_ref(db): ...@@ -53,8 +54,8 @@ def create_dangling_ref(db):
print repr(c._p_oid) print repr(c._p_oid)
o2.child = c o2.child = c
get_transaction().note("set child on o2") transaction.get().note("set child on o2")
get_transaction().commit() transaction.commit()
def main(): def main():
fs = FileStorage("dangle.fs") fs = FileStorage("dangle.fs")
......
...@@ -40,6 +40,7 @@ sys.path.insert(0, os.getcwd()) ...@@ -40,6 +40,7 @@ sys.path.insert(0, os.getcwd())
import ZODB, ZODB.FileStorage import ZODB, ZODB.FileStorage
import persistent import persistent
import transaction
class P(persistent.Persistent): pass class P(persistent.Persistent): pass
...@@ -85,7 +86,7 @@ def main(args): ...@@ -85,7 +86,7 @@ def main(args):
for r in 1, 10, 100, 1000: for r in 1, 10, 100, 1000:
t=time.time() t=time.time()
jar=db.open() jar=db.open()
get_transaction().begin() transaction.begin()
rt=jar.root() rt=jar.root()
key='s%s' % r key='s%s' % r
if rt.has_key(key): p=rt[key] if rt.has_key(key): p=rt[key]
...@@ -96,7 +97,7 @@ def main(args): ...@@ -96,7 +97,7 @@ def main(args):
v=getattr(p, str(i), P()) v=getattr(p, str(i), P())
v.d=d v.d=d
setattr(p,str(i),v) setattr(p,str(i),v)
get_transaction().commit() transaction.commit()
jar.close() jar.close()
t=time.time()-t t=time.time()-t
if detailed: if detailed:
......
...@@ -13,13 +13,13 @@ ...@@ -13,13 +13,13 @@
############################################################################## ##############################################################################
"""Test broken-object suppport """Test broken-object suppport
$Id: testBroken.py,v 1.3 2004/03/04 22:41:53 jim Exp $ $Id: testBroken.py,v 1.4 2004/04/16 15:58:11 jeremy Exp $
""" """
import sys import sys
import unittest import unittest
import persistent import persistent
#from transaction import get_transaction import transaction
from doctest import DocTestSuite from doctest import DocTestSuite
from ZODB.tests.util import DB from ZODB.tests.util import DB
...@@ -46,7 +46,7 @@ def test_integration(): ...@@ -46,7 +46,7 @@ def test_integration():
>>> a.x = 1 >>> a.x = 1
>>> conn1 = db.open() >>> conn1 = db.open()
>>> conn1.root()['a'] = a >>> conn1.root()['a'] = a
>>> get_transaction().commit() >>> transaction.commit()
>>> conn2 = db.open() >>> conn2 = db.open()
>>> a2 = conn2.root()['a'] >>> a2 = conn2.root()['a']
......
...@@ -22,10 +22,11 @@ import gc ...@@ -22,10 +22,11 @@ import gc
import time import time
import unittest import unittest
import ZODB
import ZODB.MappingStorage
from persistent.cPickleCache import PickleCache from persistent.cPickleCache import PickleCache
from persistent.mapping import PersistentMapping from persistent.mapping import PersistentMapping
import transaction
import ZODB
import ZODB.MappingStorage
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.utils import p64 from ZODB.utils import p64
...@@ -60,14 +61,14 @@ class CacheTestBase(unittest.TestCase): ...@@ -60,14 +61,14 @@ class CacheTestBase(unittest.TestCase):
d = r.get(i) d = r.get(i)
if d is None: if d is None:
d = r[i] = PersistentMapping() d = r[i] = PersistentMapping()
get_transaction().commit() transaction.commit()
for i in range(15): for i in range(15):
o = d.get(i) o = d.get(i)
if o is None: if o is None:
o = d[i] = MinPO(i) o = d[i] = MinPO(i)
o.value += 1 o.value += 1
get_transaction().commit() transaction.commit()
class DBMethods(CacheTestBase): class DBMethods(CacheTestBase):
...@@ -145,7 +146,7 @@ class LRUCacheTests(CacheTestBase): ...@@ -145,7 +146,7 @@ class LRUCacheTests(CacheTestBase):
for t in range(5): for t in range(5):
for i in range(dataset_size): for i in range(dataset_size):
l[(t,i)] = r[i] = MinPO(i) l[(t,i)] = r[i] = MinPO(i)
get_transaction().commit() transaction.commit()
# commit() will register the objects, placing them in the # commit() will register the objects, placing them in the
# cache. at the end of commit, the cache will be reduced # cache. at the end of commit, the cache will be reduced
# down to CACHE_SIZE items # down to CACHE_SIZE items
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import tempfile import tempfile
import unittest import unittest
import transaction
import ZODB.config import ZODB.config
from ZODB.POSException import ReadOnlyError from ZODB.POSException import ReadOnlyError
...@@ -34,7 +35,7 @@ class ConfigTestBase(unittest.TestCase): ...@@ -34,7 +35,7 @@ class ConfigTestBase(unittest.TestCase):
cn = db.open() cn = db.open()
rt = cn.root() rt = cn.root()
rt["test"] = 1 rt["test"] = 1
get_transaction().commit() transaction.commit()
db.close() db.close()
......
...@@ -18,10 +18,10 @@ import unittest ...@@ -18,10 +18,10 @@ import unittest
import warnings import warnings
from persistent import Persistent from persistent import Persistent
import transaction
from ZODB.config import databaseFromString from ZODB.config import databaseFromString
from ZODB.utils import p64, u64 from ZODB.utils import p64, u64
from ZODB.tests.warnhook import WarningsHook from ZODB.tests.warnhook import WarningsHook
import transaction
class ConnectionDotAdd(unittest.TestCase): class ConnectionDotAdd(unittest.TestCase):
...@@ -397,7 +397,7 @@ class InvalidationTests(unittest.TestCase): ...@@ -397,7 +397,7 @@ class InvalidationTests(unittest.TestCase):
>>> p3 = Persistent() >>> p3 = Persistent()
>>> r = cn.root() >>> r = cn.root()
>>> r.update(dict(p1=p1, p2=p2, p3=p3)) >>> r.update(dict(p1=p1, p2=p2, p3=p3))
>>> get_transaction().commit() >>> transaction.commit()
Transaction ids are 8-byte strings, just like oids; p64() will Transaction ids are 8-byte strings, just like oids; p64() will
create one from an int. create one from an int.
......
...@@ -16,6 +16,8 @@ import time ...@@ -16,6 +16,8 @@ import time
import unittest import unittest
import warnings import warnings
import transaction
import ZODB import ZODB
import ZODB.FileStorage import ZODB.FileStorage
...@@ -38,10 +40,10 @@ class DBTests(unittest.TestCase): ...@@ -38,10 +40,10 @@ class DBTests(unittest.TestCase):
c = self.db.open(version) c = self.db.open(version)
r = c.root() r = c.root()
o = r[time.time()] = MinPO(0) o = r[time.time()] = MinPO(0)
get_transaction().commit() transaction.commit()
for i in range(25): for i in range(25):
o.value = MinPO(i) o.value = MinPO(i)
get_transaction().commit() transaction.commit()
o = o.value o = o.value
c.close() c.close()
......
...@@ -22,9 +22,10 @@ old code, developers will have a hard time testing the new code. ...@@ -22,9 +22,10 @@ old code, developers will have a hard time testing the new code.
import unittest import unittest
import transaction
from transaction import Transaction
import ZODB import ZODB
from ZODB.MappingStorage import MappingStorage from ZODB.MappingStorage import MappingStorage
from transaction import Transaction
import cPickle import cPickle
import cStringIO import cStringIO
import sys import sys
...@@ -59,7 +60,7 @@ class PMTests(unittest.TestCase): ...@@ -59,7 +60,7 @@ class PMTests(unittest.TestCase):
r[1] = 1 r[1] = 1
r[2] = 2 r[2] = 2
r[3] = r r[3] = r
get_transaction().commit() transaction.commit()
# MappingStorage stores serialno + pickle in its _index. # MappingStorage stores serialno + pickle in its _index.
root_pickle = s._index['\000' * 8][8:] root_pickle = s._index['\000' * 8][8:]
......
...@@ -26,6 +26,7 @@ from ZODB.FileStorage import FileStorage ...@@ -26,6 +26,7 @@ from ZODB.FileStorage import FileStorage
from ZODB.fsrecover import recover from ZODB.fsrecover import recover
from persistent.mapping import PersistentMapping from persistent.mapping import PersistentMapping
import transaction
class RecoverTest(unittest.TestCase): class RecoverTest(unittest.TestCase):
...@@ -58,10 +59,10 @@ class RecoverTest(unittest.TestCase): ...@@ -58,10 +59,10 @@ class RecoverTest(unittest.TestCase):
# looks like a Data.fs > 1MB # looks like a Data.fs > 1MB
for i in range(50): for i in range(50):
d = rt[i] = PersistentMapping() d = rt[i] = PersistentMapping()
get_transaction().commit() transaction.commit()
for j in range(50): for j in range(50):
d[j] = "a" * j d[j] = "a" * j
get_transaction().commit() transaction.commit()
def damage(self, num, size): def damage(self, num, size):
self.storage.close() self.storage.close()
......
...@@ -43,14 +43,14 @@ class ZODBTests(unittest.TestCase): ...@@ -43,14 +43,14 @@ class ZODBTests(unittest.TestCase):
self._db = ZODB.DB(self._storage) self._db = ZODB.DB(self._storage)
def populate(self): def populate(self):
get_transaction().begin() transaction.begin()
conn = self._db.open() conn = self._db.open()
root = conn.root() root = conn.root()
root['test'] = pm = PersistentMapping() root['test'] = pm = PersistentMapping()
for n in range(100): for n in range(100):
pm[n] = PersistentMapping({0: 100 - n}) pm[n] = PersistentMapping({0: 100 - n})
get_transaction().note('created test data') transaction.get().note('created test data')
get_transaction().commit() transaction.commit()
conn.close() conn.close()
def tearDown(self): def tearDown(self):
...@@ -71,8 +71,8 @@ class ZODBTests(unittest.TestCase): ...@@ -71,8 +71,8 @@ class ZODBTests(unittest.TestCase):
conn.close() conn.close()
def duplicate(self, conn, abort_it): def duplicate(self, conn, abort_it):
get_transaction().begin() transaction.begin()
get_transaction().note('duplication') transaction.get().note('duplication')
root = conn.root() root = conn.root()
ob = root['test'] ob = root['test']
assert len(ob) > 10, 'Insufficient test data' assert len(ob) > 10, 'Insufficient test data'
...@@ -87,15 +87,15 @@ class ZODBTests(unittest.TestCase): ...@@ -87,15 +87,15 @@ class ZODBTests(unittest.TestCase):
root['dup'] = new_ob root['dup'] = new_ob
f.close() f.close()
if abort_it: if abort_it:
get_transaction().abort() transaction.abort()
else: else:
get_transaction().commit() transaction.commit()
except: except:
get_transaction().abort() transaction.abort()
raise raise
def verify(self, conn, abort_it): def verify(self, conn, abort_it):
get_transaction().begin() transaction.begin()
root = conn.root() root = conn.root()
ob = root['test'] ob = root['test']
try: try:
...@@ -123,7 +123,7 @@ class ZODBTests(unittest.TestCase): ...@@ -123,7 +123,7 @@ class ZODBTests(unittest.TestCase):
for v in ob2.values(): for v in ob2.values():
assert not oids.has_key(v._p_oid), ( assert not oids.has_key(v._p_oid), (
'Did not fully separate duplicate from original') 'Did not fully separate duplicate from original')
get_transaction().commit() transaction.commit()
def checkExportImportAborted(self): def checkExportImportAborted(self):
self.checkExportImport(abort_it=True) self.checkExportImport(abort_it=True)
...@@ -136,11 +136,11 @@ class ZODBTests(unittest.TestCase): ...@@ -136,11 +136,11 @@ class ZODBTests(unittest.TestCase):
try: try:
r = conn.root() r = conn.root()
r[1] = 1 r[1] = 1
get_transaction().commit() transaction.commit()
finally: finally:
conn.close() conn.close()
self._db.abortVersion("version") self._db.abortVersion("version")
get_transaction().commit() transaction.commit()
def checkResetCache(self): def checkResetCache(self):
# The cache size after a reset should be 0. Note that # The cache size after a reset should be 0. Note that
...@@ -302,7 +302,7 @@ class ZODBTests(unittest.TestCase): ...@@ -302,7 +302,7 @@ class ZODBTests(unittest.TestCase):
real_data["b"] = PersistentMapping({"indexed_value": 1}) real_data["b"] = PersistentMapping({"indexed_value": 1})
index[1] = PersistentMapping({"b": 1}) index[1] = PersistentMapping({"b": 1})
index[0] = PersistentMapping({"a": 1}) index[0] = PersistentMapping({"a": 1})
get_transaction().commit() transaction.commit()
# load some objects from one connection # load some objects from one connection
tm = transaction.TransactionManager() tm = transaction.TransactionManager()
...@@ -314,7 +314,7 @@ class ZODBTests(unittest.TestCase): ...@@ -314,7 +314,7 @@ class ZODBTests(unittest.TestCase):
real_data["b"]["indexed_value"] = 0 real_data["b"]["indexed_value"] = 0
del index[1]["b"] del index[1]["b"]
index[0]["b"] = 1 index[0]["b"] = 1
get_transaction().commit() transaction.commit()
del real_data2["a"] del real_data2["a"]
try: try:
...@@ -334,7 +334,7 @@ class ZODBTests(unittest.TestCase): ...@@ -334,7 +334,7 @@ class ZODBTests(unittest.TestCase):
self.assert_(not index2[1]._p_changed) self.assert_(not index2[1]._p_changed)
self.assertRaises(ConflictError, tm.get().commit) self.assertRaises(ConflictError, tm.get().commit)
get_transaction().abort() transaction.abort()
def checkIndependent(self): def checkIndependent(self):
self.obj = Independent() self.obj = Independent()
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
import doctest import doctest
from persistent import Persistent from persistent import Persistent
import transaction
from ZODB.config import databaseFromString from ZODB.config import databaseFromString
class RecalcitrantObject(Persistent): class RecalcitrantObject(Persistent):
...@@ -67,7 +68,7 @@ class CacheTests: ...@@ -67,7 +68,7 @@ class CacheTests:
... o = RegularObject() ... o = RegularObject()
... L.append(o) ... L.append(o)
... r[i] = o ... r[i] = o
>>> get_transaction().commit() >>> transaction.commit()
After committing a transaction and calling cacheGC(), there After committing a transaction and calling cacheGC(), there
should be cache-size (4) objects in the cache. One of the should be cache-size (4) objects in the cache. One of the
...@@ -137,7 +138,7 @@ class CacheTests: ...@@ -137,7 +138,7 @@ class CacheTests:
... o = RecalcitrantObject() ... o = RecalcitrantObject()
... L.append(o) ... L.append(o)
... r[i] = o ... r[i] = o
>>> get_transaction().commit() >>> transaction.commit()
>>> [o._p_state for o in L] >>> [o._p_state for o in L]
[0, 0, 0, 0, 0] [0, 0, 0, 0, 0]
...@@ -174,7 +175,7 @@ class CacheTests: ...@@ -174,7 +175,7 @@ class CacheTests:
... o = RegularObject() ... o = RegularObject()
... L.append(o) ... L.append(o)
... r[i] = o ... r[i] = o
>>> get_transaction().commit() >>> transaction.commit()
>>> RegularObject.deactivations >>> RegularObject.deactivations
1 1
...@@ -188,7 +189,7 @@ class CacheTests: ...@@ -188,7 +189,7 @@ class CacheTests:
>>> cn._cache.ringlen() >>> cn._cache.ringlen()
5 5
>>> get_transaction().abort() >>> transaction.abort()
>>> cn._cache.ringlen() >>> cn._cache.ringlen()
2 2
>>> RegularObject.deactivations >>> RegularObject.deactivations
......
...@@ -13,11 +13,12 @@ ...@@ -13,11 +13,12 @@
############################################################################## ##############################################################################
"""Conventience function for creating test databases """Conventience function for creating test databases
$Id: util.py,v 1.3 2004/02/19 18:24:00 jeremy Exp $ $Id: util.py,v 1.4 2004/04/16 15:58:11 jeremy Exp $
""" """
import time import time
import persistent import persistent
import transaction
from ZODB.MappingStorage import MappingStorage from ZODB.MappingStorage import MappingStorage
from ZODB.DB import DB as _DB from ZODB.DB import DB as _DB
try: try:
...@@ -29,7 +30,7 @@ def DB(name='Test'): ...@@ -29,7 +30,7 @@ def DB(name='Test'):
return _DB(MappingStorage(name)) return _DB(MappingStorage(name))
def commit(): def commit():
get_transaction().commit() transaction.commit()
def pack(db): def pack(db):
db.pack(time.time()+1) db.pack(time.time()+1)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
from ZODB.POSException import ReadConflictError, ConflictError from ZODB.POSException import ReadConflictError, ConflictError
def _commit(note): def _commit(note):
t = get_transaction() t = transaction.get()
if note: if note:
t.note(note) t.note(note)
t.commit() t.commit()
...@@ -42,14 +42,14 @@ def transact(f, note=None, retries=5): ...@@ -42,14 +42,14 @@ def transact(f, note=None, retries=5):
try: try:
r = f(*args, **kwargs) r = f(*args, **kwargs)
except ReadConflictError, msg: except ReadConflictError, msg:
get_transaction().abort() transaction.abort()
if not n: if not n:
raise raise
continue continue
try: try:
_commit(note) _commit(note)
except ConflictError, msg: except ConflictError, msg:
get_transaction().abort() transaction.abort()
if not n: if not n:
raise raise
continue continue
......
...@@ -16,14 +16,11 @@ ...@@ -16,14 +16,11 @@
This module tests and documents, through example, overriding attribute This module tests and documents, through example, overriding attribute
access methods. access methods.
$Id: test_overriding_attrs.py,v 1.5 2004/03/04 22:41:59 jim Exp $ $Id: test_overriding_attrs.py,v 1.6 2004/04/16 15:58:10 jeremy Exp $
""" """
from persistent import Persistent from persistent import Persistent
try: import transaction
from transaction import get_transaction
except ImportError:
pass # else assume ZODB will install it as a builtin
from ZODB.tests.util import DB from ZODB.tests.util import DB
class SampleOverridingGetattr(Persistent): class SampleOverridingGetattr(Persistent):
...@@ -58,7 +55,7 @@ class SampleOverridingGetattr(Persistent): ...@@ -58,7 +55,7 @@ class SampleOverridingGetattr(Persistent):
>>> db = DB() >>> db = DB()
>>> conn = db.open() >>> conn = db.open()
>>> conn.root()['o'] = o >>> conn.root()['o'] = o
>>> get_transaction().commit() >>> transaction.commit()
>>> o._p_deactivate() >>> o._p_deactivate()
>>> o._p_changed >>> o._p_changed
...@@ -124,7 +121,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent): ...@@ -124,7 +121,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
>>> db = DB() >>> db = DB()
>>> conn = db.open() >>> conn = db.open()
>>> conn.root()['o'] = o >>> conn.root()['o'] = o
>>> get_transaction().commit() >>> transaction.commit()
>>> o._p_deactivate() >>> o._p_deactivate()
>>> o._p_changed >>> o._p_changed
...@@ -229,7 +226,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent): ...@@ -229,7 +226,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
>>> db = DB() >>> db = DB()
>>> conn = db.open() >>> conn = db.open()
>>> conn.root()['o'] = o >>> conn.root()['o'] = o
>>> get_transaction().commit() >>> transaction.commit()
>>> o._p_deactivate() >>> o._p_deactivate()
>>> o._p_changed >>> o._p_changed
...@@ -247,7 +244,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent): ...@@ -247,7 +244,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
Now, if commit: Now, if commit:
>>> get_transaction().commit() >>> transaction.commit()
>>> o._p_changed >>> o._p_changed
0 0
...@@ -329,7 +326,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent): ...@@ -329,7 +326,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
>>> db = DB() >>> db = DB()
>>> conn = db.open() >>> conn = db.open()
>>> conn.root()['o'] = o >>> conn.root()['o'] = o
>>> get_transaction().commit() >>> transaction.commit()
>>> o._p_deactivate() >>> o._p_deactivate()
>>> o._p_changed >>> o._p_changed
...@@ -352,7 +349,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent): ...@@ -352,7 +349,7 @@ class SampleOverridingGetattributeSetattrAndDelattr(Persistent):
Now, if commit: Now, if commit:
>>> get_transaction().commit() >>> transaction.commit()
>>> o._p_changed >>> o._p_changed
0 0
......
...@@ -66,7 +66,7 @@ def check_server(addr, storage, write): ...@@ -66,7 +66,7 @@ def check_server(addr, storage, write):
monitor = root['monitor'] = PersistentMapping() monitor = root['monitor'] = PersistentMapping()
obj = monitor['zeoup'] = monitor.get('zeoup', MinPO(0)) obj = monitor['zeoup'] = monitor.get('zeoup', MinPO(0))
obj.value += 1 obj.value += 1
get_transaction().commit() transaction.commit()
except ConflictError: except ConflictError:
pass pass
cn.close() cn.close()
......
...@@ -89,7 +89,7 @@ Usage: loadmail2 [options] ...@@ -89,7 +89,7 @@ Usage: loadmail2 [options]
Specify the mailbox for getting input data. Specify the mailbox for getting input data.
$Id: zodbload.py,v 1.5 2004/03/18 13:27:49 yuppie Exp $ $Id: zodbload.py,v 1.6 2004/04/16 15:58:10 jeremy Exp $
""" """
import mailbox import mailbox
...@@ -217,7 +217,7 @@ def setup(lib_python): ...@@ -217,7 +217,7 @@ def setup(lib_python):
app.cat.addIndex('PrincipiaSearchSource', 'ZCTextIndex', extra) app.cat.addIndex('PrincipiaSearchSource', 'ZCTextIndex', extra)
get_transaction().commit() transaction.commit()
system = AccessControl.SpecialUsers.system system = AccessControl.SpecialUsers.system
AccessControl.SecurityManagement.newSecurityManager(None, system) AccessControl.SecurityManagement.newSecurityManager(None, system)
...@@ -237,7 +237,7 @@ def do(db, f, args): ...@@ -237,7 +237,7 @@ def do(db, f, args):
while 1: while 1:
connection = db.open() connection = db.open()
try: try:
get_transaction().begin() transaction.begin()
t=time.time() t=time.time()
c=time.clock() c=time.clock()
try: try:
...@@ -245,7 +245,7 @@ def do(db, f, args): ...@@ -245,7 +245,7 @@ def do(db, f, args):
r = f(connection, *args) r = f(connection, *args)
except ConflictError: except ConflictError:
rconflicts += 1 rconflicts += 1
get_transaction().abort() transaction.abort()
continue continue
finally: finally:
wcomp += time.time() - t wcomp += time.time() - t
...@@ -255,11 +255,11 @@ def do(db, f, args): ...@@ -255,11 +255,11 @@ def do(db, f, args):
c=time.clock() c=time.clock()
try: try:
try: try:
get_transaction().commit() transaction.commit()
break break
except ConflictError: except ConflictError:
wconflicts += 1 wconflicts += 1
get_transaction().abort() transaction.abort()
continue continue
finally: finally:
wcommit += time.time() - t wcommit += time.time() - t
......
...@@ -36,7 +36,7 @@ TODO ...@@ -36,7 +36,7 @@ TODO
add in tests for objects which are modified multiple times, add in tests for objects which are modified multiple times,
for example an object that gets modified in multiple sub txns. for example an object that gets modified in multiple sub txns.
$Id: test_transaction.py,v 1.1 2004/04/16 00:19:38 jeremy Exp $ $Id: test_transaction.py,v 1.2 2004/04/16 15:58:10 jeremy Exp $
""" """
import unittest import unittest
...@@ -64,7 +64,7 @@ class TransactionTests(unittest.TestCase): ...@@ -64,7 +64,7 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify() self.sub1.modify()
self.sub2.modify() self.sub2.modify()
get_transaction().commit() transaction.commit()
assert self.sub1._p_jar.ccommit_sub == 0 assert self.sub1._p_jar.ccommit_sub == 0
assert self.sub1._p_jar.ctpc_finish == 1 assert self.sub1._p_jar.ctpc_finish == 1
...@@ -74,13 +74,13 @@ class TransactionTests(unittest.TestCase): ...@@ -74,13 +74,13 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify() self.sub1.modify()
self.sub2.modify() self.sub2.modify()
get_transaction().abort() transaction.abort()
assert self.sub2._p_jar.cabort == 1 assert self.sub2._p_jar.cabort == 1
def testTransactionNote(self): def testTransactionNote(self):
t = get_transaction() t = transaction.get()
t.note('This is a note.') t.note('This is a note.')
self.assertEqual(t.description, 'This is a note.') self.assertEqual(t.description, 'This is a note.')
...@@ -94,12 +94,12 @@ class TransactionTests(unittest.TestCase): ...@@ -94,12 +94,12 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify() self.sub1.modify()
self.sub2.modify() self.sub2.modify()
get_transaction().commit(1) transaction.commit(1)
assert self.sub1._p_jar.ctpc_vote == 0 assert self.sub1._p_jar.ctpc_vote == 0
assert self.sub1._p_jar.ctpc_finish == 1 assert self.sub1._p_jar.ctpc_finish == 1
get_transaction().commit() transaction.commit()
assert self.sub1._p_jar.ccommit_sub == 1 assert self.sub1._p_jar.ccommit_sub == 1
assert self.sub1._p_jar.ctpc_vote == 1 assert self.sub1._p_jar.ctpc_vote == 1
...@@ -109,8 +109,8 @@ class TransactionTests(unittest.TestCase): ...@@ -109,8 +109,8 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify() self.sub1.modify()
self.sub2.modify() self.sub2.modify()
get_transaction().commit(1) transaction.commit(1)
get_transaction().abort() transaction.abort()
assert self.sub1._p_jar.ctpc_vote == 0 assert self.sub1._p_jar.ctpc_vote == 0
assert self.sub1._p_jar.cabort == 0 assert self.sub1._p_jar.cabort == 0
...@@ -118,12 +118,12 @@ class TransactionTests(unittest.TestCase): ...@@ -118,12 +118,12 @@ class TransactionTests(unittest.TestCase):
def testMultipleSubTransactionCommitCommit(self): def testMultipleSubTransactionCommitCommit(self):
self.sub1.modify() self.sub1.modify()
get_transaction().commit(1) transaction.commit(1)
self.sub2.modify() self.sub2.modify()
# reset a flag on the original to test it again # reset a flag on the original to test it again
self.sub1.ctpc_finish = 0 self.sub1.ctpc_finish = 0
get_transaction().commit(1) transaction.commit(1)
# this is interesting.. we go through # this is interesting.. we go through
# every subtrans commit with all subtrans capable # every subtrans commit with all subtrans capable
...@@ -135,7 +135,7 @@ class TransactionTests(unittest.TestCase): ...@@ -135,7 +135,7 @@ class TransactionTests(unittest.TestCase):
# add another before we do the entire txn commit # add another before we do the entire txn commit
self.sub3.modify() self.sub3.modify()
get_transaction().commit() transaction.commit()
# we did an implicit sub commit, is this impl artifact? # we did an implicit sub commit, is this impl artifact?
assert self.sub3._p_jar.ccommit_sub == 1 assert self.sub3._p_jar.ccommit_sub == 1
...@@ -161,12 +161,12 @@ class TransactionTests(unittest.TestCase): ...@@ -161,12 +161,12 @@ class TransactionTests(unittest.TestCase):
# add it # add it
self.sub1.modify() self.sub1.modify()
get_transaction().commit(1) transaction.commit(1)
# add another # add another
self.sub2.modify() self.sub2.modify()
get_transaction().commit(1) transaction.commit(1)
assert self.sub1._p_jar.ctpc_vote == 0 assert self.sub1._p_jar.ctpc_vote == 0
assert self.sub1._p_jar.ctpc_finish > 0 assert self.sub1._p_jar.ctpc_finish > 0
...@@ -175,10 +175,10 @@ class TransactionTests(unittest.TestCase): ...@@ -175,10 +175,10 @@ class TransactionTests(unittest.TestCase):
self.sub3.modify() self.sub3.modify()
# abort the sub transaction # abort the sub transaction
get_transaction().abort(1) transaction.abort(1)
# commit the container transaction # commit the container transaction
get_transaction().commit() transaction.commit()
assert self.sub3._p_jar.cabort == 1 assert self.sub3._p_jar.cabort == 1
assert self.sub1._p_jar.ccommit_sub == 1 assert self.sub1._p_jar.ccommit_sub == 1
...@@ -190,7 +190,7 @@ class TransactionTests(unittest.TestCase): ...@@ -190,7 +190,7 @@ class TransactionTests(unittest.TestCase):
self.nosub1.modify() self.nosub1.modify()
get_transaction().commit() transaction.commit()
assert self.nosub1._p_jar.ctpc_finish == 1 assert self.nosub1._p_jar.ctpc_finish == 1
...@@ -198,7 +198,7 @@ class TransactionTests(unittest.TestCase): ...@@ -198,7 +198,7 @@ class TransactionTests(unittest.TestCase):
self.nosub1.modify() self.nosub1.modify()
get_transaction().abort() transaction.abort()
assert self.nosub1._p_jar.ctpc_finish == 0 assert self.nosub1._p_jar.ctpc_finish == 0
assert self.nosub1._p_jar.cabort == 1 assert self.nosub1._p_jar.cabort == 1
...@@ -222,7 +222,7 @@ class TransactionTests(unittest.TestCase): ...@@ -222,7 +222,7 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify(tracing='sub') self.sub1.modify(tracing='sub')
self.nosub1.modify(tracing='nosub') self.nosub1.modify(tracing='nosub')
get_transaction().commit(1) transaction.commit(1)
assert self.sub1._p_jar.ctpc_finish == 1 assert self.sub1._p_jar.ctpc_finish == 1
...@@ -230,7 +230,7 @@ class TransactionTests(unittest.TestCase): ...@@ -230,7 +230,7 @@ class TransactionTests(unittest.TestCase):
# in a subtrans # in a subtrans
assert self.nosub1._p_jar.ctpc_finish == 0 assert self.nosub1._p_jar.ctpc_finish == 0
get_transaction().abort() transaction.abort()
assert self.nosub1._p_jar.cabort == 1 assert self.nosub1._p_jar.cabort == 1
assert self.sub1._p_jar.cabort_sub == 1 assert self.sub1._p_jar.cabort_sub == 1
...@@ -240,11 +240,11 @@ class TransactionTests(unittest.TestCase): ...@@ -240,11 +240,11 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify() self.sub1.modify()
self.nosub1.modify() self.nosub1.modify()
get_transaction().commit(1) transaction.commit(1)
assert self.nosub1._p_jar.ctpc_vote == 0 assert self.nosub1._p_jar.ctpc_vote == 0
get_transaction().commit() transaction.commit()
#assert self.nosub1._p_jar.ccommit_sub == 0 #assert self.nosub1._p_jar.ccommit_sub == 0
assert self.nosub1._p_jar.ctpc_vote == 1 assert self.nosub1._p_jar.ctpc_vote == 1
...@@ -277,12 +277,12 @@ class TransactionTests(unittest.TestCase): ...@@ -277,12 +277,12 @@ class TransactionTests(unittest.TestCase):
# add it # add it
self.sub1.modify() self.sub1.modify()
get_transaction().commit(1) transaction.commit(1)
# add another # add another
self.nosub1.modify() self.nosub1.modify()
get_transaction().commit(1) transaction.commit(1)
assert self.sub1._p_jar.ctpc_vote == 0 assert self.sub1._p_jar.ctpc_vote == 0
assert self.nosub1._p_jar.ctpc_vote == 0 assert self.nosub1._p_jar.ctpc_vote == 0
...@@ -292,7 +292,7 @@ class TransactionTests(unittest.TestCase): ...@@ -292,7 +292,7 @@ class TransactionTests(unittest.TestCase):
self.sub2.modify() self.sub2.modify()
# commit the container transaction # commit the container transaction
get_transaction().commit() transaction.commit()
# we did an implicit sub commit # we did an implicit sub commit
assert self.sub2._p_jar.ccommit_sub == 1 assert self.sub2._p_jar.ccommit_sub == 1
...@@ -317,7 +317,7 @@ class TransactionTests(unittest.TestCase): ...@@ -317,7 +317,7 @@ class TransactionTests(unittest.TestCase):
self.sub2.modify() self.sub2.modify()
try: try:
get_transaction().abort() transaction.abort()
except TestTxnException: pass except TestTxnException: pass
assert self.nosub1._p_jar.cabort == 1 assert self.nosub1._p_jar.cabort == 1
...@@ -331,7 +331,7 @@ class TransactionTests(unittest.TestCase): ...@@ -331,7 +331,7 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify(nojar=1) self.sub1.modify(nojar=1)
try: try:
get_transaction().commit() transaction.commit()
except TestTxnException: pass except TestTxnException: pass
assert self.nosub1._p_jar.ctpc_finish == 0 assert self.nosub1._p_jar.ctpc_finish == 0
...@@ -346,7 +346,7 @@ class TransactionTests(unittest.TestCase): ...@@ -346,7 +346,7 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify(nojar=1) self.sub1.modify(nojar=1)
try: try:
get_transaction().commit() transaction.commit()
except TestTxnException: pass except TestTxnException: pass
assert self.nosub1._p_jar.ctpc_finish == 0 assert self.nosub1._p_jar.ctpc_finish == 0
...@@ -372,7 +372,7 @@ class TransactionTests(unittest.TestCase): ...@@ -372,7 +372,7 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify(nojar=1) self.sub1.modify(nojar=1)
try: try:
get_transaction().commit() transaction.commit()
except TestTxnException: pass except TestTxnException: pass
assert self.nosub1._p_jar.ctpc_abort == 1 assert self.nosub1._p_jar.ctpc_abort == 1
...@@ -386,7 +386,7 @@ class TransactionTests(unittest.TestCase): ...@@ -386,7 +386,7 @@ class TransactionTests(unittest.TestCase):
self.sub1.modify(nojar=1) self.sub1.modify(nojar=1)
try: try:
get_transaction().commit() transaction.commit()
except TestTxnException: except TestTxnException:
pass pass
...@@ -403,19 +403,19 @@ class TransactionTests(unittest.TestCase): ...@@ -403,19 +403,19 @@ class TransactionTests(unittest.TestCase):
# they come out of the dictionary. # they come out of the dictionary.
self.sub1.modify() self.sub1.modify()
get_transaction().commit(1) transaction.commit(1)
self.nosub1.modify() self.nosub1.modify()
self.sub2._p_jar = SubTransactionJar(errors='commit_sub') self.sub2._p_jar = SubTransactionJar(errors='commit_sub')
self.sub2.modify(nojar=1) self.sub2.modify(nojar=1)
get_transaction().commit(1) transaction.commit(1)
self.sub3.modify() self.sub3.modify()
try: try:
get_transaction().commit() transaction.commit()
except TestTxnException: except TestTxnException:
pass pass
...@@ -442,17 +442,17 @@ class TransactionTests(unittest.TestCase): ...@@ -442,17 +442,17 @@ class TransactionTests(unittest.TestCase):
self.sub1._p_jar = SubTransactionJar(errors='commit_sub') self.sub1._p_jar = SubTransactionJar(errors='commit_sub')
self.sub1.modify(nojar=1) self.sub1.modify(nojar=1)
get_transaction().commit(1) transaction.commit(1)
self.nosub1.modify() self.nosub1.modify()
self.sub2._p_jar = SubTransactionJar(errors='abort_sub') self.sub2._p_jar = SubTransactionJar(errors='abort_sub')
self.sub2.modify(nojar=1) self.sub2.modify(nojar=1)
get_transaction().commit(1) transaction.commit(1)
self.sub3.modify() self.sub3.modify()
try: try:
get_transaction().commit() transaction.commit()
except TestTxnException, err: except TestTxnException, err:
pass pass
else: else:
...@@ -483,7 +483,7 @@ class TransactionTests(unittest.TestCase): ...@@ -483,7 +483,7 @@ class TransactionTests(unittest.TestCase):
## obj.modify(nojar=1) ## obj.modify(nojar=1)
## try: ## try:
## get_transaction().commit() ## transaction.commit()
## except TestTxnException: ## except TestTxnException:
## pass ## pass
...@@ -492,7 +492,7 @@ class TransactionTests(unittest.TestCase): ...@@ -492,7 +492,7 @@ class TransactionTests(unittest.TestCase):
## self.sub2.modify() ## self.sub2.modify()
## try: ## try:
## get_transaction().commit() ## transaction.commit()
## except Transaction.POSException.TransactionError: ## except Transaction.POSException.TransactionError:
## pass ## pass
## else: ## else:
...@@ -511,7 +511,7 @@ class DataObject: ...@@ -511,7 +511,7 @@ class DataObject:
self._p_jar = NoSubTransactionJar(tracing=tracing) self._p_jar = NoSubTransactionJar(tracing=tracing)
else: else:
self._p_jar = SubTransactionJar(tracing=tracing) self._p_jar = SubTransactionJar(tracing=tracing)
get_transaction().register(self) transaction.get().register(self)
class TestTxnException(Exception): class TestTxnException(Exception):
pass pass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment