Commit 3d1627f4 authored by Jeremy Hylton's avatar Jeremy Hylton

Add another test of the basic cache methods.

parent e3f96a50
......@@ -49,10 +49,82 @@ class RecalcitrantObject(Persistent):
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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment