[Zodb-checkins] CVS: ZODB3/bsddb3Storage/bsddb3Storage/tests - test_whitebox.py:1.1.2.3

Barry Warsaw barry@wooz.org
Wed, 11 Sep 2002 18:53:37 -0400


Update of /cvs-repository/ZODB3/bsddb3Storage/bsddb3Storage/tests
In directory cvs.zope.org:/tmp/cvs-serv15082

Modified Files:
      Tag: bdb-nolocks
	test_whitebox.py 
Log Message:
checkRecursiveReferenceCounting(): Check for more nesting in object
structure.


=== ZODB3/bsddb3Storage/bsddb3Storage/tests/test_whitebox.py 1.1.2.2 => 1.1.2.3 ===
--- ZODB3/bsddb3Storage/bsddb3Storage/tests/test_whitebox.py:1.1.2.2	Wed Sep 11 14:11:48 2002
+++ ZODB3/bsddb3Storage/bsddb3Storage/tests/test_whitebox.py	Wed Sep 11 18:53:37 2002
@@ -23,10 +23,17 @@
 from bsddb3Storage.tests.BerkeleyTestBase import BerkeleyTestBase
 from bsddb3Storage.tests.ZODBTestBase import ZODBTestBase
 
+from Persistence import Persistent
+
 ZERO = '\0'*8
 
 
 
+class Object(Persistent):
+    pass
+
+
+
 class WhiteboxLowLevel(BerkeleyTestBase):
     ConcreteStorage = Minimal
 
@@ -83,6 +90,9 @@
         get_transaction().commit()
         obj.value = 13
         get_transaction().commit()
+        # Make sure the databases have what we expect
+        eq(len(self._storage._serials.items()), 2)
+        eq(len(self._storage._pickles.items()), 2)
         # And now refcount out the object
         del self._root.obj
         get_transaction().commit()
@@ -95,6 +105,48 @@
         # The pickles table now should have exactly one revision of the root
         # object, and no revisions of the MinPO object, which should have been
         # collected away.
+        pickles = self._storage._pickles.items()
+        eq(len(pickles), 1)
+        rec = pickles[0]
+        key = rec[0]
+        data = rec[1]
+        eq(key[:8], ZERO)
+        # And that pickle should have no 'obj' attribute.
+        unobj = zodb_unpickle(data)
+        self.failIf(hasattr(unobj, 'obj'))
+        # Our refcounts table should have no entries in it, because the root
+        # object is an island.
+        eq(len(self._storage._refcounts.keys()), 0)
+        # And of course, oids and pendings should be empty too
+        eq(len(self._storage._oids.keys()), 0)
+        eq(len(self._storage._pending.keys()), 0)
+
+    def checkRecursiveReferenceCounting(self):
+        eq = self.assertEqual
+        obj1 = Object()
+        obj2 = Object()
+        obj3 = Object()
+        obj4 = Object()
+        self._root.obj = obj1
+        obj1.obj = obj2
+        obj2.obj = obj3
+        obj3.obj = obj4
+        get_transaction().commit()
+        # Make sure the databases have what we expect
+        eq(len(self._storage._serials.items()), 5)
+        eq(len(self._storage._pickles.items()), 5)
+        # And now refcount out the object
+        del self._root.obj
+        get_transaction().commit()
+        # Verification stage.  Our serials table should have exactly one
+        # entry, oid == 0
+        keys = self._storage._serials.keys()
+        eq(len(keys), 1)
+        eq(len(self._storage._serials.items()), 1)
+        eq(keys[0], ZERO)
+        # The pickles table now should have exactly one revision of the root
+        # object, and no revisions of any other objects, which should have
+        # been collected away.
         pickles = self._storage._pickles.items()
         eq(len(pickles), 1)
         rec = pickles[0]