Commit 45376017 authored by Jeremy Hylton's avatar Jeremy Hylton

Merge tests changes from the Standby-branch branch

parent d721ad08
...@@ -10,7 +10,8 @@ from ZODB.Transaction import Transaction ...@@ -10,7 +10,8 @@ from ZODB.Transaction import Transaction
from ZODB import POSException from ZODB import POSException
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, handle_serials
ZERO = '\0'*8 ZERO = '\0'*8
...@@ -77,7 +78,7 @@ class BasicStorage: ...@@ -77,7 +78,7 @@ class BasicStorage:
'', txn) '', txn)
r2 = self._storage.tpc_vote(txn) r2 = self._storage.tpc_vote(txn)
self._storage.tpc_finish(txn) self._storage.tpc_finish(txn)
newrevid = self._handle_serials(oid, r1, r2) newrevid = handle_serials(oid, r1, r2)
data, revid = self._storage.load(oid, '') data, revid = self._storage.load(oid, '')
value = zodb_unpickle(data) value = zodb_unpickle(data)
eq(value, MinPO(11)) eq(value, MinPO(11))
...@@ -173,3 +174,14 @@ class BasicStorage: ...@@ -173,3 +174,14 @@ class BasicStorage:
# And another one # And another one
revid2 = self._dostore(oid, revid=revid1, data=p42) revid2 = self._dostore(oid, revid=revid1, data=p42)
eq(revid2, self._storage.getSerial(oid)) eq(revid2, self._storage.getSerial(oid))
def checkTwoArgBegin(self):
# XXX how standard is three-argument tpc_begin()?
t = Transaction()
tid = chr(42) * 8
self._storage.tpc_begin(t, tid)
oid = self._storage.new_oid()
data = zodb_pickle(MinPO(8))
self._storage.store(oid, None, data, '', t)
self._storage.tpc_vote(t)
self._storage.tpc_finish(t)
...@@ -14,9 +14,9 @@ class FileStorageCorruptTests(StorageTestBase): ...@@ -14,9 +14,9 @@ class FileStorageCorruptTests(StorageTestBase):
__super_tearDown = StorageTestBase.tearDown __super_tearDown = StorageTestBase.tearDown
def setUp(self): def setUp(self):
self.__super_setUp()
self.path = tempfile.mktemp() self.path = tempfile.mktemp()
self._storage = ZODB.FileStorage.FileStorage(self.path, create=1) self._storage = ZODB.FileStorage.FileStorage(self.path, create=1)
self.__super_setUp()
def tearDown(self): def tearDown(self):
self.__super_tearDown() self.__super_tearDown()
......
...@@ -6,21 +6,17 @@ all these tests. ...@@ -6,21 +6,17 @@ all these tests.
from ZODB.tests.MinPO import MinPO from ZODB.tests.MinPO import MinPO
from ZODB.tests.StorageTestBase import zodb_unpickle from ZODB.tests.StorageTestBase import zodb_unpickle
from ZODB.utils import U64, p64
class IteratorStorage: class IteratorCompare:
def checkSimpleIteration(self):
def iter_verify(self, txniter, revids, val0):
eq = self.assertEqual eq = self.assertEqual
# Store a bunch of revisions of a single object oid = self._oid
oid = self._storage.new_oid() val = val0
revid1 = self._dostore(oid, data=MinPO(11)) for reciter, revid in zip(txniter, revids + [None]):
revid2 = self._dostore(oid, revid=revid1, data=MinPO(12))
revid3 = self._dostore(oid, revid=revid2, data=MinPO(13))
# Now iterate over all the transactions
val = 11
txniter = self._storage.iterator()
for reciter, revid in zip(txniter, (revid1, revid2, revid3)):
eq(reciter.tid, revid) eq(reciter.tid, revid)
for rec in reciter: for rec in reciter:
eq(rec.oid, oid) eq(rec.oid, oid)
...@@ -28,3 +24,54 @@ class IteratorStorage: ...@@ -28,3 +24,54 @@ class IteratorStorage:
eq(rec.version, '') eq(rec.version, '')
eq(zodb_unpickle(rec.data), MinPO(val)) eq(zodb_unpickle(rec.data), MinPO(val))
val = val + 1 val = val + 1
eq(val, val0 + len(revids))
class IteratorStorage(IteratorCompare):
def checkSimpleIteration(self):
# Store a bunch of revisions of a single object
self._oid = oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
revid2 = self._dostore(oid, revid=revid1, data=MinPO(12))
revid3 = self._dostore(oid, revid=revid2, data=MinPO(13))
# Now iterate over all the transactions and compare carefully
txniter = self._storage.iterator()
self.iter_verify(txniter, [revid1, revid2, revid3], 11)
class ExtendedIteratorStorage(IteratorCompare):
def checkExtendedIteration(self):
# Store a bunch of revisions of a single object
self._oid = oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(11))
revid2 = self._dostore(oid, revid=revid1, data=MinPO(12))
revid3 = self._dostore(oid, revid=revid2, data=MinPO(13))
revid4 = self._dostore(oid, revid=revid3, data=MinPO(14))
# Note that the end points are included
# Iterate over all of the transactions with explicit start/stop
txniter = self._storage.iterator(revid1, revid4)
self.iter_verify(txniter, [revid1, revid2, revid3, revid4], 11)
# Iterate over some of the transactions with explicit start
txniter = self._storage.iterator(revid3)
self.iter_verify(txniter, [revid3, revid4], 13)
# Iterate over some of the transactions with explicit stop
txniter = self._storage.iterator(None, revid2)
self.iter_verify(txniter, [revid1, revid2], 11)
# Iterate over some of the transactions with explicit start+stop
txniter = self._storage.iterator(revid2, revid3)
self.iter_verify(txniter, [revid2, revid3], 12)
# Specify an upper bound somewhere in between values
revid3a = p64((U64(revid3) + U64(revid4)) / 2)
txniter = self._storage.iterator(revid2, revid3a)
self.iter_verify(txniter, [revid2, revid3], 12)
# Specify a lower bound somewhere in between values
revid1a = p64((U64(revid1) + U64(revid2)) / 2)
txniter = self._storage.iterator(revid1a, revid3a)
self.iter_verify(txniter, [revid2, revid3], 12)
# Specify an empty range
txniter = self._storage.iterator(revid3, revid2)
self.iter_verify(txniter, [], 13)
# Specify a singleton range
txniter = self._storage.iterator(revid3, revid3)
self.iter_verify(txniter, [revid3], 13)
...@@ -67,28 +67,7 @@ def zodb_unpickle(data): ...@@ -67,28 +67,7 @@ def zodb_unpickle(data):
inst.__setstate__(state) inst.__setstate__(state)
return inst return inst
def import_helper(name): def handle_all_serials(oid, *args):
mod = __import__(name)
for part in string.split(name, ".")[1:]:
mod = getattr(mod, part)
return mod
class StorageTestBase(unittest.TestCase):
def setUp(self):
# You need to override this with a setUp that creates self._storage
self._transaction = Transaction()
def _close(self):
# You should override this if closing your storage requires additional
# shutdown operations.
self._transaction.abort()
self._storage.close()
def tearDown(self):
self._close()
def _handle_all_serials(self, oid, *args):
"""Return dict of oid to serialno from store() and tpc_vote(). """Return dict of oid to serialno from store() and tpc_vote().
Raises an exception if one of the calls raised an exception. Raises an exception if one of the calls raised an exception.
...@@ -114,13 +93,35 @@ class StorageTestBase(unittest.TestCase): ...@@ -114,13 +93,35 @@ class StorageTestBase(unittest.TestCase):
d[oid] = serial d[oid] = serial
return d return d
def _handle_serials(self, oid, *args): def handle_serials(oid, *args):
"""Return the serialno for oid based on multiple return values. """Return the serialno for oid based on multiple return values.
A helper for function _handle_all_serials(). A helper for function _handle_all_serials().
""" """
args = (oid,) + args args = (oid,) + args
return apply(self._handle_all_serials, args)[oid] return apply(handle_all_serials, args)[oid]
def import_helper(name):
mod = __import__(name)
return sys.modules[name]
class StorageTestBase(unittest.TestCase):
def setUp(self):
# You need to override this with a setUp that creates self._storage
self._transaction = Transaction()
self._storage = None
def _close(self):
# You should override this if closing your storage requires additional
# shutdown operations.
if self._transaction:
self._transaction.abort()
if self._storage is not None:
self._storage.close()
def tearDown(self):
self._close()
def _dostore(self, oid=None, revid=None, data=None, version=None, def _dostore(self, oid=None, revid=None, data=None, version=None,
already_pickled=0): already_pickled=0):
...@@ -146,6 +147,7 @@ class StorageTestBase(unittest.TestCase): ...@@ -146,6 +147,7 @@ class StorageTestBase(unittest.TestCase):
if version is None: if version is None:
version = '' version = ''
# Begin the transaction # Begin the transaction
self._transaction = Transaction()
self._storage.tpc_begin(self._transaction) self._storage.tpc_begin(self._transaction)
# Store an object # Store an object
r1 = self._storage.store(oid, revid, data, version, r1 = self._storage.store(oid, revid, data, version,
...@@ -153,7 +155,7 @@ class StorageTestBase(unittest.TestCase): ...@@ -153,7 +155,7 @@ class StorageTestBase(unittest.TestCase):
# Finish the transaction # Finish the transaction
r2 = self._storage.tpc_vote(self._transaction) r2 = self._storage.tpc_vote(self._transaction)
self._storage.tpc_finish(self._transaction) self._storage.tpc_finish(self._transaction)
return self._handle_serials(oid, r1, r2) return handle_serials(oid, r1, r2)
def _dostoreNP(self, oid=None, revid=None, data=None, version=None): def _dostoreNP(self, oid=None, revid=None, data=None, version=None):
return self._dostore(oid, revid, data, version, already_pickled=1) return self._dostore(oid, revid, data, version, already_pickled=1)
...@@ -11,8 +11,8 @@ class DemoStorageTests(StorageTestBase.StorageTestBase, ...@@ -11,8 +11,8 @@ class DemoStorageTests(StorageTestBase.StorageTestBase,
): ):
def setUp(self): def setUp(self):
self._storage = ZODB.DemoStorage.DemoStorage()
StorageTestBase.StorageTestBase.setUp(self) StorageTestBase.StorageTestBase.setUp(self)
self._storage = ZODB.DemoStorage.DemoStorage()
def test_suite(): def test_suite():
suite = unittest.makeSuite(DemoStorageTests, 'check') suite = unittest.makeSuite(DemoStorageTests, 'check')
......
...@@ -5,7 +5,8 @@ from ZODB.tests import StorageTestBase, BasicStorage, \ ...@@ -5,7 +5,8 @@ from ZODB.tests import StorageTestBase, BasicStorage, \
TransactionalUndoStorage, VersionStorage, \ TransactionalUndoStorage, VersionStorage, \
TransactionalUndoVersionStorage, PackableStorage, \ TransactionalUndoVersionStorage, PackableStorage, \
Synchronization, ConflictResolution, HistoryStorage, \ Synchronization, ConflictResolution, HistoryStorage, \
IteratorStorage, Corruption, RevisionStorage, PersistentStorage IteratorStorage, Corruption, RevisionStorage, PersistentStorage, \
MTStorage, ReadOnlyStorage
class FileStorageTests( class FileStorageTests(
StorageTestBase.StorageTestBase, StorageTestBase.StorageTestBase,
...@@ -19,7 +20,10 @@ class FileStorageTests( ...@@ -19,7 +20,10 @@ class FileStorageTests(
ConflictResolution.ConflictResolvingStorage, ConflictResolution.ConflictResolvingStorage,
HistoryStorage.HistoryStorage, HistoryStorage.HistoryStorage,
IteratorStorage.IteratorStorage, IteratorStorage.IteratorStorage,
IteratorStorage.ExtendedIteratorStorage,
PersistentStorage.PersistentStorage, PersistentStorage.PersistentStorage,
MTStorage.MTStorage,
ReadOnlyStorage.ReadOnlyStorage
): ):
def open(self, **kwargs): def open(self, **kwargs):
...@@ -31,8 +35,8 @@ class FileStorageTests( ...@@ -31,8 +35,8 @@ class FileStorageTests(
'FileStorageTests.fs', **kwargs) 'FileStorageTests.fs', **kwargs)
def setUp(self): def setUp(self):
self.open(create=1)
StorageTestBase.StorageTestBase.setUp(self) StorageTestBase.StorageTestBase.setUp(self)
self.open(create=1)
def tearDown(self): def tearDown(self):
StorageTestBase.StorageTestBase.tearDown(self) StorageTestBase.StorageTestBase.tearDown(self)
......
...@@ -9,8 +9,8 @@ class MappingStorageTests(StorageTestBase.StorageTestBase, ...@@ -9,8 +9,8 @@ class MappingStorageTests(StorageTestBase.StorageTestBase,
): ):
def setUp(self): def setUp(self):
self._storage = ZODB.MappingStorage.MappingStorage()
StorageTestBase.StorageTestBase.setUp(self) StorageTestBase.StorageTestBase.setUp(self)
self._storage = ZODB.MappingStorage.MappingStorage()
def test_suite(): def test_suite():
suite = unittest.makeSuite(MappingStorageTests, 'check') suite = unittest.makeSuite(MappingStorageTests, 'check')
......
...@@ -64,7 +64,6 @@ class PMTests(unittest.TestCase): ...@@ -64,7 +64,6 @@ class PMTests(unittest.TestCase):
def find_global(modulename, classname): def find_global(modulename, classname):
"""Helper for this test suite to get special PersistentMapping""" """Helper for this test suite to get special PersistentMapping"""
#print modulename, classname
if classname == "PersistentMapping": if classname == "PersistentMapping":
class PersistentMapping: class PersistentMapping:
def __setstate__(self, state): def __setstate__(self, state):
......
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