[Zodb-checkins] CVS: StandaloneZODB/ZODB/tests - BasicStorage.py:1.14 PackableStorage.py:1.12 StorageTestBase.py:1.9

Jeremy Hylton jeremy@zope.com
Fri, 2 Nov 2001 16:51:39 -0500


Update of /cvs-repository/StandaloneZODB/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv26673

Modified Files:
	BasicStorage.py PackableStorage.py StorageTestBase.py 
Log Message:
Fix tests to account for ZEO's load() & tpc_vote() return values


=== StandaloneZODB/ZODB/tests/BasicStorage.py 1.13 => 1.14 ===
         # Use None for serial.  Don't use _dostore() here because that coerces
         # serial=None to serial=ZERO.
-        newrevid = self._storage.store(oid, None, zodb_pickle(MinPO(11)),
+        r1 = self._storage.store(oid, None, zodb_pickle(MinPO(11)),
                                        '', txn)
-        self._storage.tpc_vote(txn)
+        r2 = self._storage.tpc_vote(txn)
         self._storage.tpc_finish(txn)
+        newrevid = self._handle_serials(oid, r1, r2)
         data, revid = self._storage.load(oid, '')
         value = zodb_unpickle(data)
         eq(value, MinPO(11))
@@ -118,22 +119,22 @@
     def checkWriteAfterAbort(self):
         oid = self._storage.new_oid()
         self._storage.tpc_begin(self._transaction)
-        revid = self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)),
-                                    '', self._transaction)
+        self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)),
+                            '', self._transaction)
         # Now abort this transaction
         self._storage.tpc_abort(self._transaction)
         # Now start all over again
         self._transaction = Transaction()
         oid = self._storage.new_oid()
-        revid = self._dostore(oid=oid, data=MinPO(6))
+        self._dostore(oid=oid, data=MinPO(6))
 
     def checkAbortAfterVote(self):
         oid1 = self._storage.new_oid()
         revid1 = self._dostore(oid=oid1, data=MinPO(-2))
         oid = self._storage.new_oid()
         self._storage.tpc_begin(self._transaction)
-        revid = self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)),
-                                    '', self._transaction)
+        self._storage.store(oid, ZERO, zodb_pickle(MinPO(5)),
+                            '', self._transaction)
         # Now abort this transaction
         self._storage.tpc_vote(self._transaction)
         self._storage.tpc_abort(self._transaction)


=== StandaloneZODB/ZODB/tests/PackableStorage.py 1.11 => 1.12 ===
         self._storage.pack(time.time() + 10000, referencesf)
             
+    def checkPackYesterday(self):
+        self._initroot()
+        self._storage.pack(time.time() - 10000, referencesf)
+            
     def checkPackAllRevisions(self):
         self._initroot()
         eq = self.assertEqual


=== StandaloneZODB/ZODB/tests/StorageTestBase.py 1.8 => 1.9 ===
         self._close()
 
+    def _handle_all_serials(self, oid, *args):
+        """Return dict of oid to serialno from store() and tpc_vote().
+
+        Raises an exception if one of the calls raised an exception.
+
+        The storage interface got complicated when ZEO was introduced.
+        Any individual store() call can return None or a sequence of
+        2-tuples where the 2-tuple is either oid, serialno or an
+        exception to be raised by the client.
+
+        The original interface just returned the serialno for the
+        object.
+        """
+        d = {}
+        for arg in args:
+            if isinstance(arg, types.StringType):
+                d[oid] = arg
+            elif arg is None:
+                pass
+            else:
+                for oid, serial in arg:
+                    if not isinstance(serial, types.StringType):
+                        raise arg
+                    d[oid] = serial
+        return d
+
+    def _handle_serials(self, oid, *args):
+        """Return the serialno for oid based on multiple return values.
+
+        A helper for function _handle_all_serials().
+        """
+        args = (oid,) + args
+        return apply(self._handle_all_serials, args)[oid]
+
     def _dostore(self, oid=None, revid=None, data=None, version=None,
                  already_pickled=0):
         """Do a complete storage transaction.  The defaults are:
@@ -114,12 +148,12 @@
         # Begin the transaction
         self._storage.tpc_begin(self._transaction)
         # Store an object
-        newrevid = self._storage.store(oid, revid, data, version,
+        r1 = self._storage.store(oid, revid, data, version,
                                        self._transaction)
         # Finish the transaction
-        self._storage.tpc_vote(self._transaction)
+        r2 = self._storage.tpc_vote(self._transaction)
         self._storage.tpc_finish(self._transaction)
-        return newrevid
+        return self._handle_serials(oid, r1, r2)
         
     def _dostoreNP(self, oid=None, revid=None, data=None, version=None):
         return self._dostore(oid, revid, data, version, already_pickled=1)