Commit f0f00357 authored by Jim Fulton's avatar Jim Fulton

Updated some tests and test support to use TransactionMetaData

parent d2b72af8
...@@ -20,6 +20,7 @@ import unittest ...@@ -20,6 +20,7 @@ import unittest
import ZODB.blob import ZODB.blob
import ZODB.FileStorage import ZODB.FileStorage
import ZODB.tests.util import ZODB.tests.util
from ZODB.Connection import TransactionMetaData
from zope.testing import renormalizing from zope.testing import renormalizing
checker = renormalizing.RENormalizing([ checker = renormalizing.RENormalizing([
...@@ -124,7 +125,7 @@ def pack_with_repeated_blob_records(): ...@@ -124,7 +125,7 @@ def pack_with_repeated_blob_records():
Now, create a transaction with multiple saves: Now, create a transaction with multiple saves:
>>> trans = tm.begin() >>> trans = TransactionMetaData()
>>> fs.tpc_begin(trans) >>> fs.tpc_begin(trans)
>>> with open('ablob', 'w') as file: >>> with open('ablob', 'w') as file:
... _ = file.write('some data') ... _ = file.write('some data')
...@@ -151,7 +152,7 @@ _save_index can fail for large indexes. ...@@ -151,7 +152,7 @@ _save_index can fail for large indexes.
>>> import ZODB.utils >>> import ZODB.utils
>>> fs = ZODB.FileStorage.FileStorage('data.fs') >>> fs = ZODB.FileStorage.FileStorage('data.fs')
>>> t = transaction.begin() >>> t = TransactionMetaData()
>>> fs.tpc_begin(t) >>> fs.tpc_begin(t)
>>> oid = 0 >>> oid = 0
>>> for i in range(5000): >>> for i in range(5000):
......
...@@ -41,7 +41,8 @@ Now we'll use the new deleteObject API to delete the objects. We can't ...@@ -41,7 +41,8 @@ Now we'll use the new deleteObject API to delete the objects. We can't
go through the database to do this, so we'll have to manage the go through the database to do this, so we'll have to manage the
transaction ourselves. transaction ourselves.
>>> txn = transaction.begin() >>> from ZODB.Connection import TransactionMetaData
>>> txn = TransactionMetaData()
>>> storage.tpc_begin(txn) >>> storage.tpc_begin(txn)
>>> storage.deleteObject(oid0, s0, txn) >>> storage.deleteObject(oid0, s0, txn)
>>> storage.deleteObject(oid1, s1, txn) >>> storage.deleteObject(oid1, s1, txn)
...@@ -116,7 +117,7 @@ isn't current: ...@@ -116,7 +117,7 @@ isn't current:
>>> conn.root()[0].x = 1 >>> conn.root()[0].x = 1
>>> transaction.commit() >>> transaction.commit()
>>> txn = transaction.begin() >>> txn = TransactionMetaData()
>>> storage.tpc_begin(txn) >>> storage.tpc_begin(txn)
>>> storage.deleteObject(oid, bad_serial, txn); storage.tpc_vote(txn) >>> storage.deleteObject(oid, bad_serial, txn); storage.tpc_vote(txn)
... # doctest: +ELLIPSIS ... # doctest: +ELLIPSIS
......
...@@ -144,12 +144,12 @@ class PackableStorageBase: ...@@ -144,12 +144,12 @@ class PackableStorageBase:
try: try:
load_current(self._storage, ZERO) load_current(self._storage, ZERO)
except KeyError: except KeyError:
from transaction import Transaction from ZODB.Connection import TransactionMetaData
file = BytesIO() file = BytesIO()
p = Pickler(file, _protocol) p = Pickler(file, _protocol)
p.dump((PersistentMapping, None)) p.dump((PersistentMapping, None))
p.dump({'_container': {}}) p.dump({'_container': {}})
t=Transaction() t = TransactionMetaData()
t.description = u'initial database creation' t.description = u'initial database creation'
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(ZERO, None, file.getvalue(), '', t) self._storage.store(ZERO, None, file.getvalue(), '', t)
......
...@@ -377,7 +377,8 @@ If a transaction is aborted in the middle of 2-phase commit, any data ...@@ -377,7 +377,8 @@ If a transaction is aborted in the middle of 2-phase commit, any data
stored are discarded. stored are discarded.
>>> olddata, oldserial = blob_storage.load(blob._p_oid, '') >>> olddata, oldserial = blob_storage.load(blob._p_oid, '')
>>> t = transaction.get() >>> from ZODB.Connection import TransactionMetaData
>>> t = TransactionMetaData()
>>> blob_storage.tpc_begin(t) >>> blob_storage.tpc_begin(t)
>>> with open('blobfile', 'wb') as file: >>> with open('blobfile', 'wb') as file:
... _ = file.write(b'This data should go away') ... _ = file.write(b'This data should go away')
......
...@@ -25,6 +25,7 @@ import transaction ...@@ -25,6 +25,7 @@ import transaction
import unittest import unittest
import warnings import warnings
import ZODB.utils import ZODB.utils
from ZODB.Connection import TransactionMetaData
import zope.testing.setupstack import zope.testing.setupstack
from zope.testing import renormalizing from zope.testing import renormalizing
...@@ -161,7 +162,7 @@ def store(storage, oid, value='x', serial=ZODB.utils.z64): ...@@ -161,7 +162,7 @@ def store(storage, oid, value='x', serial=ZODB.utils.z64):
oid = ZODB.utils.p64(oid) oid = ZODB.utils.p64(oid)
if not isinstance(serial, bytes): if not isinstance(serial, bytes):
serial = ZODB.utils.p64(serial) serial = ZODB.utils.p64(serial)
t = transaction.get() t = TransactionMetaData()
storage.tpc_begin(t) storage.tpc_begin(t)
storage.store(oid, serial, value, '', t) storage.store(oid, serial, value, '', t)
storage.tpc_vote(t) storage.tpc_vote(t)
......
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