[Zodb-checkins] CVS: ZODB3/ZODB/tests - testFileStorage.py:1.19.28.1 VersionStorage.py:1.17.24.1 StorageTestBase.py:1.17.32.1
Jeremy Hylton
jeremy@zope.com
Fri, 15 Nov 2002 10:44:43 -0500
Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv23852/ZODB/tests
Modified Files:
Tag: ZODB3-restore-debug-branch
testFileStorage.py VersionStorage.py StorageTestBase.py
Log Message:
Add new test checkRecoverUndoInVersion(), which fails,
and a bunch of new code for debugging that problem.
=== ZODB3/ZODB/tests/testFileStorage.py 1.19 => 1.19.28.1 ===
--- ZODB3/ZODB/tests/testFileStorage.py:1.19 Wed Aug 14 18:07:09 2002
+++ ZODB3/ZODB/tests/testFileStorage.py Fri Nov 15 10:44:12 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,
@@ -76,6 +77,23 @@
StorageTestBase.removefs("Source.fs")
StorageTestBase.removefs("Dest.fs")
+ def _dump(self, path):
+ from ZODB.fsdump import Dumper
+ from cStringIO import StringIO
+ f = StringIO()
+ Dumper(path, f).dump()
+ return f.getvalue()
+
+ def compare(self, storage1, storage2):
+ from difflib import ndiff
+ from ZODB.tests.IteratorStorage import IteratorDeepCompare
+ dump1 = self._dump(storage1.__name__)
+ dump2 = self._dump(storage2.__name__)
+ for line in ndiff(dump1.splitlines(1),
+ dump2.splitlines(2)):
+ print line,
+ IteratorDeepCompare.compare(self, storage1, storage2)
+
def checkSimpleRecovery(self):
oid = self._storage.new_oid()
revid = self._dostore(oid, data=11)
@@ -90,12 +108,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)
@@ -125,6 +138,49 @@
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._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
+ self.compare(self._storage, self._dst)
def test_suite():
suite = unittest.makeSuite(FileStorageTests, 'check')
=== ZODB3/ZODB/tests/VersionStorage.py 1.17 => 1.17.24.1 ===
--- ZODB3/ZODB/tests/VersionStorage.py:1.17 Wed Aug 28 14:16:32 2002
+++ ZODB3/ZODB/tests/VersionStorage.py Fri Nov 15 10:44:12 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))
=== ZODB3/ZODB/tests/StorageTestBase.py 1.17 => 1.17.32.1 ===
--- ZODB3/ZODB/tests/StorageTestBase.py:1.17 Wed Aug 14 18:07:09 2002
+++ ZODB3/ZODB/tests/StorageTestBase.py Fri Nov 15 10:44:12 2002
@@ -181,3 +181,35 @@
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()
+ 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
+