[Zodb-checkins] SVN: ZODB/branches/jim-transform-wrapping/src/Z checkpoint

Jim Fulton jim at zope.com
Mon May 17 13:34:30 EDT 2010


Log message for revision 112423:
  checkpoint

Changed:
  U   ZODB/branches/jim-transform-wrapping/src/ZEO/tests/IterationTests.py
  U   ZODB/branches/jim-transform-wrapping/src/ZEO/tests/testZEO.py
  U   ZODB/branches/jim-transform-wrapping/src/ZODB/tests/component.xml
  U   ZODB/branches/jim-transform-wrapping/src/ZODB/tests/hexstorage.py
  U   ZODB/branches/jim-transform-wrapping/src/ZODB/tests/testFileStorage.py

-=-
Modified: ZODB/branches/jim-transform-wrapping/src/ZEO/tests/IterationTests.py
===================================================================
--- ZODB/branches/jim-transform-wrapping/src/ZEO/tests/IterationTests.py	2010-05-17 16:40:20 UTC (rev 112422)
+++ ZODB/branches/jim-transform-wrapping/src/ZEO/tests/IterationTests.py	2010-05-17 17:34:29 UTC (rev 112423)
@@ -35,7 +35,12 @@
 
     def checkIteratorExhaustionStorage(self):
         # Test the storage's garbage collection mechanism.
+        self._dostore()
         iterator = self._storage.iterator()
+
+        # At this point, a wrapping iterator might not have called the CS
+        # iterator yet. We'll consume one item to make sure this happens.
+        iterator.next()
         self.assertEquals(1, len(self._storage._iterator_ids))
         iid = list(self._storage._iterator_ids)[0]
         self.assertEquals([], list(iterator))
@@ -59,8 +64,14 @@
     def checkIteratorGCStorageCommitting(self):
         # We want the iterator to be garbage-collected, so we don't keep any
         # hard references to it. The storage tracks its ID, though.
-        self._storage.iterator()
 
+        # The odd little jig we do below arises from the fact that the
+        # CS iterator may not be constructed right away if the CS is wrapped.
+        # We need to actually do some iteration to get the iterator created.
+        # We do a store to make sure the iterator isn't exhausted right away.
+        self._dostore()
+        self._storage.iterator().next()
+
         self.assertEquals(1, len(self._storage._iterator_ids))
         iid = list(self._storage._iterator_ids)[0]
 
@@ -71,8 +82,15 @@
         self.assertRaises(KeyError, self._storage._server.iterator_next, iid)
 
     def checkIteratorGCStorageTPCAborting(self):
-        self._storage.iterator()
+        # The odd little jig we do below arises from the fact that the
+        # CS iterator may not be constructed right away if the CS is wrapped.
+        # We need to actually do some iteration to get the iterator created.
+        # We do a store to make sure the iterator isn't exhausted right away.
+        self._dostore()
+        self._storage.iterator().next()
+
         iid = list(self._storage._iterator_ids)[0]
+
         t = transaction.Transaction()
         self._storage.tpc_begin(t)
         self._storage.tpc_abort(t)
@@ -80,7 +98,14 @@
         self.assertRaises(KeyError, self._storage._server.iterator_next, iid)
 
     def checkIteratorGCStorageDisconnect(self):
-        self._storage.iterator()
+
+        # The odd little jig we do below arises from the fact that the
+        # CS iterator may not be constructed right away if the CS is wrapped.
+        # We need to actually do some iteration to get the iterator created.
+        # We do a store to make sure the iterator isn't exhausted right away.
+        self._dostore()
+        self._storage.iterator().next()
+
         iid = list(self._storage._iterator_ids)[0]
         t = transaction.Transaction()
         self._storage.tpc_begin(t)

Modified: ZODB/branches/jim-transform-wrapping/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/branches/jim-transform-wrapping/src/ZEO/tests/testZEO.py	2010-05-17 16:40:20 UTC (rev 112422)
+++ ZODB/branches/jim-transform-wrapping/src/ZEO/tests/testZEO.py	2010-05-17 17:34:29 UTC (rev 112423)
@@ -47,6 +47,7 @@
 import ZEO.zrpc.connection
 import ZODB
 import ZODB.blob
+import ZODB.tests.hexstorage
 import ZODB.tests.testblob
 import ZODB.tests.util
 import ZODB.utils
@@ -59,6 +60,7 @@
         pass
     def invalidateCache(*unused):
         pass
+    transform_record_data = untransform_record_data = lambda self, v: v
 
 
 class CreativeGetState(persistent.Persistent):
@@ -94,7 +96,8 @@
 
     def checkZEOInvalidation(self):
         addr = self._storage._addr
-        storage2 = ClientStorage(addr, wait=1, min_disconnect_poll=0.1)
+        storage2 = self._wrap_client(
+            ClientStorage(addr, wait=1, min_disconnect_poll=0.1))
         try:
             oid = self._storage.new_oid()
             ob = MinPO('first')
@@ -196,13 +199,16 @@
             self.blob_cache_dir = tempfile.mkdtemp(
                 'blob_cache',
                 dir=os.path.abspath(os.getcwd()))
-        self._storage = ClientStorage(
+        self._storage = self._wrap_client(ClientStorage(
             zport, '1', cache_size=20000000,
             min_disconnect_poll=0.5, wait=1,
             wait_timeout=60, blob_dir=self.blob_cache_dir,
-            shared_blob_dir=self.shared_blob_dir)
+            shared_blob_dir=self.shared_blob_dir))
         self._storage.registerDB(DummyDB())
 
+    def _wrap_client(self, client):
+        return client
+
     def tearDown(self):
         self._storage.close()
         for server in self._servers:
