[Checkins] SVN: gocept.zeoraid/trunk/src/gocept/zeoraid/ Implemented and tested IServable.

Christian Theune ct at gocept.com
Thu Jan 31 03:56:05 EST 2008


Log message for revision 83329:
  Implemented and tested IServable.
  

Changed:
  U   gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py
  U   gocept.zeoraid/trunk/src/gocept/zeoraid/tests/failingstorage.py
  U   gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py

-=-
Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py	2008-01-31 08:36:16 UTC (rev 83328)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/storage.py	2008-01-31 08:56:05 UTC (rev 83329)
@@ -438,29 +438,23 @@
 
     # IServeable
 
-    # XXX
-    def lastInvalidations(self, size):
-        """Get recent transaction invalidations."""
+    # Note: We opt to not implement lastInvalidations until ClientStorage does.
+    # def lastInvalidations(self, size):
+    #    """Get recent transaction invalidations."""
+    #    return self._apply_single_storage('lastInvalidations', (size,))
 
-    # XXX
     def tpc_transaction(self):
         """The current transaction being committed."""
         return self._transaction
 
-    # XXX
     def getTid(self, oid):
+        """The last transaction to change an object."""
         return self._apply_single_storage('getTid', (oid,))
 
-    # XXX
     def getExtensionMethods(self):
-        methods = self._apply_single_storage('getExtensionMethods')
-        if methods is None:
-            # Allow management while status is 'failed'
-            methods = {}
-        methods['raid_recover'] = None
-        methods['raid_status'] = None
-        methods['raid_disable'] = None
-        methods['raid_details'] = None
+        # This method isn't officially part of the interface but it is supported.
+        methods = dict.fromkeys(
+            ['raid_recover', 'raid_status', 'raid_disable', 'raid_details'])
         return methods
 
     # IRAIDStorage

Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/tests/failingstorage.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/tests/failingstorage.py	2008-01-31 08:36:16 UTC (rev 83328)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/tests/failingstorage.py	2008-01-31 08:56:05 UTC (rev 83329)
@@ -62,7 +62,7 @@
     # non-data descriptors on the proxy object.
     __stub_methods__ = ['history', 'loadSerial', 'close', 'getSize', 'pack',
                         'tpc_abort', 'tpc_finish', 'storeBlob', 'loadBlob',
-                        'undo', 'record_iternext']
+                        'undo', 'record_iternext', 'getTid']
     for name in __stub_methods__:
         method = zope.proxy.non_overridable(failing_method(name))
         locals()[name] = method

Modified: gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py
===================================================================
--- gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py	2008-01-31 08:36:16 UTC (rev 83328)
+++ gocept.zeoraid/trunk/src/gocept/zeoraid/tests/test_basics.py	2008-01-31 08:56:05 UTC (rev 83329)
@@ -12,7 +12,9 @@
 
 import zope.interface.verify
 
+import persistent.dict
 import transaction
+
 from ZODB.tests import StorageTestBase, BasicStorage, \
              TransactionalUndoStorage, PackableStorage, \
              Synchronization, ConflictResolution, HistoryStorage, \
@@ -105,7 +107,11 @@
                       ZODB.interfaces.IBlobStorage,
                       ZODB.interfaces.IStorageUndoable,
                       ZODB.interfaces.IStorageCurrentRecordIteration,
-                      ZEO.interfaces.IServeable,
+
+                      # The IServable interface allows to not implement the
+                      # `lastInvalidations` method. We chose to do this and
+                      # can't verify the interface formally due to that.
+                      # ZEO.interfaces.IServeable,
                       ):
             self.assert_(zope.interface.verify.verifyObject(iface,
                                                             self._storage))
@@ -1001,6 +1007,66 @@
                           self._storage.record_iternext, next)
         self.assertEquals('failed', self._storage.raid_status())
 
+    def test_gettid_degrading1(self):
+        oid = self._storage.new_oid()
+        revid = self._dostoreNP(oid, data='foo')
+
+        self._disable_storage(0)
+        tid = self._storage.getTid(oid)
+        self.assertEquals(revid, tid)
+
+        self._disable_storage(0)
+        self.assertRaises(gocept.zeoraid.interfaces.RAIDError,
+                          self._storage.getTid, oid)
+
+    def test_gettid_degrading2(self):
+        oid = self._storage.new_oid()
+        revid = self._dostoreNP(oid, data='foo')
+
+        self._backend(0).fail('getTid')
+        tid = self._storage.getTid(oid)
+        self.assertEquals(revid, tid)
+        self.assertEquals('degraded', self._storage.raid_status())
+
+        self._backend(0).fail('getTid')
+        self.assertRaises(gocept.zeoraid.interfaces.RAIDError,
+                          self._storage.getTid, oid)
+        self.assertEquals('failed', self._storage.raid_status())
+
+    def test_tpc_transaction_finishing(self):
+        self.assertEquals(None, self._storage.tpc_transaction())
+        t = transaction.Transaction()
+        self._storage.tpc_begin(t)
+        self.assertEquals(t, self._storage.tpc_transaction())
+        self._storage.tpc_vote(t)
+        self.assertEquals(t, self._storage.tpc_transaction())
+        self._storage.tpc_finish(t)
+        self.assertEquals(None, self._storage.tpc_transaction())
+
+    def test_tpc_transaction_aborting(self):
+        self.assertEquals(None, self._storage.tpc_transaction())
+        t = transaction.Transaction()
+        self._storage.tpc_begin(t)
+        self.assertEquals(t, self._storage.tpc_transaction())
+        self._storage.tpc_vote(t)
+        self.assertEquals(t, self._storage.tpc_transaction())
+        self._storage.tpc_abort(t)
+        self.assertEquals(None, self._storage.tpc_transaction())
+
+    def test_getExtensionMethods(self):
+        methods = self._storage.getExtensionMethods()
+        self.assertEquals(dict(raid_details=None,
+                               raid_disable=None,
+                               raid_recover=None,
+                               raid_status=None),
+                          methods)
+
+    def test_getExtensionMethods_degrading(self):
+        self._disable_storage(0)
+        self._storage.getExtensionMethods()
+        self._disable_storage(0)
+        self._storage.getExtensionMethods()
+
 class ZEOReplicationStorageTests(ZEOStorageBackendTests,
                                  ReplicationStorageTests,
                                  ThreadTests.ThreadTests):



More information about the Checkins mailing list