Commit f351e577 authored by Jeremy Hylton's avatar Jeremy Hylton

Fix tests to account for ZEO's load() & tpc_vote() return values

parent 5bedc346
...@@ -73,10 +73,11 @@ class BasicStorage: ...@@ -73,10 +73,11 @@ class BasicStorage:
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.
newrevid = self._storage.store(oid, None, zodb_pickle(MinPO(11)), r1 = self._storage.store(oid, None, zodb_pickle(MinPO(11)),
'', txn) '', txn)
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)
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))
...@@ -118,22 +119,22 @@ class BasicStorage: ...@@ -118,22 +119,22 @@ class BasicStorage:
def checkWriteAfterAbort(self): def checkWriteAfterAbort(self):
oid = self._storage.new_oid() oid = self._storage.new_oid()
self._storage.tpc_begin(self._transaction) self._storage.tpc_begin(self._transaction)
revid = self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)),
'', self._transaction) '', self._transaction)
# Now abort this transaction # Now abort this transaction
self._storage.tpc_abort(self._transaction) self._storage.tpc_abort(self._transaction)
# Now start all over again # Now start all over again
self._transaction = Transaction() self._transaction = Transaction()
oid = self._storage.new_oid() oid = self._storage.new_oid()
revid = self._dostore(oid=oid, data=MinPO(6)) self._dostore(oid=oid, data=MinPO(6))
def checkAbortAfterVote(self): def checkAbortAfterVote(self):
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()
self._storage.tpc_begin(self._transaction) self._storage.tpc_begin(self._transaction)
revid = self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)), self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)),
'', self._transaction) '', self._transaction)
# Now abort this transaction # Now abort this transaction
self._storage.tpc_vote(self._transaction) self._storage.tpc_vote(self._transaction)
self._storage.tpc_abort(self._transaction) self._storage.tpc_abort(self._transaction)
......
...@@ -126,6 +126,10 @@ class PackableStorage(PackableStorageBase): ...@@ -126,6 +126,10 @@ class PackableStorage(PackableStorageBase):
self._initroot() self._initroot()
self._storage.pack(time.time() + 10000, referencesf) self._storage.pack(time.time() + 10000, referencesf)
def checkPackYesterday(self):
self._initroot()
self._storage.pack(time.time() - 10000, referencesf)
def checkPackAllRevisions(self): def checkPackAllRevisions(self):
self._initroot() self._initroot()
eq = self.assertEqual eq = self.assertEqual
......
...@@ -88,6 +88,40 @@ class StorageTestBase(unittest.TestCase): ...@@ -88,6 +88,40 @@ class StorageTestBase(unittest.TestCase):
def tearDown(self): def tearDown(self):
self._close() self._close()
def _handle_all_serials(self, oid, *args):
"""Return dict of oid to serialno from store() and tpc_vote().
Raises an exception if one of the calls raised an exception.
The storage interface got complicated when ZEO was introduced.
Any individual store() call can return None or a sequence of
2-tuples where the 2-tuple is either oid, serialno or an
exception to be raised by the client.
The original interface just returned the serialno for the
object.
"""
d = {}
for arg in args:
if isinstance(arg, types.StringType):
d[oid] = arg
elif arg is None:
pass
else:
for oid, serial in arg:
if not isinstance(serial, types.StringType):
raise arg
d[oid] = serial
return d
def _handle_serials(self, oid, *args):
"""Return the serialno for oid based on multiple return values.
A helper for function _handle_all_serials().
"""
args = (oid,) + args
return apply(self._handle_all_serials, args)[oid]
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):
"""Do a complete storage transaction. The defaults are: """Do a complete storage transaction. The defaults are:
...@@ -114,12 +148,12 @@ class StorageTestBase(unittest.TestCase): ...@@ -114,12 +148,12 @@ class StorageTestBase(unittest.TestCase):
# Begin the transaction # Begin the transaction
self._storage.tpc_begin(self._transaction) self._storage.tpc_begin(self._transaction)
# Store an object # Store an object
newrevid = self._storage.store(oid, revid, data, version, r1 = self._storage.store(oid, revid, data, version,
self._transaction) self._transaction)
# Finish the transaction # Finish the transaction
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 newrevid return self._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)
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