[Zodb-checkins] CVS: ZODB3/ZODB/tests - VersionStorage.py:1.23.8.2.2.1 TransactionalUndoVersionStorage.py:1.11.34.1.2.1 TransactionalUndoStorage.py:1.32.6.1.2.1 StorageTestBase.py:1.27.6.1.2.1 RecoveryStorage.py:1.8.6.2.2.1

Jeremy Hylton jeremy at zope.com
Mon Sep 29 14:24:09 EDT 2003


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

Modified Files:
      Tag: ZODB3-mvcc-branch
	VersionStorage.py TransactionalUndoVersionStorage.py 
	TransactionalUndoStorage.py StorageTestBase.py 
	RecoveryStorage.py 
Log Message:
First cut at MVCC implementation for FileStorage.

Two tests fail sporadically: checkNZODBThreads() and checkPackWhileWriting().
The latter probably fails because it occasionally returns data from a
packed transaction, which shouldn't be allowed.

loadNonCurrent() is implemented as a hack in BaseStorage.  It can't be
implemented correctly using history(), because history doesn't return
transaction ids and because history doesn't give any indication of
whether the transaction containing the object was packed.

The DB API had to change so that tids can be passed with all
invalidations.  (Up until now, only ZEO passed a tid with an
invalidation.)  Currently, the storage doesn't expose the current
transaction id to the database.  As a result, abortVersion(),
commitVersion(), and transactionalUndo() need to return a tid as well
as oids.  The callback passed to tpc_finish() needs to take a tid as
well as oids as arguments.

Many tests needed to be updated to track the changes to the storage
API.

I expect ZEO and BDBStorage will fail in a variety of ways.



=== ZODB3/ZODB/tests/VersionStorage.py 1.23.8.2 => 1.23.8.2.2.1 ===
--- ZODB3/ZODB/tests/VersionStorage.py:1.23.8.2	Mon Sep 15 17:26:57 2003
+++ ZODB3/ZODB/tests/VersionStorage.py	Mon Sep 29 14:23:38 2003
@@ -197,13 +197,6 @@
         t = Transaction()
         self._storage.tpc_begin(t)
 
-        #JF# The spec is silent on what happens if you abort or commit
-        #JF# a non-existent version. FileStorage consideres this a noop.
-        #JF# We can change the spec, but until we do ....
-        #JF# self.assertRaises(POSException.VersionError,
-        #JF#                   self._storage.abortVersion,
-        #JF#                   'bogus', t)
-
         # And try to abort the empty version
         if (hasattr(self._storage, 'supportsTransactionalUndo')
             and self._storage.supportsTransactionalUndo()):
@@ -213,7 +206,7 @@
                               '', t)
 
         # But now we really try to abort the version
-        oids = self._storage.abortVersion(version, t)
+        tid, oids = self._storage.abortVersion(version, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         eq(len(oids), 1)
@@ -376,7 +369,7 @@
         # Now abort the version and the creation
         t = Transaction()
         self._storage.tpc_begin(t)
-        oids = self._storage.abortVersion('one', t)
+        tid, oids = self._storage.abortVersion('one', t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         self.assertEqual(oids, [oid])


=== ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py 1.11.34.1 => 1.11.34.1.2.1 ===
--- ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py:1.11.34.1	Mon Sep 15 17:26:57 2003
+++ ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py	Mon Sep 29 14:23:38 2003
@@ -42,15 +42,6 @@
                 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):
         eq = self.assertEqual
         unless = self.failUnless
@@ -70,7 +61,7 @@
                                 version=version)
 
         info = self._storage.undoInfo()
-        self._undo(info[0]['id'], oid)
+        self._undo(info[0]['id'], [oid])
 
         data, revid = self._storage.load(oid, '')
         eq(revid, revid_a)
@@ -80,11 +71,7 @@
         eq(zodb_unpickle(data), MinPO(92))
 
         # Now commit the version...
