[Zodb-checkins] SVN: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/ - added test for getSize()

Christian Theune ct at gocept.com
Mon Feb 27 00:23:57 EST 2006


Log message for revision 65510:
   - added test for getSize()
   - fixed problem handling data manager registrations for non-default 
     transaction managers
  

Changed:
  U   ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py
  U   ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt

-=-
Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py	2006-02-27 05:08:07 UTC (rev 65509)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/Blob.py	2006-02-27 05:23:56 UTC (rev 65510)
@@ -26,6 +26,12 @@
     # blobs here.
     _p_blob_manager = None
 
+    # Blobs need to participate in transactions even when not connected to
+    # a database yet. If you want to use a non-default transaction manager,
+    # you can override it via _p_blob_transaction. This is currently
+    # required for unit testing.
+    _p_blob_transaction = None
+
     def open(self, mode="r"):
         """ Returns a file(-like) object representing blob data.  This
         method will either return the file object, raise a BlobError
@@ -75,7 +81,7 @@
                 # Re-use existing working copy
                 uncommitted = BlobFile(self._p_blob_uncommitted, mode, self)
 
-            self._p_blob_writers +=1
+            self._p_blob_writers += 1
             result = uncommitted
 
         else:
@@ -92,7 +98,21 @@
 
             if self._p_blob_manager is None:
                 dm = BlobDataManager(self, result)
-                transaction.get().register(dm)
+
+                # Blobs need to always participate in transactions.
+                if self._p_jar:
+                    # If we are connected to a database, then we register
+                    # with the transaction manager for that.
+                    self._p_jar.transaction_manager.get().register(dm)
+                else:
+                    # If we are not connected to a database, we check whether
+                    # we have been given an explicit transaction manager
+                    if self._p_blob_transaction:
+                        self._p_blob_transaction.get().register(dm)
+                    else:
+                        # Otherwise we register with the default 
+                        # transaction manager as an educated guess.
+                        transaction.get().register(dm)
             else:
                 # each blob data manager should manage only the one blob
                 # assert that this is the case and it is the correct blob

Modified: ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt
===================================================================
--- ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt	2006-02-27 05:08:07 UTC (rev 65509)
+++ ZODB/branches/blob-merge-branch/src/ZODB/Blobs/tests/transaction.txt	2006-02-27 05:23:56 UTC (rev 65510)
@@ -170,11 +170,21 @@
     >>> blob1c3fh1.write('this is from connection 3')
     >>> blob1c4fh1.write('this is from connection 4')
     >>> tm1.get().commit()
+    >>> root3['blob1'].open('r').read()
+    'this is blob 1woot!this is from connection 3'
     >>> tm2.get().commit()
     Traceback (most recent call last):
         ...
     ConflictError: database conflict error (oid 0x01, class ZODB.Blobs.Blob.Blob)
 
+BlobStorages implementation of getSize() includes the blob data and adds it to
+the underlying storages result of getSize():
+
+    >>> underlying_size = base_storage.getSize()
+    >>> blob_size = blob_storage.getSize()
+    >>> blob_size - underlying_size
+    91L
+
 We don't need the storage directory and databases anymore:
 
     >>> import shutil
@@ -182,3 +192,4 @@
     >>> tm1.get().abort()
     >>> tm2.get().abort()
     >>> database.close()
+



More information about the Zodb-checkins mailing list