[Zodb-checkins] CVS: Zope3/src/ZODB/tests - testmvcc.py:1.11.2.1 testZODB.py:1.24.2.4 testTransaction.py:1.19.2.9

Jeremy Hylton jeremy at zope.com
Wed Mar 31 17:01:51 EST 2004


Update of /cvs-repository/Zope3/src/ZODB/tests
In directory cvs.zope.org:/tmp/cvs-serv15378/src/ZODB/tests

Modified Files:
      Tag: jeremy-txn-branch
	testmvcc.py testZODB.py testTransaction.py 
Log Message:
Fix tests that depended on details of transaction implementation.

Use explicit transaction manager passed to DB.open() instead of
setLocalTransaction.  Add a test of explicit transaction management.

Disable code in testTransaction that checked hosed variable.  It
doesn't exist in the new implementation.



=== Zope3/src/ZODB/tests/testmvcc.py 1.11 => 1.11.2.1 ===
--- Zope3/src/ZODB/tests/testmvcc.py:1.11	Fri Mar 12 16:47:35 2004
+++ Zope3/src/ZODB/tests/testmvcc.py	Wed Mar 31 17:01:50 2004
@@ -41,8 +41,9 @@
 setLocalTransaction() method to make sure that the connections act
 independently, even though they'll be run from a single thread.
 
->>> cn1 = db.open()
->>> txn1 = cn1.setLocalTransaction()
+>>> import transaction
+>>> tm1 = transaction.TransactionManager()
+>>> cn1 = db.open(txn_mgr=tm1)
 
 The test will just use some MinPO objects.  The next few lines just
 setup an initial database state.
@@ -51,12 +52,12 @@
 >>> r = cn1.root()
 >>> r["a"] = MinPO(1)
 >>> r["b"] = MinPO(1)
->>> txn1.commit()
+>>> tm1.get().commit()
 
 Now open a second connection.
 
->>> cn2 = db.open()
->>> txn2 = cn2.setLocalTransaction()
+>>> tm2 = transaction.TransactionManager()
+>>> cn2 = db.open(txn_mgr=tm2)
 
 Connection high-water mark
 --------------------------
@@ -104,7 +105,7 @@
 
 >>> r1 = cn1.root()
 >>> r1["a"].value = 2
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 >>> txn = db.lastTransaction()
 
 The second connection has its high-water mark set now.
@@ -141,7 +142,7 @@
 commit the transaction.
 
 >>> r2["a"].value = 3
->>> txn2.commit()
+>>> tm2.get().commit()
 Traceback (most recent call last):
  ...
 ConflictError: database conflict error (oid 0000000000000001, class ZODB.tests.MinPO.MinPO)
@@ -155,9 +156,7 @@
 
 >>> r1 = cn1.root()
 >>> r1["a"].value = 3
->>> txn1 is cn1.getTransaction()
-True
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 >>> txn = db.lastTransaction()
 >>> cn2._txn_time == txn
 True
@@ -165,7 +164,7 @@
 >>> r2["b"].value = r2["a"].value + 1
 >>> r2["b"].value
 3
->>> txn2.commit()
+>>> tm2.get().commit()
 >>> print cn2._txn_time
 None
 
@@ -185,7 +184,7 @@
 >>> cn1.sync()
 >>> r1["a"].value = 0
 >>> r1["b"].value = 0
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 
 >>> cn2.sync()
 >>> r2["a"].value
@@ -206,7 +205,7 @@
 ...     cn1.sync()
 ...     r1["a"].value = 0
 ...     r1["b"].value = 0
-...     cn1.getTransaction().commit()
+...     tm1.get().commit()
 ...     cn2.sync()
 ...     r2["b"].value = 1
 ...     cn2.getTransaction().commit()
@@ -217,7 +216,7 @@
 >>> r1["b"].value
 0
 >>> r1["a"].value = 1
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 >>> r1["b"]._p_state
 -1
 
@@ -280,14 +279,13 @@
 
 >>> ts = TestStorage()
 >>> db = DB(ts)
->>> cn1 = db.open()
->>> txn1 = cn1.setLocalTransaction()
+>>> cn1 = db.open(txn_mgr=tm1)
 >>> r1 = cn1.root()
 >>> r1["a"] = MinPO(0)
 >>> r1["b"] = MinPO(0)
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 >>> r1["b"].value = 1
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 >>> cn1.cacheMinimize()  # makes everything in cache a ghost
 
 >>> oid = r1["b"]._p_oid
@@ -318,12 +316,11 @@
 
 >>> ts = TestStorage()
 >>> db = DB(ts)
->>> cn1 = db.open()
->>> txn1 = cn1.setLocalTransaction()
+>>> cn1 = db.open(txn_mgr=tm1)
 >>> r1 = cn1.root()
 >>> r1["a"] = MinPO(0)
 >>> r1["b"] = MinPO(0)
->>> cn1.getTransaction().commit()
+>>> tm1.get().commit()
 >>> cn1.cacheMinimize()  # makes everything in cache a ghost
 
 >>> oid = r1["b"]._p_oid


=== Zope3/src/ZODB/tests/testZODB.py 1.24.2.3 => 1.24.2.4 ===
--- Zope3/src/ZODB/tests/testZODB.py:1.24.2.3	Mon Mar 29 13:44:28 2004
+++ Zope3/src/ZODB/tests/testZODB.py	Wed Mar 31 17:01:50 2004
@@ -16,8 +16,10 @@
 import ZODB
 import ZODB.FileStorage
 from ZODB.POSException import ReadConflictError, ConflictError