-        t = Transaction()
-        self._storage.tpc_begin(t)
-        oids = self._storage.commitVersion(version, '', t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
+        oids = self._commitVersion(version, "")
         eq(len(oids), 1)
         eq(oids[0], oid)
 
@@ -92,7 +79,7 @@
 
         # ...and undo the commit
         info = self._storage.undoInfo()
-        self._undo(info[0]['id'], oid)
+        self._undo(info[0]['id'], [oid])
 
         check_objects(91, 92)
 
@@ -104,7 +91,7 @@
 
         # Now undo the abort
         info=self._storage.undoInfo()
-        self._undo(info[0]['id'], oid)
+        self._undo(info[0]['id'], [oid])
 
         check_objects(91, 92)
 
@@ -145,12 +132,7 @@
 
         self._storage.pack(pt, referencesf)
 
-        t = Transaction()
-        t.description = 'undo commit version'
-        self._storage.tpc_begin(t)
-        self._storage.transactionalUndo(t_id, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
+        self._undo(t_id, note="undo commit version")
 
         self.assertEqual(load_value(oid1), 0)
         self.assertEqual(load_value(oid1, version), 2)
@@ -191,12 +173,7 @@
         # after abort, we should see non-version data
         self.assertEqual(load_value(oid1, version), 0)
 
-        t = Transaction()
-        t.description = 'undo abort version'
-        self._storage.tpc_begin(t)
-        self._storage.transactionalUndo(t_id, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
+        self._undo(t_id, note="undo abort version")
 
         self.assertEqual(load_value(oid1), 0)
         # t undo will re-create the version
@@ -207,12 +184,7 @@
 
         self._storage.pack(pt, referencesf)
 
-        t = Transaction()
-        t.description = 'undo undo'
-        self._storage.tpc_begin(t)
-        self._storage.transactionalUndo(t_id, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
+        self._undo(t_id, note="undo undo")
 
         # undo of undo will put as back where we started
         self.assertEqual(load_value(oid1), 0)


=== ZODB3/ZODB/tests/TransactionalUndoStorage.py 1.32.6.1 => 1.32.6.1.2.1 ===
--- ZODB3/ZODB/tests/TransactionalUndoStorage.py:1.32.6.1	Mon Sep 15 17:26:57 2003
+++ ZODB3/ZODB/tests/TransactionalUndoStorage.py	Mon Sep 29 14:23:38 2003
@@ -109,53 +109,29 @@
         info = self._storage.undoInfo()
         tid = info[0]['id']
         # Now start an undo transaction
-        t = Transaction()
-        t.note('undo1')
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[0]["id"], [oid], note="undo1")
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(24))
+
         # Do another one
         info = self._storage.undoInfo()
         tid = info[2]['id']
-        t = Transaction()
-        t.note('undo2')
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[2]["id"], [oid], note="undo2")
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(23))
+
         # Try to undo the first record
         info = self._storage.undoInfo()
         tid = info[4]['id']
-        t = Transaction()
-        t.note('undo3')
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[4]["id"], [oid], note="undo3")
         # This should fail since we've undone the object's creation
         self.assertRaises(KeyError,
                           self._storage.load, oid, '')
+
         # And now let's try to redo the object's creation
         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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[0]["id"], [oid])
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(23))
         self._iterate()
@@ -166,13 +142,7 @@
         revid = self._dostore(oid, data=MinPO(23))
         # undo its creation
         info = self._storage.undoInfo()
-        tid = info[0]['id']
-        t = Transaction()
-        t.note('undo1')
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
+        self._undo(info[0]["id"], [oid], note="undo1")
         # Check that calling getSerial on an uncreated object raises a KeyError
         # The current version of FileStorage fails this test
         self.assertRaises(KeyError, self._storage.getSerial, oid)
@@ -184,27 +154,14 @@
         revid = self._dostore(oid, revid=revid, data=MinPO(12))
         # Undo the last transaction
         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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[0]['id'], [oid])
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(11))
+        
         # Now from here, we can either redo the last undo, or undo the object
         # creation.  Let's undo the object creation.
         info = self._storage.undoInfo()
-        tid = info[2]['id']
-        t = Transaction()
-        self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[2]['id'], [oid])
         self.assertRaises(KeyError, self._storage.load, oid, '')
         self._iterate()
 
@@ -215,27 +172,13 @@
         revid = self._dostore(oid, revid=revid, data=MinPO(12))
         # Undo the last transaction
         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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[0]['id'], [oid])
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(11))
         # Now from here, we can either redo the last undo, or undo the object
         # creation.  Let's redo the last undo
         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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        self._undo(info[0]['id'], [oid])
         data, revid = self._storage.load(oid, '')
         eq(zodb_unpickle(data), MinPO(12))
         self._iterate()
@@ -277,17 +220,10 @@
         eq(zodb_unpickle(data), MinPO(32))
         data, revid2 = self._storage.load(oid2, '')
         eq(zodb_unpickle(data), MinPO(52))
+        
         # Now attempt to undo the transaction containing two objects
         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)
-        eq(len(oids), 2)
-        self.failUnless(oid1 in oids)
-        self.failUnless(oid2 in oids)
+        self._undo(info[0]['id'], [oid1, oid2])
         data, revid1 = self._storage.load(oid1, '')
         eq(zodb_unpickle(data), MinPO(31))
         data, revid2 = self._storage.load(oid2, '')
@@ -333,13 +269,11 @@
         tid1 = info[1]['id']
         t = Transaction()
         self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
