[Zope3-checkins] CVS: Zope/lib/python/ZODB/tests - test_cache.py:1.2

Jeremy Hylton jeremy at zope.com
Tue Mar 2 11:43:59 EST 2004


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

Modified Files:
	test_cache.py 
Log Message:
Add another test of the basic cache methods.


=== Zope/lib/python/ZODB/tests/test_cache.py 1.1 => 1.2 ===
--- Zope/lib/python/ZODB/tests/test_cache.py:1.1	Tue Mar  2 11:25:21 2004
+++ Zope/lib/python/ZODB/tests/test_cache.py	Tue Mar  2 11:43:58 2004
@@ -49,10 +49,82 @@
     def _p_deactivate(self):
         self.__class__.deactivations += 1
 
+class RegularObject(Persistent):
+
+    deactivations = 0
+    invalidations = 0
+
+    def _p_deactivate(self):
+        self.__class__.deactivations += 1
+        super(RegularObject, self)._p_deactivate()
+
+    def _p_invalidate(self):
+        self.__class__.invalidations += 1
+        super(RegularObject, self)._p_invalidate()
+
 class CacheTests(unittest.TestCase):
 
     def test_cache(self):
-        pass
+        r"""Test basic cache methods.
+        
+        >>> db = databaseFromString("<zodb>\n"
+        ...                         "cache-size 4\n"
+        ...                         "<mappingstorage/>\n"
+        ...                         "</zodb>")
+        >>> cn = db.open()
+        >>> r = cn.root()
+        >>> L = []
+        >>> for i in range(5):
+        ...     o = RegularObject()
+        ...     L.append(o)
+        ...     r[i] = o
+        >>> get_transaction().commit()
+
+        After committing a transaction and calling cacheGC(), there
+        should be cache-size (4) objects in the cache.  One of the
+        RegularObjects was deactivated.
+        
+        >>> cn._cache.ringlen()
+        4
+        >>> RegularObject.deactivations
+        1
+
+        If we explicitly activate the objects again, the ringlen
+        should go back up to 5.
+        
+        >>> for o in L:
+        ...     o._p_activate()
+        >>> cn._cache.ringlen()
+        5
+
+        >>> cn.cacheGC()
+        >>> cn._cache.ringlen()
+        4
+        >>> RegularObject.deactivations
+        2
+        
+        >>> cn.cacheMinimize()
+        >>> cn._cache.ringlen()
+        0
+        >>> RegularObject.deactivations
+        6
+
+        If we activate all the objects again and mark one as modified,
+        then the one object should not be deactivated even by a
+        minimize.
+        
+        >>> for o in L:
+        ...     o._p_activate()
+        >>> o.attr = 1  
+        >>> cn._cache.ringlen()
+        5
+        >>> cn.cacheMinimize()
+        >>> cn._cache.ringlen()
+        1
+        >>> RegularObject.deactivations
+        10
+        
+        """
 
     def test_cache_gc_recalcitrant(self):
         r"""Test that a cacheGC() call will return.




More information about the Zope3-Checkins mailing list