+
 from persistent import Persistent
 from persistent.mapping import PersistentMapping
+import transaction
 
 class P(Persistent):
     pass
@@ -163,6 +165,44 @@
         self.assert_(len(conn._cache) > 0)  # Still not flushed
         conn._setDB(self._db)  # simulate the connection being reopened
         self.assertEqual(len(conn._cache), 0)
+
+    def checkExplicitTransactionManager(self):
+        # Test of transactions that apply to only the connection,
+        # not the thread.
+        tm1 = transaction.TransactionManager()
+        conn1 = self._db.open(txn_mgr=tm1)
+        tm2 = transaction.TransactionManager()
+        conn2 = self._db.open(txn_mgr=tm2)
+        try:
+            r1 = conn1.root()
+            r2 = conn2.root()
+            if r1.has_key('item'):
+                del r1['item']
+                tm1.get().commit()
+            r1.get('item')
+            r2.get('item')
+            r1['item'] = 1
+            tm1.get().commit()
+            self.assertEqual(r1['item'], 1)
+            # r2 has not seen a transaction boundary,
+            # so it should be unchanged.
+            self.assertEqual(r2.get('item'), None)
+            conn2.sync()
+            # Now r2 is updated.
+            self.assertEqual(r2['item'], 1)
+
+            # Now, for good measure, send an update in the other direction.
+            r2['item'] = 2
+            tm2.get().commit()
+            self.assertEqual(r1['item'], 1)
+            self.assertEqual(r2['item'], 2)
+            conn1.sync()
+            conn2.sync()
+            self.assertEqual(r1['item'], 2)
+            self.assertEqual(r2['item'], 2)
+        finally:
+            conn1.close()
+            conn2.close()
 
     def checkLocalTransactions(self):
         # Test of transactions that apply to only the connection,


=== Zope3/src/ZODB/tests/testTransaction.py 1.19.2.8 => 1.19.2.9 ===
--- Zope3/src/ZODB/tests/testTransaction.py:1.19.2.8	Wed Mar 31 14:14:24 2004
+++ Zope3/src/ZODB/tests/testTransaction.py	Wed Mar 31 17:01:50 2004
@@ -47,7 +47,6 @@
     def setUp(self):
         self.orig_tm = transaction.manager
         transaction.manager = transaction.TransactionManager()
-        Transaction.hosed = 0
         self.sub1 = DataObject()
         self.sub2 = DataObject()
         self.sub3 = DataObject()
@@ -337,7 +336,6 @@
         assert self.nosub1._p_jar.ctpc_finish == 0
         assert self.nosub1._p_jar.ccommit == 1
         assert self.nosub1._p_jar.ctpc_abort == 1
-        assert Transaction.hosed == 0
 
     def testExceptionInTpcVote(self):
 
@@ -354,7 +352,6 @@
         assert self.nosub1._p_jar.ccommit == 1
         assert self.nosub1._p_jar.ctpc_abort == 1
         assert self.sub1._p_jar.ctpc_abort == 1
-        assert Transaction.hosed == 0
 
     def testExceptionInTpcBegin(self):
         """
@@ -393,7 +390,6 @@
         except TestTxnException: pass
 
         assert self.nosub1._p_jar.ctpc_abort == 1
-        assert Transaction.hosed == 0
 
     ### More Failure modes...
     # now we mix in some sub transactions
@@ -472,38 +468,34 @@
 
     # last test, check the hosing mechanism
 
-    def testHoserStoppage(self):
-        # XXX We should consult ZConfig to decide whether we can get into a
-        # hosed state or not.
-        return
-
-        # It's hard to test the "hosed" state of the database, where
-        # hosed means that a failure occurred in the second phase of
-        # the two phase commit.  It's hard because the database can
-        # recover from such an error if it occurs during the very first
-        # tpc_finish() call of the second phase.
-
-        for obj in self.sub1, self.sub2:
-            j = HoserJar(errors='tpc_finish')
-            j.reset()
-            obj._p_jar = j
-            obj.modify(nojar=1)
-
-        try:
-            get_transaction().commit()
-        except TestTxnException:
-            pass
-
-        self.assert_(Transaction.hosed)
-
-        self.sub2.modify()
-
-        try:
-            get_transaction().commit()
-        except Transaction.POSException.TransactionError:
-            pass
-        else:
-            self.fail("Hosed Application didn't stop commits")
+##    def testHoserStoppage(self):
+##        # It's hard to test the "hosed" state of the database, where
+##        # hosed means that a failure occurred in the second phase of
+##        # the two phase commit.  It's hard because the database can
+##        # recover from such an error if it occurs during the very first
+##        # tpc_finish() call of the second phase.
+
+##        for obj in self.sub1, self.sub2:
+##            j = HoserJar(errors='tpc_finish')
+##            j.reset()
+##            obj._p_jar = j
+##            obj.modify(nojar=1)
+
+##        try:
+##            get_transaction().commit()
+##        except TestTxnException:
+##            pass
+
+##        self.assert_(Transaction.hosed)
+
+##        self.sub2.modify()
+
+##        try:
+##            get_transaction().commit()
+##        except Transaction.POSException.TransactionError:
+##            pass
+##        else:
+##            self.fail("Hosed Application didn't stop commits")
 
 
 class DataObject:




More information about the Zodb-checkins mailing list