-        oids1 = self._storage.transactionalUndo(tid1, t)
+        tid, oids = self._storage.transactionalUndo(tid, t)
+        tid, oids1 = self._storage.transactionalUndo(tid1, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         # We get the finalization stuff called an extra time:
-##        self._storage.tpc_vote(t)
-##        self._storage.tpc_finish(t)
         eq(len(oids), 2)
         eq(len(oids1), 2)
         unless(oid1 in oids)
@@ -348,17 +282,10 @@
         eq(zodb_unpickle(data), MinPO(30))
         data, revid2 = self._storage.load(oid2, '')
         eq(zodb_unpickle(data), MinPO(50))
+        
         # Now try to undo the one we just did to undo, whew
         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)
-        eq(len(oids), 2)
-        unless(oid1 in oids)
-        unless(oid2 in oids)
+        self._undo(info[0]['id'], [oid1, oid2])
         data, revid1 = self._storage.load(oid1, '')
         eq(zodb_unpickle(data), MinPO(32))
         data, revid2 = self._storage.load(oid2, '')
@@ -390,15 +317,7 @@
         eq(revid1, revid2)
         # Now attempt to undo the transaction containing two objects
         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)
-        eq(len(oids), 2)
-        self.failUnless(oid1 in oids)
-        self.failUnless(oid2 in oids)
+        self._undo(info[0]["id"], [oid1, oid2])
         data, revid1 = self._storage.load(oid1, '')
         eq(zodb_unpickle(data), MinPO(31))
         data, revid2 = self._storage.load(oid2, '')
@@ -424,7 +343,7 @@
         tid = info[1]['id']
         t = Transaction()
         self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
+        tid, oids = self._storage.transactionalUndo(tid, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         eq(len(oids), 1)
@@ -517,7 +436,7 @@
         # And now attempt to undo the last transaction
         t = Transaction()
         self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
+        tid, oids = self._storage.transactionalUndo(tid, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         eq(len(oids), 1)


=== ZODB3/ZODB/tests/StorageTestBase.py 1.27.6.1 => 1.27.6.1.2.1 ===
--- ZODB3/ZODB/tests/StorageTestBase.py:1.27.6.1	Mon Sep 15 17:26:57 2003
+++ ZODB3/ZODB/tests/StorageTestBase.py	Mon Sep 29 14:23:38 2003
@@ -213,25 +213,26 @@
 
     # The following methods depend on optional storage features.
 
-    def _undo(self, tid, oid=None):
+    def _undo(self, tid, expected_oids=None, note=None):
         # Undo a tid that affects a single object (oid).
         # XXX This is very specialized
         t = Transaction()
-        t.note("undo")
+        t.note(note or "undo")
         self._storage.tpc_begin(t)
-        oids = self._storage.transactionalUndo(tid, t)
+        tid, oids = self._storage.transactionalUndo(tid, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
-        if oid is not None:
-            self.assertEqual(len(oids), 1)
-            self.assertEqual(oids[0], oid)
+        if expected_oids is not None:
+            self.assertEqual(len(oids), len(expected_oids))
+            for oid in expected_oids:
+                self.assert_(oid in oids)
         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)
+        tid, oids = self._storage.commitVersion(src, dst, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         return oids
@@ -240,7 +241,7 @@
         t = Transaction()
         t.note("abort %r" % ver)
         self._storage.tpc_begin(t)
-        oids = self._storage.abortVersion(ver, t)
+        tid, oids = self._storage.abortVersion(ver, t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         return oids


=== ZODB3/ZODB/tests/RecoveryStorage.py 1.8.6.2 => 1.8.6.2.2.1 ===
--- ZODB3/ZODB/tests/RecoveryStorage.py:1.8.6.2	Mon Sep 15 17:26:57 2003
+++ ZODB3/ZODB/tests/RecoveryStorage.py	Mon Sep 29 14:23:38 2003
@@ -54,7 +54,7 @@
         # Now abort the version and the creation
         t = Transaction()
         self._storage.tpc_begin(t)
-        oids = self._storage.abortVersion('one', t)
+        tid, oids = self._storage.abortVersion('one', t)
         self._storage.tpc_vote(t)
         self._storage.tpc_finish(t)
         self.assertEqual(oids, [oid])
@@ -80,9 +80,9 @@
                                 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._undo(self._storage.undoInfo()[0]['id'], [oid])
         self._commitVersion(version, '')
-        self._undo(self._storage.undoInfo()[0]['id'], oid)
+        self._undo(self._storage.undoInfo()[0]['id'], [oid])
 
         # now copy the records to a new storage
         self._dst.copyTransactionsFrom(self._storage)
@@ -95,7 +95,7 @@
 
         self._abortVersion(version)
         self.assert_(self._storage.versionEmpty(version))
-        self._undo(self._storage.undoInfo()[0]['id'], oid)
+        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
@@ -109,7 +109,7 @@
         self._storage = self._dst
         self._abortVersion(version)
         self.assert_(self._storage.versionEmpty(version))
-        self._undo(self._storage.undoInfo()[0]['id'], oid)
+        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




More information about the Zodb-checkins mailing list