[Zope-Checkins] CVS: Zope/lib/python/ZODB/tests - testFileStorage.py:1.19.6.1 VersionStorage.py:1.17.2.1 TransactionalUndoVersionStorage.py:1.8.6.1 StorageTestBase.py:1.17.6.1
Jeremy Hylton
jeremy@zope.com
Fri, 15 Nov 2002 12:45:33 -0500
Update of /cvs-repository/Zope/lib/python/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv5028/lib/python/ZODB/tests
Modified Files:
Tag: Zope-2_6-branch
testFileStorage.py VersionStorage.py
TransactionalUndoVersionStorage.py StorageTestBase.py
Log Message:
Fix two problems with restore() and backpointers.
Merge ZODB3-restore-debug-branch and misc changes from
ZODB3-3_1-branch.
=== Zope/lib/python/ZODB/tests/testFileStorage.py 1.19 => 1.19.6.1 ===
--- Zope/lib/python/ZODB/tests/testFileStorage.py:1.19 Wed Aug 14 18:07:09 2002
+++ Zope/lib/python/ZODB/tests/testFileStorage.py Fri Nov 15 12:45:02 2002
@@ -12,6 +12,7 @@
Synchronization, ConflictResolution, HistoryStorage, \
IteratorStorage, Corruption, RevisionStorage, PersistentStorage, \
MTStorage, ReadOnlyStorage
+from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle
class FileStorageTests(
StorageTestBase.StorageTestBase,
@@ -67,6 +68,8 @@
):
def setUp(self):
+ StorageTestBase.removefs("Source.fs")
+ StorageTestBase.removefs("Dest.fs")
self._storage = ZODB.FileStorage.FileStorage('Source.fs')
self._dst = ZODB.FileStorage.FileStorage('Dest.fs')
@@ -90,12 +93,7 @@
revid = self._dostore(oid, revid=revid, data=22)
revid = self._dostore(oid, revid=revid, data=23, version='one')
revid = self._dostore(oid, revid=revid, data=34, version='one')
- # Now commit the version
- t = Transaction()
- self._storage.tpc_begin(t)
- self._storage.commitVersion('one', '', t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
+ self._commitVersion("one", "")
self._dst.copyTransactionsFrom(self._storage)
self.compare(self._storage, self._dst)
@@ -104,12 +102,7 @@
revid = self._dostore(oid, data=21, version="one")
revid = self._dostore(oid, revid=revid, data=23, version='one')
revid = self._dostore(oid, revid=revid, data=34, version='one')
- # Now abort the version and the creation
- t = Transaction()
- self._storage.tpc_begin(t)
- oids = self._storage.abortVersion('one', t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
+ oids = self._abortVersion("one")
self.assertEqual(oids, [oid])
self._dst.copyTransactionsFrom(self._storage)
self.compare(self._storage, self._dst)
@@ -125,6 +118,63 @@
self.assertEqual(data.oid, oid)
self.assertEqual(data.data, None)
+ def checkRecoverUndoInVersion(self):
+ oid = self._storage.new_oid()
+ version = "aVersion"
+ revid_a = self._dostore(oid, data=MinPO(91))
+ revid_b = self._dostore(oid, revid=revid_a, version=version,
+ data=MinPO(92))
+ revid_c = self._dostore(oid, revid=revid_b, version=version,
+ data=MinPO(93))
+ self._undo(self._storage.undoInfo()[0]['id'], oid)
+ self._commitVersion(version, '')
+ self._undo(self._storage.undoInfo()[0]['id'], oid)
+
+ # now copy the records to a new storage
+ self._dst.copyTransactionsFrom(self._storage)
+ self.compare(self._storage, self._dst)
+
+ # The last two transactions were applied directly rather than
+ # copied. So we can't use compare() to verify that they new
+ # transactions are applied correctly. (The new transactions
+ # will have different timestamps for each storage.)
+
+ self._abortVersion(version)
+ self.assert_(self._storage.versionEmpty(version))
+ self._undo(self._storage.undoInfo()[0]['id'], oid)
+ self.assert_(not self._storage.versionEmpty(version))
+
+ # check the data is what we expect it to be
+ data, revid = self._storage.load(oid, version)
+ self.assertEqual(zodb_unpickle(data), MinPO(92))
+ data, revid = self._storage.load(oid, '')
+ self.assertEqual(zodb_unpickle(data), MinPO(91))
+
+ # and swap the storages
+ tmp = self._storage
+ self._storage = self._dst
+ self._abortVersion(version)
+ self.assert_(self._storage.versionEmpty(version))
+ self._undo(self._storage.undoInfo()[0]['id'], oid)
+ self.assert_(not self._storage.versionEmpty(version))
+
+ # check the data is what we expect it to be
+ data, revid = self._storage.load(oid, version)
+ self.assertEqual(zodb_unpickle(data), MinPO(92))
+ data, revid = self._storage.load(oid, '')
+ self.assertEqual(zodb_unpickle(data), MinPO(91))
+
+ # swap them back
+ self._storage = tmp
+
+ # Now remove _dst and copy all the transactions a second time.
+ # This time we will be able to confirm via compare().
+ self._dst.close()
+ StorageTestBase.removefs("Dest.fs")
+ self._dst = ZODB.FileStorage.FileStorage('Dest.fs')
+ self._dst.copyTransactionsFrom(self._storage)
+ self.compare(self._storage, self._dst)
+
def test_suite():
suite = unittest.makeSuite(FileStorageTests, 'check')
=== Zope/lib/python/ZODB/tests/VersionStorage.py 1.17 => 1.17.2.1 ===
--- Zope/lib/python/ZODB/tests/VersionStorage.py:1.17 Wed Aug 28 14:16:32 2002
+++ Zope/lib/python/ZODB/tests/VersionStorage.py Fri Nov 15 12:45:02 2002
@@ -14,22 +14,6 @@
class VersionStorage:
- def _commitVersion(self, src, dst):
- t = Transaction()
- self._storage.tpc_begin(t)
- oids = self._storage.commitVersion(src, dst, t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
- return oids
-
- def _abortVersion(self, ver):
- t = Transaction()
- self._storage.tpc_begin(t)
- oids = self._storage.abortVersion(ver, t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
- return oids
-
def checkCommitVersionSerialno(self):
oid = self._storage.new_oid()
revid1 = self._dostore(oid, data=MinPO(12))
=== Zope/lib/python/ZODB/tests/TransactionalUndoVersionStorage.py 1.8 => 1.8.6.1 ===
--- Zope/lib/python/ZODB/tests/TransactionalUndoVersionStorage.py:1.8 Wed Aug 14 18:07:09 2002
+++ Zope/lib/python/ZODB/tests/TransactionalUndoVersionStorage.py Fri Nov 15 12:45:02 2002
@@ -29,7 +29,23 @@
pass # not expected
return self._dostore(*args, **kwargs)
+ def _undo(self, tid, oid):
+ t = Transaction()
+ self._storage.tpc_begin(t)
+ oids = self._storage.transactionalUndo(tid, t)
+ self._storage.tpc_vote(t)
+ self._storage.tpc_finish(t)
+ self.assertEqual(len(oids), 1)
+ self.assertEqual(oids[0], oid)
+
def checkUndoInVersion(self):
+
+ def check_objects(nonversiondata, versiondata):
+ data, revid = self._storage.load(oid, version)
+ self.assertEqual(zodb_unpickle(data), MinPO(versiondata))
+ data, revid = self._storage.load(oid, '')
+ self.assertEqual(zodb_unpickle(data), MinPO(nonversiondata))
+
oid = self._storage.new_oid()
version = 'one'
revid_a = self._dostore(oid, data=MinPO(91))
@@ -37,21 +53,17 @@
version=version)
revid_c = self._dostore(oid, revid=revid_b, data=MinPO(93),
version=version)
- info=self._storage.undoInfo()
- tid=info[0]['id']
- t = Transaction()
- self._storage.tpc_begin(t)
- oids = self._storage.transactionalUndo(tid, t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
- assert len(oids) == 1
- assert oids[0] == oid
+
+ info = self._storage.undoInfo()
+ self._undo(info[0]['id'], oid)
+
data, revid = self._storage.load(oid, '')
assert revid == revid_a
assert zodb_unpickle(data) == MinPO(91)
data, revid = self._storage.load(oid, version)
assert revid > revid_b and revid > revid_c
assert zodb_unpickle(data) == MinPO(92)
+
# Now commit the version...
t = Transaction()
self._storage.tpc_begin(t)
@@ -61,28 +73,14 @@
assert len(oids) == 1
assert oids[0] == oid
- #JF# No, because we fall back to non-version data.
- #JF# self.assertRaises(POSException.VersionError,
- #JF# self._storage.load,
- #JF# oid, version)
- data, revid = self._storage.load(oid, version)
- assert zodb_unpickle(data) == MinPO(92)
- data, revid = self._storage.load(oid, '')
- assert zodb_unpickle(data) == MinPO(92)
+ check_objects(92, 92)
+
# ...and undo the commit
- info=self._storage.undoInfo()
- tid=info[0]['id']
- t = Transaction()
- self._storage.tpc_begin(t)
- oids = self._storage.transactionalUndo(tid, t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
- assert len(oids) == 1
- assert oids[0] == oid
- data, revid = self._storage.load(oid, version)
- assert zodb_unpickle(data) == MinPO(92)
- data, revid = self._storage.load(oid, '')
- assert zodb_unpickle(data) == MinPO(91)
+ info = self._storage.undoInfo()
+ self._undo(info[0]['id'], oid)
+
+ check_objects(91, 92)
+
# Now abort the version
t = Transaction()
self._storage.tpc_begin(t)
@@ -91,31 +89,15 @@
self._storage.tpc_finish(t)
assert len(oids) == 1
assert oids[0] == oid
- # The object should not exist in the version now, but it should exist
- # in the non-version
- #JF# No, because we fall back
- #JF# self.assertRaises(POSException.VersionError,
- #JF# self._storage.load,
- #JF# oid, version)
- data, revid = self._storage.load(oid, version)
- assert zodb_unpickle(data) == MinPO(91)
- data, revid = self._storage.load(oid, '')
- assert zodb_unpickle(data) == MinPO(91)
+
+ check_objects(91, 91)
+
# Now undo the abort
info=self._storage.undoInfo()
- tid=info[0]['id']
- t = Transaction()
- self._storage.tpc_begin(t)
- oids = self._storage.transactionalUndo(tid, t)
- self._storage.tpc_vote(t)
- self._storage.tpc_finish(t)
- assert len(oids) == 1
- assert oids[0] == oid
+ self._undo(info[0]['id'], oid)
+
# And the object should be back in versions 'one' and ''
- data, revid = self._storage.load(oid, version)
- assert zodb_unpickle(data) == MinPO(92)
- data, revid = self._storage.load(oid, '')
- assert zodb_unpickle(data) == MinPO(91)
+ check_objects(91, 92)
def checkUndoCommitVersion(self):
def load_value(oid, version=''):
=== Zope/lib/python/ZODB/tests/StorageTestBase.py 1.17 => 1.17.6.1 ===
--- Zope/lib/python/ZODB/tests/StorageTestBase.py:1.17 Wed Aug 14 18:07:09 2002
+++ Zope/lib/python/ZODB/tests/StorageTestBase.py Fri Nov 15 12:45:03 2002
@@ -181,3 +181,37 @@
def _dostoreNP(self, oid=None, revid=None, data=None, version=None,
user=None, description=None):
return self._dostore(oid, revid, data, version, already_pickled=1)
+
+ # The following methods depend on optional storage features.
+
+ def _undo(self, tid, oid):
+ # Undo a tid that affects a single object (oid).
+ # XXX This is very specialized
+ t = Transaction()
+ t.note("undo")
+ self._storage.tpc_begin(t)
+ oids = self._storage.transactionalUndo(tid, t)
+ self._storage.tpc_vote(t)
+ self._storage.tpc_finish(t)
+ self.assertEqual(len(oids), 1)
+ self.assertEqual(oids[0], oid)
+ return self._storage.lastTransaction()
+
+ def _commitVersion(self, src, dst):
+ t = Transaction()
+ t.note("commit %r to %r" % (src, dst))
+ self._storage.tpc_begin(t)
+ oids = self._storage.commitVersion(src, dst, t)
+ self._storage.tpc_vote(t)
+ self._storage.tpc_finish(t)
+ return oids
+
+ def _abortVersion(self, ver):
+ t = Transaction()
+ t.note("abort %r" % ver)
+ self._storage.tpc_begin(t)
+ oids = self._storage.abortVersion(ver, t)
+ self._storage.tpc_vote(t)
+ self._storage.tpc_finish(t)
+ return oids
+