Commit 32c8436c authored by Jim Fulton's avatar Jim Fulton

Removed the extension_bytes feature and updated many tests to use TransactionMetaData

parent b3a389fa
...@@ -49,9 +49,9 @@ from ZODB import utils ...@@ -49,9 +49,9 @@ from ZODB import utils
import six import six
from .mvccadapter import HistoricalStorageAdapter from .mvccadapter import HistoricalStorageAdapter
from ._compat import dumps, loads, _protocol
from . import valuedoc from . import valuedoc
from . import _compat
global_reset_counter = 0 global_reset_counter = 0
...@@ -1291,9 +1291,8 @@ class TransactionMetaData: ...@@ -1291,9 +1291,8 @@ class TransactionMetaData:
def __init__(self, user=u'', description=u'', extension=b''): def __init__(self, user=u'', description=u'', extension=b''):
self.user = user self.user = user
self.description = description self.description = description
if isinstance(extension, bytes): if not isinstance(extension, dict):
self.extension_bytes = extension extension = _compat.loads(extension) if extension else {}
else:
self.extension = extension self.extension = extension
@property @property
...@@ -1316,6 +1315,16 @@ class TransactionMetaData: ...@@ -1316,6 +1315,16 @@ class TransactionMetaData:
description = description.encode('utf-8') description = description.encode('utf-8')
self.__description = description self.__description = description
def note(self, text): # for tests
text = text.strip()
if not isinstance(text, bytes):
text = text.encode('utf-8')
if self.description:
self.description = self.description.strip() + b' ' + text
else:
self.description = text
@property @property
def extension(self): def extension(self):
return self.__extension return self.__extension
...@@ -1323,16 +1332,5 @@ class TransactionMetaData: ...@@ -1323,16 +1332,5 @@ class TransactionMetaData:
@extension.setter @extension.setter
def extension(self, v): def extension(self, v):
self.__extension = v self.__extension = v
self.__extension_bytes = dumps(v, _protocol) if v else b''
_extension = extension _extension = extension
@property
def extension_bytes(self):
return self.__extension_bytes
@extension_bytes.setter
def extension_bytes(self, v):
d = loads(v) if v else {}
self.__extension_bytes = v if d else b''
self.__extension = d
...@@ -19,12 +19,12 @@ http://www.zope.org/Documentation/Developer/Models/ZODB/ZODB_Architecture_Storag ...@@ -19,12 +19,12 @@ http://www.zope.org/Documentation/Developer/Models/ZODB/ZODB_Architecture_Storag
All storages should be able to pass these tests. All storages should be able to pass these tests.
""" """
from ZODB import POSException from ZODB import POSException
from ZODB.Connection import TransactionMetaData
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle
import threading import threading
import time import time
import transaction
import zope.interface import zope.interface
import zope.interface.verify import zope.interface.verify
...@@ -36,7 +36,7 @@ class BasicStorage: ...@@ -36,7 +36,7 @@ class BasicStorage:
def checkBasics(self): def checkBasics(self):
self.assertEqual(self._storage.lastTransaction(), ZERO) self.assertEqual(self._storage.lastTransaction(), ZERO)
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self.assertRaises(POSException.StorageTransactionError, self.assertRaises(POSException.StorageTransactionError,
self._storage.tpc_begin, t) self._storage.tpc_begin, t)
...@@ -48,22 +48,22 @@ class BasicStorage: ...@@ -48,22 +48,22 @@ class BasicStorage:
self.assertRaises( self.assertRaises(
POSException.StorageTransactionError, POSException.StorageTransactionError,
self._storage.store, self._storage.store,
ZERO, ZERO, b'', '', transaction.Transaction()) ZERO, ZERO, b'', '', TransactionMetaData())
self.assertRaises( self.assertRaises(
POSException.StorageTransactionError, POSException.StorageTransactionError,
self._storage.store, self._storage.store,
ZERO, 1, b'2', '', transaction.Transaction()) ZERO, 1, b'2', '', TransactionMetaData())
self.assertRaises( self.assertRaises(
POSException.StorageTransactionError, POSException.StorageTransactionError,
self._storage.tpc_vote, transaction.Transaction()) self._storage.tpc_vote, TransactionMetaData())
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
def checkSerialIsNoneForInitialRevision(self): def checkSerialIsNoneForInitialRevision(self):
eq = self.assertEqual eq = self.assertEqual
oid = self._storage.new_oid() oid = self._storage.new_oid()
txn = transaction.Transaction() txn = TransactionMetaData()
self._storage.tpc_begin(txn) self._storage.tpc_begin(txn)
# Use None for serial. Don't use _dostore() here because that coerces # Use None for serial. Don't use _dostore() here because that coerces
# serial=None to serial=ZERO. # serial=None to serial=ZERO.
...@@ -106,7 +106,7 @@ class BasicStorage: ...@@ -106,7 +106,7 @@ class BasicStorage:
def checkWriteAfterAbort(self): def checkWriteAfterAbort(self):
oid = self._storage.new_oid() oid = self._storage.new_oid()
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t) self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t)
# Now abort this transaction # Now abort this transaction
...@@ -119,7 +119,7 @@ class BasicStorage: ...@@ -119,7 +119,7 @@ class BasicStorage:
oid1 = self._storage.new_oid() oid1 = self._storage.new_oid()
revid1 = self._dostore(oid=oid1, data=MinPO(-2)) revid1 = self._dostore(oid=oid1, data=MinPO(-2))
oid = self._storage.new_oid() oid = self._storage.new_oid()
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t) self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t)
# Now abort this transaction # Now abort this transaction
...@@ -180,7 +180,7 @@ class BasicStorage: ...@@ -180,7 +180,7 @@ class BasicStorage:
def checkNote(self): def checkNote(self):
oid = self._storage.new_oid() oid = self._storage.new_oid()
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
t.note('this is a test') t.note('this is a test')
self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t) self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), '', t)
...@@ -194,18 +194,14 @@ class BasicStorage: ...@@ -194,18 +194,14 @@ class BasicStorage:
def checkMultipleEmptyTransactions(self): def checkMultipleEmptyTransactions(self):
# There was a bug in handling empty transactions in mapping # There was a bug in handling empty transactions in mapping
# storage that caused the commit lock not to be released. :( # storage that caused the commit lock not to be released. :(
transaction.begin() t = TransactionMetaData()
t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
self._storage.tpc_finish(t) self._storage.tpc_finish(t)
t.commit() t = TransactionMetaData()
transaction.begin()
t = transaction.get()
self._storage.tpc_begin(t) # Hung here before self._storage.tpc_begin(t) # Hung here before
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
self._storage.tpc_finish(t) self._storage.tpc_finish(t)
t.commit()
def _do_store_in_separate_thread(self, oid, revid, voted): def _do_store_in_separate_thread(self, oid, revid, voted):
# We'll run the competing trans in a separate thread: # We'll run the competing trans in a separate thread:
...@@ -224,8 +220,7 @@ class BasicStorage: ...@@ -224,8 +220,7 @@ class BasicStorage:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# stale read # stale read
transaction.begin() t = TransactionMetaData()
t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
try: try:
self._storage.store(b'\0\0\0\0\0\0\0\xf1', self._storage.store(b'\0\0\0\0\0\0\0\xf1',
...@@ -243,8 +238,7 @@ class BasicStorage: ...@@ -243,8 +238,7 @@ class BasicStorage:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# non-stale read, no stress. :) # non-stale read, no stress. :)
transaction.begin() t = TransactionMetaData()
t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(b'\0\0\0\0\0\0\0\xf2', self._storage.store(b'\0\0\0\0\0\0\0\xf2',
b'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
...@@ -255,8 +249,7 @@ class BasicStorage: ...@@ -255,8 +249,7 @@ class BasicStorage:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# non-stale read, competition after vote. The competing # non-stale read, competition after vote. The competing
# transaction must produce a tid > this transaction's tid # transaction must produce a tid > this transaction's tid
transaction.begin() t = TransactionMetaData()
t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(b'\0\0\0\0\0\0\0\xf3', self._storage.store(b'\0\0\0\0\0\0\0\xf3',
b'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
...@@ -275,8 +268,7 @@ class BasicStorage: ...@@ -275,8 +268,7 @@ class BasicStorage:
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# non-stale competing trans after checkCurrentSerialInTransaction # non-stale competing trans after checkCurrentSerialInTransaction
transaction.begin() t = TransactionMetaData()
t = transaction.get()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(b'\0\0\0\0\0\0\0\xf4', self._storage.store(b'\0\0\0\0\0\0\0\xf4',
b'\0\0\0\0\0\0\0\0', data, '', t) b'\0\0\0\0\0\0\0\0', data, '', t)
...@@ -312,7 +304,7 @@ class BasicStorage: ...@@ -312,7 +304,7 @@ class BasicStorage:
# verify that a storage gets it right. # verify that a storage gets it right.
# First, some initial data. # First, some initial data.
t = transaction.get() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(ZERO, ZERO, b'x', '', t) self._storage.store(ZERO, ZERO, b'x', '', t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
...@@ -322,7 +314,7 @@ class BasicStorage: ...@@ -322,7 +314,7 @@ class BasicStorage:
# OK, now we'll start a new transaction, take it to finish, # OK, now we'll start a new transaction, take it to finish,
# and then block finish while we do some other operations. # and then block finish while we do some other operations.
t = transaction.get() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(ZERO, tids[0], b'y', '', t) self._storage.store(ZERO, tids[0], b'y', '', t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
......
...@@ -14,9 +14,10 @@ ...@@ -14,9 +14,10 @@
"""Tests for application-level conflict resolution.""" """Tests for application-level conflict resolution."""
from ZODB import DB from ZODB import DB
from ZODB.Connection import TransactionMetaData
from ZODB.POSException import ConflictError, UndoError from ZODB.POSException import ConflictError, UndoError
from persistent import Persistent from persistent import Persistent
from transaction import Transaction, TransactionManager from transaction import TransactionManager
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle
...@@ -148,7 +149,7 @@ class ConflictResolvingTransUndoStorage: ...@@ -148,7 +149,7 @@ class ConflictResolvingTransUndoStorage:
# Start the undo # Start the undo
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[1]['id'] tid = info[1]['id']
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.undo(tid, t) self._storage.undo(tid, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
...@@ -170,6 +171,6 @@ class ConflictResolvingTransUndoStorage: ...@@ -170,6 +171,6 @@ class ConflictResolvingTransUndoStorage:
# Start the undo # Start the undo
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[1]['id'] tid = info[1]['id']
t = Transaction() t = TransactionMetaData()
self.assertRaises(UndoError, self._begin_undos_vote, t, tid) self.assertRaises(UndoError, self._begin_undos_vote, t, tid)
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
...@@ -18,12 +18,11 @@ all these tests. ...@@ -18,12 +18,11 @@ all these tests.
""" """
from ZODB.Connection import TransactionMetaData
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_pickle, zodb_unpickle from ZODB.tests.StorageTestBase import zodb_pickle, zodb_unpickle
from ZODB.utils import U64, p64, load_current from ZODB.utils import U64, p64, load_current
from transaction import Transaction
import ZODB.blob import ZODB.blob
try: try:
...@@ -67,7 +66,7 @@ class IteratorStorage(IteratorCompare): ...@@ -67,7 +66,7 @@ class IteratorStorage(IteratorCompare):
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[0]['id'] tid = info[0]['id']
# Undo the creation of the object, rendering it a zombie # Undo the creation of the object, rendering it a zombie
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
oids = self._storage.undo(tid, t) oids = self._storage.undo(tid, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
...@@ -105,7 +104,7 @@ class IteratorStorage(IteratorCompare): ...@@ -105,7 +104,7 @@ class IteratorStorage(IteratorCompare):
# Then the code in FileIterator.next() hasn't yet been fixed. # Then the code in FileIterator.next() hasn't yet been fixed.
# Should automate that check. # Should automate that check.
oid = self._storage.new_oid() oid = self._storage.new_oid()
t = Transaction() t = TransactionMetaData()
data = zodb_pickle(MinPO(0)) data = zodb_pickle(MinPO(0))
try: try:
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
......
...@@ -8,6 +8,7 @@ import six ...@@ -8,6 +8,7 @@ import six
import transaction import transaction
import ZODB import ZODB
from ZODB.Connection import TransactionMetaData
from ZODB.tests.StorageTestBase import zodb_pickle, zodb_unpickle from ZODB.tests.StorageTestBase import zodb_pickle, zodb_unpickle
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.POSException import ConflictError from ZODB.POSException import ConflictError
...@@ -140,7 +141,7 @@ class StorageClientThread(TestThread): ...@@ -140,7 +141,7 @@ class StorageClientThread(TestThread):
def dostore(self, i): def dostore(self, i):
data = zodb_pickle(MinPO((self.getName(), i))) data = zodb_pickle(MinPO((self.getName(), i)))
t = transaction.Transaction() t = TransactionMetaData()
oid = self.oid() oid = self.oid()
self.pause() self.pause()
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
# FOR A PARTICULAR PURPOSE. # FOR A PARTICULAR PURPOSE.
# #
############################################################################## ##############################################################################
from ZODB.Connection import TransactionMetaData
from ZODB.POSException import ReadOnlyError, Unsupported from ZODB.POSException import ReadOnlyError, Unsupported
import transaction
from ZODB.utils import load_current from ZODB.utils import load_current
...@@ -48,7 +48,7 @@ class ReadOnlyStorage: ...@@ -48,7 +48,7 @@ class ReadOnlyStorage:
def checkWriteMethods(self): def checkWriteMethods(self):
self._make_readonly() self._make_readonly()
self.assertRaises(ReadOnlyError, self._storage.new_oid) self.assertRaises(ReadOnlyError, self._storage.new_oid)
t = transaction.Transaction() t = TransactionMetaData()
self.assertRaises(ReadOnlyError, self._storage.tpc_begin, t) self.assertRaises(ReadOnlyError, self._storage.tpc_begin, t)
self.assertRaises(ReadOnlyError, self._storage.store, self.assertRaises(ReadOnlyError, self._storage.store,
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
"""More recovery and iterator tests.""" """More recovery and iterator tests."""
import transaction import transaction
from transaction import Transaction from ZODB.Connection import TransactionMetaData
from ZODB.tests.IteratorStorage import IteratorDeepCompare from ZODB.tests.IteratorStorage import IteratorDeepCompare
from ZODB.tests.StorageTestBase import MinPO, snooze from ZODB.tests.StorageTestBase import MinPO, snooze
from ZODB import DB from ZODB import DB
...@@ -147,7 +147,7 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -147,7 +147,7 @@ class RecoveryStorage(IteratorDeepCompare):
# Undo the attribute creation. # Undo the attribute creation.
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[0]['id'] tid = info[0]['id']
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
oids = self._storage.undo(tid, t) oids = self._storage.undo(tid, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
...@@ -171,7 +171,7 @@ class RecoveryStorage(IteratorDeepCompare): ...@@ -171,7 +171,7 @@ class RecoveryStorage(IteratorDeepCompare):
# Undo the undo (restore the attributes). # Undo the undo (restore the attributes).
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[0]['id'] tid = info[0]['id']
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
oids = self._storage.undo(tid, t) oids = self._storage.undo(tid, t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
......
...@@ -13,12 +13,11 @@ ...@@ -13,12 +13,11 @@
############################################################################## ##############################################################################
"""Check loadSerial() on storages that support historical revisions.""" """Check loadSerial() on storages that support historical revisions."""
from ZODB.Connection import TransactionMetaData
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle, snooze from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle, snooze
from ZODB.utils import p64, u64, load_current from ZODB.utils import p64, u64, load_current
import transaction
ZERO = '\0'*8 ZERO = '\0'*8
class RevisionStorage: class RevisionStorage:
...@@ -142,7 +141,7 @@ class RevisionStorage: ...@@ -142,7 +141,7 @@ class RevisionStorage:
oid = self._storage.new_oid() oid = self._storage.new_oid()
def helper(tid, revid, x): def helper(tid, revid, x):
data = zodb_pickle(MinPO(x)) data = zodb_pickle(MinPO(x))
t = transaction.Transaction() t = TransactionMetaData()
try: try:
self._storage.tpc_begin(t, p64(tid)) self._storage.tpc_begin(t, p64(tid))
self._storage.store(oid, revid, data, '', t) self._storage.store(oid, revid, data, '', t)
......
...@@ -21,8 +21,8 @@ single object revision. ...@@ -21,8 +21,8 @@ single object revision.
from __future__ import print_function from __future__ import print_function
import sys import sys
import time import time
import transaction
from ZODB.Connection import TransactionMetaData
from ZODB.utils import u64, z64 from ZODB.utils import u64, z64
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB._compat import PersistentPickler, Unpickler, BytesIO, _protocol from ZODB._compat import PersistentPickler, Unpickler, BytesIO, _protocol
...@@ -144,7 +144,7 @@ class StorageTestBase(ZODB.tests.util.TestCase): ...@@ -144,7 +144,7 @@ class StorageTestBase(ZODB.tests.util.TestCase):
if not already_pickled: if not already_pickled:
data = zodb_pickle(data) data = zodb_pickle(data)
# Begin the transaction # Begin the transaction
t = transaction.Transaction() t = TransactionMetaData()
if user is not None: if user is not None:
t.user = user t.user = user
if description is not None: if description is not None:
...@@ -170,7 +170,7 @@ class StorageTestBase(ZODB.tests.util.TestCase): ...@@ -170,7 +170,7 @@ class StorageTestBase(ZODB.tests.util.TestCase):
def _undo(self, tid, expected_oids=None, note=None): def _undo(self, tid, expected_oids=None, note=None):
# Undo a tid that affects a single object (oid). # Undo a tid that affects a single object (oid).
# This is very specialized. # This is very specialized.
t = transaction.Transaction() t = TransactionMetaData()
t.note(note or "undo") t.note(note or "undo")
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
undo_result = self._storage.undo(tid, t) undo_result = self._storage.undo(tid, t)
......
...@@ -62,7 +62,7 @@ tested? Is it a general restriction? ...@@ -62,7 +62,7 @@ tested? Is it a general restriction?
""" """
from transaction import Transaction from ZODB.Connection import TransactionMetaData
from ZODB.POSException import StorageTransactionError from ZODB.POSException import StorageTransactionError
OID = "\000" * 8 OID = "\000" * 8
...@@ -75,43 +75,43 @@ class SynchronizedStorage: ...@@ -75,43 +75,43 @@ class SynchronizedStorage:
self.assertRaises(StorageTransactionError, callable, *args) self.assertRaises(StorageTransactionError, callable, *args)
def verifyWrongTrans(self, callable, *args): def verifyWrongTrans(self, callable, *args):
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self.assertRaises(StorageTransactionError, callable, *args) self.assertRaises(StorageTransactionError, callable, *args)
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
def checkStoreNotCommitting(self): def checkStoreNotCommitting(self):
self.verifyNotCommitting(self._storage.store, self.verifyNotCommitting(self._storage.store,
OID, SERIALNO, b"", "", Transaction()) OID, SERIALNO, b"", "", TransactionMetaData())
def checkStoreWrongTrans(self): def checkStoreWrongTrans(self):
self.verifyWrongTrans(self._storage.store, self.verifyWrongTrans(self._storage.store,
OID, SERIALNO, b"", "", Transaction()) OID, SERIALNO, b"", "", TransactionMetaData())
def checkAbortNotCommitting(self): def checkAbortNotCommitting(self):
self._storage.tpc_abort(Transaction()) self._storage.tpc_abort(TransactionMetaData())
def checkAbortWrongTrans(self): def checkAbortWrongTrans(self):
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.tpc_abort(Transaction()) self._storage.tpc_abort(TransactionMetaData())
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
def checkFinishNotCommitting(self): def checkFinishNotCommitting(self):
t = Transaction() t = TransactionMetaData()
self.assertRaises(StorageTransactionError, self.assertRaises(StorageTransactionError,
self._storage.tpc_finish, t) self._storage.tpc_finish, t)
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
def checkFinishWrongTrans(self): def checkFinishWrongTrans(self):
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self.assertRaises(StorageTransactionError, self.assertRaises(StorageTransactionError,
self._storage.tpc_finish, Transaction()) self._storage.tpc_finish, TransactionMetaData())
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
def checkBeginCommitting(self): def checkBeginCommitting(self):
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
......
...@@ -22,6 +22,7 @@ import transaction ...@@ -22,6 +22,7 @@ import transaction
from transaction import Transaction from transaction import Transaction
from ZODB import POSException from ZODB import POSException
from ZODB.Connection import TransactionMetaData
from ZODB.serialize import referencesf from ZODB.serialize import referencesf
from ZODB.utils import p64, load_current from ZODB.utils import p64, load_current
from ZODB import DB from ZODB import DB
...@@ -53,7 +54,7 @@ def listeq(L1, L2): ...@@ -53,7 +54,7 @@ def listeq(L1, L2):
class TransactionalUndoStorage: class TransactionalUndoStorage:
def _multi_obj_transaction(self, objs): def _multi_obj_transaction(self, objs):
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
for oid, rev, data in objs: for oid, rev, data in objs:
self._storage.store(oid, rev, data, '', t) self._storage.store(oid, rev, data, '', t)
...@@ -82,7 +83,7 @@ class TransactionalUndoStorage: ...@@ -82,7 +83,7 @@ class TransactionalUndoStorage:
return oids return oids
def undo(self, tid, note=None): def undo(self, tid, note=None):
t = Transaction() t = TransactionMetaData()
if note is not None: if note is not None:
t.note(note) t.note(note)
oids = self._begin_undos_vote(t, tid) oids = self._begin_undos_vote(t, tid)
...@@ -182,7 +183,7 @@ class TransactionalUndoStorage: ...@@ -182,7 +183,7 @@ class TransactionalUndoStorage:
oid2 = self._storage.new_oid() oid2 = self._storage.new_oid()
revid1 = revid2 = ZERO revid1 = revid2 = ZERO
# Store two objects in the same transaction # Store two objects in the same transaction
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid1, revid1, p31, '', t) self._storage.store(oid1, revid1, p31, '', t)
self._storage.store(oid2, revid2, p51, '', t) self._storage.store(oid2, revid2, p51, '', t)
...@@ -190,7 +191,7 @@ class TransactionalUndoStorage: ...@@ -190,7 +191,7 @@ class TransactionalUndoStorage:
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
tid = self._storage.tpc_finish(t) tid = self._storage.tpc_finish(t)
# Update those same two objects # Update those same two objects
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid1, tid, p32, '', t) self._storage.store(oid1, tid, p32, '', t)
self._storage.store(oid2, tid, p52, '', t) self._storage.store(oid2, tid, p52, '', t)
...@@ -242,7 +243,7 @@ class TransactionalUndoStorage: ...@@ -242,7 +243,7 @@ class TransactionalUndoStorage:
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[0]['id'] tid = info[0]['id']
tid1 = info[1]['id'] tid1 = info[1]['id']
t = Transaction() t = TransactionMetaData()
oids = self._begin_undos_vote(t, tid, tid1) oids = self._begin_undos_vote(t, tid, tid1)
serial = self._storage.tpc_finish(t) serial = self._storage.tpc_finish(t)
# We may get the finalization stuff called an extra time, # We may get the finalization stuff called an extra time,
...@@ -275,7 +276,7 @@ class TransactionalUndoStorage: ...@@ -275,7 +276,7 @@ class TransactionalUndoStorage:
revid1 = self._dostore(oid1, data=p31, already_pickled=1) revid1 = self._dostore(oid1, data=p31, already_pickled=1)
revid2 = self._dostore(oid2, data=p51, already_pickled=1) revid2 = self._dostore(oid2, data=p51, already_pickled=1)
# Update those same two objects # Update those same two objects
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid1, revid1, p32, '', t) self._storage.store(oid1, revid1, p32, '', t)
self._storage.store(oid2, revid2, p52, '', t) self._storage.store(oid2, revid2, p52, '', t)
...@@ -291,7 +292,7 @@ class TransactionalUndoStorage: ...@@ -291,7 +292,7 @@ class TransactionalUndoStorage:
eq(zodb_unpickle(data), MinPO(51)) eq(zodb_unpickle(data), MinPO(51))
# Like the above, but this time, the second transaction contains only # Like the above, but this time, the second transaction contains only
# one object. # one object.
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid1, revid1, p33, '', t) self._storage.store(oid1, revid1, p33, '', t)
self._storage.store(oid2, revid2, p53, '', t) self._storage.store(oid2, revid2, p53, '', t)
...@@ -320,7 +321,7 @@ class TransactionalUndoStorage: ...@@ -320,7 +321,7 @@ class TransactionalUndoStorage:
# Start the undo # Start the undo
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[1]['id'] tid = info[1]['id']
t = Transaction() t = TransactionMetaData()
self.assertRaises(POSException.UndoError, self.assertRaises(POSException.UndoError,
self._begin_undos_vote, t, tid) self._begin_undos_vote, t, tid)
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
...@@ -334,7 +335,7 @@ class TransactionalUndoStorage: ...@@ -334,7 +335,7 @@ class TransactionalUndoStorage:
p81, p82, p91, p92 = map(zodb_pickle, p81, p82, p91, p92 = map(zodb_pickle,
map(MinPO, (81, 82, 91, 92))) map(MinPO, (81, 82, 91, 92)))
t = Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.store(oid1, revid1, p81, '', t) self._storage.store(oid1, revid1, p81, '', t)
self._storage.store(oid2, revid2, p91, '', t) self._storage.store(oid2, revid2, p91, '', t)
...@@ -352,7 +353,7 @@ class TransactionalUndoStorage: ...@@ -352,7 +353,7 @@ class TransactionalUndoStorage:
self.assertNotEqual(tid, revid2) self.assertNotEqual(tid, revid2)
info = self._storage.undoInfo() info = self._storage.undoInfo()
tid = info[1]['id'] tid = info[1]['id']
t = Transaction() t = TransactionMetaData()
self.assertRaises(POSException.UndoError, self.assertRaises(POSException.UndoError,
self._begin_undos_vote, t, tid) self._begin_undos_vote, t, tid)
self._storage.tpc_abort(t) self._storage.tpc_abort(t)
...@@ -570,7 +571,7 @@ class TransactionalUndoStorage: ...@@ -570,7 +571,7 @@ class TransactionalUndoStorage:
orig = [] orig = []
for i in range(BATCHES): for i in range(BATCHES):
t = Transaction() t = TransactionMetaData()
tid = p64(i + 1) tid = p64(i + 1)
s.tpc_begin(t, tid) s.tpc_begin(t, tid)
for j in range(OBJECTS): for j in range(OBJECTS):
...@@ -593,7 +594,7 @@ class TransactionalUndoStorage: ...@@ -593,7 +594,7 @@ class TransactionalUndoStorage:
def undo(i): def undo(i):
info = s.undoInfo() info = s.undoInfo()
t = Transaction() t = TransactionMetaData()
s.tpc_begin(t) s.tpc_begin(t)
base = i * OBJECTS + i base = i * OBJECTS + i
for j in range(OBJECTS): for j in range(OBJECTS):
......
...@@ -24,6 +24,7 @@ import ZODB.tests.testblob ...@@ -24,6 +24,7 @@ import ZODB.tests.testblob
import zope.testing.setupstack import zope.testing.setupstack
from ZODB import POSException from ZODB import POSException
from ZODB import DB from ZODB import DB
from ZODB.Connection import TransactionMetaData
from ZODB.fsIndex import fsIndex from ZODB.fsIndex import fsIndex
from ZODB.utils import U64, p64, z64, load_current from ZODB.utils import U64, p64, z64, load_current
...@@ -182,7 +183,7 @@ class FileStorageTests( ...@@ -182,7 +183,7 @@ class FileStorageTests(
# If .store() is handed an oid bigger than the storage knows # If .store() is handed an oid bigger than the storage knows
# about already, it's crucial that the storage bump its notion # about already, it's crucial that the storage bump its notion
# of the largest oid in use. # of the largest oid in use.
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
giant_oid = b'\xee' * 8 giant_oid = b'\xee' * 8
# Store an object. # Store an object.
...@@ -199,7 +200,7 @@ class FileStorageTests( ...@@ -199,7 +200,7 @@ class FileStorageTests(
# knows about already, it's crucial that the storage bump its notion # knows about already, it's crucial that the storage bump its notion
# of the largest oid in use. Because copyTransactionsFrom(), and # of the largest oid in use. Because copyTransactionsFrom(), and
# ZRS recovery, use the .restore() method, this is plain critical. # ZRS recovery, use the .restore() method, this is plain critical.
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
giant_oid = b'\xee' * 8 giant_oid = b'\xee' * 8
# Store an object. # Store an object.
...@@ -289,7 +290,7 @@ class FileStorageTests( ...@@ -289,7 +290,7 @@ class FileStorageTests(
def checkFlushAfterTruncate(self, fail=False): def checkFlushAfterTruncate(self, fail=False):
r0 = self._dostore(z64) r0 = self._dostore(z64)
storage = self._storage storage = self._storage
t = transaction.Transaction() t = TransactionMetaData()
storage.tpc_begin(t) storage.tpc_begin(t)
storage.store(z64, r0, b'foo', b'', t) storage.store(z64, r0, b'foo', b'', t)
storage.tpc_vote(t) storage.tpc_vote(t)
...@@ -421,7 +422,7 @@ class AnalyzeDotPyTest(StorageTestBase.StorageTestBase): ...@@ -421,7 +422,7 @@ class AnalyzeDotPyTest(StorageTestBase.StorageTestBase):
self._storage.store(oid, revid, data, "", t) self._storage.store(oid, revid, data, "", t)
for i in range(2): for i in range(2):
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
# sometimes data is in this format # sometimes data is in this format
......
...@@ -16,6 +16,7 @@ import unittest ...@@ -16,6 +16,7 @@ import unittest
from persistent.mapping import PersistentMapping from persistent.mapping import PersistentMapping
import transaction import transaction
from ZODB.Connection import TransactionMetaData
from ZODB.DB import DB from ZODB.DB import DB
from ZODB.tests.MVCCMappingStorage import MVCCMappingStorage from ZODB.tests.MVCCMappingStorage import MVCCMappingStorage
import ZODB.blob import ZODB.blob
...@@ -161,7 +162,7 @@ class MVCCMappingStorageTests( ...@@ -161,7 +162,7 @@ class MVCCMappingStorageTests(
import time import time
from ZODB.utils import newTid from ZODB.utils import newTid
from ZODB.TimeStamp import TimeStamp from ZODB.TimeStamp import TimeStamp
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self._storage.tpc_vote(t) self._storage.tpc_vote(t)
self._storage.tpc_finish(t) self._storage.tpc_finish(t)
...@@ -173,7 +174,7 @@ class MVCCMappingStorageTests( ...@@ -173,7 +174,7 @@ class MVCCMappingStorageTests(
transactions[fake_timestamp] = transactions.values()[0] transactions[fake_timestamp] = transactions.values()[0]
# Verify the next transaction comes after the fake transaction # Verify the next transaction comes after the fake transaction
t = transaction.Transaction() t = TransactionMetaData()
self._storage.tpc_begin(t) self._storage.tpc_begin(t)
self.assertEqual(self._storage._tid, b'zzzzzzzz') self.assertEqual(self._storage._tid, b'zzzzzzzz')
......
...@@ -23,9 +23,8 @@ old code, developers will have a hard time testing the new code. ...@@ -23,9 +23,8 @@ old code, developers will have a hard time testing the new code.
import unittest import unittest
import sys import sys
from transaction import Transaction
import ZODB import ZODB
from ZODB.Connection import TransactionMetaData
from ZODB.MappingStorage import MappingStorage from ZODB.MappingStorage import MappingStorage
from six import PY2 from six import PY2
...@@ -47,7 +46,7 @@ class PMTests(unittest.TestCase): ...@@ -47,7 +46,7 @@ class PMTests(unittest.TestCase):
return return
# insert the pickle in place of the root # insert the pickle in place of the root
s = MappingStorage() s = MappingStorage()
t = Transaction() t = TransactionMetaData()
s.tpc_begin(t) s.tpc_begin(t)
s.store('\000' * 8, None, pickle, '', t) s.store('\000' * 8, None, pickle, '', t)
s.tpc_vote(t) s.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