[Zodb-checkins] CVS: Zope/lib/python/ZODB/tests - RecoveryStorage.py:1.1.2.1 StorageTestBase.py:1.17.26.2 testFileStorage.py:1.20.2.2

Andreas Jung andreas@andreas-jung.com
Sat, 16 Nov 2002 11:41:16 -0500


Update of /cvs-repository/Zope/lib/python/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv25283/ZODB/tests

Modified Files:
      Tag: ajung-restructuredtext-integration-branch
	RecoveryStorage.py StorageTestBase.py testFileStorage.py 
Log Message:
merge from trunk

=== Zope/lib/python/ZODB/tests/RecoveryStorage.py 1.1 => 1.1.2.1 ===
--- Zope/lib/python/ZODB/tests/RecoveryStorage.py:1.1	Thu Oct 24 09:51:23 2002
+++ Zope/lib/python/ZODB/tests/RecoveryStorage.py	Sat Nov 16 11:40:45 2002
@@ -2,6 +2,7 @@
 
 from ZODB.Transaction import Transaction
 from ZODB.tests.IteratorStorage import IteratorDeepCompare
+from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle
 
 
 class RecoveryStorage(IteratorDeepCompare):
@@ -55,3 +56,50 @@
             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))
+
+        # Now remove _dst and copy all the transactions a second time.
+        # This time we will be able to confirm via compare().
+        self._storage = tmp
+        self._dst.close()
+        self._dst = self.new_dest()
+        self._dst.copyTransactionsFrom(self._storage)
+        self.compare(self._storage, self._dst)


=== Zope/lib/python/ZODB/tests/StorageTestBase.py 1.17.26.1 => 1.17.26.2 ===
--- Zope/lib/python/ZODB/tests/StorageTestBase.py:1.17.26.1	Sat Nov  9 03:43:00 2002
+++ Zope/lib/python/ZODB/tests/StorageTestBase.py	Sat Nov 16 11:40:45 2002
@@ -180,3 +180,36 @@
     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


=== Zope/lib/python/ZODB/tests/testFileStorage.py 1.20.2.1 => 1.20.2.2 ===
--- Zope/lib/python/ZODB/tests/testFileStorage.py:1.20.2.1	Sat Nov  9 03:43:00 2002
+++ Zope/lib/python/ZODB/tests/testFileStorage.py	Sat Nov 16 11:40:45 2002
@@ -72,6 +72,10 @@
         StorageTestBase.removefs("Source.fs")
         StorageTestBase.removefs("Dest.fs")
 
+    def new_dest(self):
+        StorageTestBase.removefs('Dest.fs')
+        return ZODB.FileStorage.FileStorage('Dest.fs')
+
 
 def test_suite():
     suite = unittest.makeSuite(FileStorageTests, 'check')