[Zodb-checkins] CVS: ZODB3/ZODB/tests - testFileStorage.py:1.19.8.1 VersionStorage.py:1.17.4.1 StorageTestBase.py:1.17.8.1

Jeremy Hylton jeremy@zope.com
Fri, 15 Nov 2002 12:19:28 -0500


Update of /cvs-repository/ZODB3/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv1715/ZODB/tests

Modified Files:
      Tag: ZODB3-3_1-branch
	testFileStorage.py VersionStorage.py StorageTestBase.py 
Log Message:
Fix two restore() bugs.

Merge changes from short-lived ZODB3-restore-debug-branch.
Add entry to NEWS file about problem.
Bump version numbers to 3.1.1 and 2.0.1.


=== ZODB3/ZODB/tests/testFileStorage.py 1.19 => 1.19.8.1 ===
--- ZODB3/ZODB/tests/testFileStorage.py:1.19	Wed Aug 14 18:07:09 2002
+++ ZODB3/ZODB/tests/testFileStorage.py	Fri Nov 15 12:18:55 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')


=== ZODB3/ZODB/tests/VersionStorage.py 1.17 => 1.17.4.1 ===
--- ZODB3/ZODB/tests/VersionStorage.py:1.17	Wed Aug 28 14:16:32 2002
+++ ZODB3/ZODB/tests/VersionStorage.py	Fri Nov 15 12:18:55 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.8.1 ===
--- ZODB3/ZODB/tests/StorageTestBase.py:1.17	Wed Aug 14 18:07:09 2002
+++ ZODB3/ZODB/tests/StorageTestBase.py	Fri Nov 15 12:18:55 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
+