@@ -362,7 +368,23 @@
         </hexstorage>
         """
 
+class FileStorageClientHexTests(FileStorageHexTests):
 
+    def getConfig(self):
+        return """\
+        %import ZODB.tests
+        <serverhexstorage>
+        <filestorage 1>
+        path Data.fs
+        </filestorage>
+        </serverhexstorage>
+        """
+
+    def _wrap_client(self, client):
+        return ZODB.tests.hexstorage.HexStorage(client)
+
+
+
 class MappingStorageTests(GenericTests):
     """ZEO backed by a Mapping storage."""
 
@@ -1429,8 +1451,8 @@
 
 slow_test_classes = [
     BlobAdaptedFileStorageTests, BlobWritableCacheTests,
-    DemoStorageTests, FileStorageTests, FileStorageHexTests,
-    MappingStorageTests,
+    MappingStorageTests, DemoStorageTests,
+    FileStorageTests, FileStorageHexTests, FileStorageClientHexTests,
     ]
 
 quick_test_classes = [

Modified: ZODB/branches/jim-transform-wrapping/src/ZODB/tests/component.xml
===================================================================
--- ZODB/branches/jim-transform-wrapping/src/ZODB/tests/component.xml	2010-05-17 16:40:20 UTC (rev 112422)
+++ ZODB/branches/jim-transform-wrapping/src/ZODB/tests/component.xml	2010-05-17 17:34:29 UTC (rev 112423)
@@ -1,6 +1,16 @@
 <component>
-  <sectiontype name="hexstorage" datatype="ZODB.tests.hexstorage.ZConfig"
-               implements="ZODB.storage">
+  <sectiontype
+     name="hexstorage"
+     datatype="ZODB.tests.hexstorage.ZConfigHex"
+     implements="ZODB.storage"
+     >
     <section type="ZODB.storage" name="*" attribute="base" required="yes" />
   </sectiontype>
+  <sectiontype
+     name="serverhexstorage"
+     datatype="ZODB.tests.hexstorage.ZConfigServerHex"
+     implements="ZODB.storage"
+     >
+    <section type="ZODB.storage" name="*" attribute="base" required="yes" />
+  </sectiontype>
 </component>

Modified: ZODB/branches/jim-transform-wrapping/src/ZODB/tests/hexstorage.py
===================================================================
--- ZODB/branches/jim-transform-wrapping/src/ZODB/tests/hexstorage.py	2010-05-17 16:40:20 UTC (rev 112422)
+++ ZODB/branches/jim-transform-wrapping/src/ZODB/tests/hexstorage.py	2010-05-17 17:34:29 UTC (rev 112423)
@@ -29,21 +29,24 @@
         except StopIteration:
             raise ZODB.interfaces.StorageStopIteration()
 
+
 class HexStorage(object):
 
     zope.interface.implements(ZODB.interfaces.IStorageWrapper)
 
-    def __init__(self, base):
-        self.base = base
-        base.registerDB(self)
-
-        for name in (
+    copied_methods = (
             'close', 'getName', 'getSize', 'history', 'isReadOnly',
             'lastTransaction', 'new_oid', 'sortKey',
             'tpc_abort', 'tpc_begin', 'tpc_finish', 'tpc_vote',
             'loadBlob', 'openCommittedBlobFile', 'temporaryDirectory',
             'supportsUndo', 'undo', 'undoLog', 'undoInfo',
-            ):
+            )
+
+    def __init__(self, base):
+        self.base = base
+        base.registerDB(self)
+
+        for name in self.copied_methods:
             v = getattr(base, name, None)
             if v is not None:
                 setattr(self, name, v)
@@ -132,6 +135,18 @@
     def copyTransactionsFrom(self, other):
         ZODB.blob.copyTransactionsFromTo(other, self)
 
+class ServerHexStorage(HexStorage):
+    """Use on ZEO storage server when Hex is used on client
+
+    Don't do conversion as part of load/store, but provide
+    pickle decoding.
+    """
+
+    copied_methods = HexStorage.copied_methods + (
+        'load', 'loadBefore', 'loadSerial', 'store', 'restore',
+        'iterator', 'storeBlob', 'restoreBlob', 'record_iternext',
+        )
+
 class Transaction(object):
 
     def __init__(self, store, trans):
@@ -150,12 +165,18 @@
     def __getattr__(self, name):
         return getattr(self.__trans, name)
 
-class ZConfig:
+class ZConfigHex:
 
+    _factory = HexStorage
+
     def __init__(self, config):
         self.config = config
         self.name = config.getSectionName()
 
     def open(self):
         base = self.config.base.open()
-        return HexStorage(base)
+        return self._factory(base)
+
+class ZConfigServerHex(ZConfigHex):
+
+    _factory = ServerHexStorage

Modified: ZODB/branches/jim-transform-wrapping/src/ZODB/tests/testFileStorage.py
===================================================================
--- ZODB/branches/jim-transform-wrapping/src/ZODB/tests/testFileStorage.py	2010-05-17 16:40:20 UTC (rev 112422)
+++ ZODB/branches/jim-transform-wrapping/src/ZODB/tests/testFileStorage.py	2010-05-17 17:34:29 UTC (rev 112423)
@@ -690,6 +690,7 @@
     suite.addTest(PackableStorage.IExternalGC_suite(
         lambda : ZODB.FileStorage.FileStorage(
             'data.fs', blob_dir='blobs', pack_gc=False)))
+    suite.layer = ZODB.tests.util.MininalTestLayer('testFileStorage')
     return suite
 
 if __name__=='__main__':



More information about the Zodb-checkins mailing list