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