[Zodb-checkins] CVS: Zope3/lib/python/ZODB/tests - ConflictResolution.py:1.11

Jeremy Hylton jeremy@zope.com
Mon, 2 Dec 2002 14:17:02 -0500


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

Modified Files:
	ConflictResolution.py 
Log Message:
Revise handling of bad classes during ConflictResolution.

Extend test suite to verify that classes are recognized as
unresolvable().  This, unfortunately, extends into the ZEO test suite,
because a ZEO client doesn't know enough to support the test.


=== Zope3/lib/python/ZODB/tests/ConflictResolution.py 1.10 => 1.11 ===
--- Zope3/lib/python/ZODB/tests/ConflictResolution.py:1.10	Thu Sep 19 15:13:50 2002
+++ Zope3/lib/python/ZODB/tests/ConflictResolution.py	Mon Dec  2 14:17:01 2002
@@ -15,6 +15,7 @@
 
 from ZODB.ZTransaction import Transaction
 from ZODB.POSException import ConflictError, UndoError
+from ZODB.ConflictResolution import ResolveObjectReader
 from Persistence import Persistent
 
 from ZODB.tests.StorageTestBase import zodb_unpickle, zodb_pickle
@@ -34,6 +35,9 @@
     def inc(self):
         self._value = self._value + 1
 
+class RPCounter(PCounter):
+    """Version of PCounter that supports conflict resolution."""
+
     def _p_resolveConflict(self, oldState, savedState, newState):
         savedDiff = savedState['_value'] - oldState['_value']
         newDiff = newState['_value'] - oldState['_value']
@@ -46,7 +50,6 @@
     # conflict, but did something wrong?
 
 class PCounter2(PCounter):
-
     def _p_resolveConflict(self, oldState, savedState, newState):
         raise ConflictError
 
@@ -61,7 +64,7 @@
 class ConflictResolvingStorage:
 
     def checkResolve(self):
-        obj = PCounter()
+        obj = RPCounter()
         obj.inc()
 
         oid = self._storage.new_oid()
@@ -80,7 +83,29 @@
         inst = zodb_unpickle(data)
         self.assertEqual(inst._value, 5)
 
-    def checkUnresolvable(self):
+    def unresolvable(self, klass):
+        self.assert_(ResolveObjectReader.unresolvable(PCounter))
+
+    def checkUnresolvable1(self):
+        obj = PCounter()
+        obj.inc()
+
+        oid = self._storage.new_oid()
+
+        revid1 = self._dostoreNP(oid, data=zodb_pickle(obj))
+
+        obj.inc()
+        obj.inc()
+        # The effect of committing two transactions with the same
+        # pickle is to commit two different transactions relative to
+        # revid1 that add two to _value.  
+        revid2 = self._dostoreNP(oid, revid=revid1, data=zodb_pickle(obj))
+        self.assertRaises(ConflictError,
+                          self._dostoreNP,
+                          oid, revid=revid1, data=zodb_pickle(obj))
+        self.unresolvable(PCounter)
+
+    def checkUnresolvable2(self):
         obj = PCounter2()
         obj.inc()
 
@@ -115,6 +140,7 @@
         self.assertRaises(AttributeError,
                           self._dostoreNP,
                           oid, revid=revid1, data=zodb_pickle(obj))
+        print ResolveObjectReader.bad_classes
 
     def checkBuggyResolve2(self):
         obj = PCounter4()
@@ -133,6 +159,7 @@
         self.assertRaises(TypeError,
                           self._dostoreNP,
                           oid, revid=revid1, data=zodb_pickle(obj))
+        print ResolveObjectReader.bad_classes
 
 class ConflictResolvingTransUndoStorage: