[Zodb-checkins] CVS: ZODB3/ZODB/tests - testZODB.py:1.6 testFileStorage.py:1.23 VersionStorage.py:1.19 TransactionalUndoVersionStorage.py:1.10 StorageTestBase.py:1.20

Jeremy Hylton jeremy@zope.com
Mon, 18 Nov 2002 18:18:11 -0500


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

Modified Files:
	testZODB.py testFileStorage.py VersionStorage.py 
	TransactionalUndoVersionStorage.py StorageTestBase.py 
Log Message:
Merge ZODB 3.1 changes to the trunk.
XXX Not sure if berkeley still works.


=== ZODB3/ZODB/tests/testZODB.py 1.5 => 1.6 ===
--- ZODB3/ZODB/tests/testZODB.py:1.5	Sat Sep  7 13:22:09 2002
+++ ZODB3/ZODB/tests/testZODB.py	Mon Nov 18 18:17:40 2002
@@ -94,28 +94,6 @@
         self._storage.close()
         removefs("ZODBTests.fs")
 
-    def checkUnmodifiedObject(self):
-        # Test that a transaction with only unmodified objects works
-        # correctly.  The specific sequence of events is:
-        #     - an object is modified
-        #     - it is registered with the transaction
-        #     - the object is explicitly "unmodified"
-        #     - the transaction commits, but now has no modified objects
-        # We'd like to avoid doing anything with the storage.
-        ltid = self._storage.lastTransaction()
-        _objects = get_transaction()._objects
-        self.assertEqual(len(_objects), 0)
-        r = self._db.open().root()
-        obj = r["test"][0]
-        obj[1] = 1
-        self.assertEqual(obj._p_changed, 1)
-        self.assertEqual(len(_objects), 1)
-        del obj._p_changed
-        self.assertEqual(obj._p_changed, None)
-        self.assertEqual(len(_objects), 1)
-        get_transaction().commit()
-        self.assertEqual(ltid, self._storage.lastTransaction())
-
     def checkVersionOnly(self):
         # Make sure the changes to make empty transactions a no-op
         # still allow things like abortVersion().  This should work


=== ZODB3/ZODB/tests/testFileStorage.py 1.22 => 1.23 ===
--- ZODB3/ZODB/tests/testFileStorage.py:1.22	Fri Nov 15 12:35:11 2002
+++ ZODB3/ZODB/tests/testFileStorage.py	Mon Nov 18 18:17:40 2002
@@ -12,6 +12,7 @@
      Synchronization, ConflictResolution, HistoryStorage, \
      IteratorStorage, Corruption, RevisionStorage, PersistentStorage, \
      MTStorage, ReadOnlyStorage, RecoveryStorage
+from ZODB.tests.StorageTestBase import MinPO, zodb_unpickle
 
 class FileStorageTests(
     StorageTestBase.StorageTestBase,
@@ -63,6 +64,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')
 
@@ -76,6 +79,63 @@
         StorageTestBase.removefs('Dest.fs')
         return ZODB.FileStorage.FileStorage('Dest.fs')
 
+    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.18 => 1.19 ===
--- ZODB3/ZODB/tests/VersionStorage.py:1.18	Thu Oct 24 09:50:18 2002
+++ ZODB3/ZODB/tests/VersionStorage.py	Mon Nov 18 18:17:40 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/TransactionalUndoVersionStorage.py 1.9 => 1.10 ===
--- ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py:1.9	Tue Oct 22 19:09:41 2002
+++ ZODB3/ZODB/tests/TransactionalUndoVersionStorage.py	Mon Nov 18 18:17:40 2002
@@ -29,9 +29,25 @@
                 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
+
+        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))
@@ -39,21 +55,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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
+        
+        info = self._storage.undoInfo()
+        self._undo(info[0]['id'], oid)
+        
         data, revid = self._storage.load(oid, '')
         eq(revid, revid_a)
         eq(zodb_unpickle(data), MinPO(91))
         data, revid = self._storage.load(oid, version)
         unless(revid > revid_b and revid > revid_c)
         eq(zodb_unpickle(data), MinPO(92))
+        
         # Now commit the version...
         t = Transaction()
         self._storage.tpc_begin(t)
@@ -63,61 +75,25 @@
         eq(len(oids), 1)
         eq(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)
-        eq(zodb_unpickle(data), MinPO(92))
-        data, revid = self._storage.load(oid, '')
-        eq(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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
-        data, revid = self._storage.load(oid, version)
-        eq(zodb_unpickle(data), MinPO(92))
-        data, revid = self._storage.load(oid, '')
-        eq(zodb_unpickle(data), MinPO(91))
-        # Now abort the version
-        t = Transaction()
-        self._storage.tpc_begin(t)
-        oids = self._storage.abortVersion(version, t)
-        self._storage.tpc_vote(t)
-        self._storage.tpc_finish(t)
-        eq(len(oids), 1)
-        eq(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)
-        eq(zodb_unpickle(data), MinPO(91))
-        data, revid = self._storage.load(oid, '')
-        eq(zodb_unpickle(data), MinPO(91))
+        info = self._storage.undoInfo()
+        self._undo(info[0]['id'], oid)
+
+        check_objects(91, 92)
+
+        oids = self._abortVersion(version)
+        assert len(oids) == 1
+        assert oids[0] == oid
+
+        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)
-        eq(len(oids), 1)
-        eq(oids[0], oid)
-        # And the object should be back in versions 'one' and ''
-        data, revid = self._storage.load(oid, version)
-        eq(zodb_unpickle(data), MinPO(92))
-        data, revid = self._storage.load(oid, '')
-        eq(zodb_unpickle(data), MinPO(91))
+        self._undo(info[0]['id'], oid)
+        
+        check_objects(91, 92)
 
     def checkUndoCommitVersion(self):
         def load_value(oid, version=''):


=== ZODB3/ZODB/tests/StorageTestBase.py 1.19 => 1.20 ===
--- ZODB3/ZODB/tests/StorageTestBase.py:1.19	Fri Nov 15 12:34:23 2002
+++ ZODB3/ZODB/tests/StorageTestBase.py	Mon Nov 18 18:17:40 2002
@@ -180,7 +180,6 @@
     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):