[Zodb-checkins] CVS: ZODB3/ZEO/tests - test_cache.py:1.1.2.2
Jeremy Hylton
cvs-admin at zope.org
Mon Nov 10 17:42:55 EST 2003
Update of /cvs-repository/ZODB3/ZEO/tests
In directory cvs.zope.org:/tmp/cvs-serv9752/ZEO/tests
Modified Files:
Tag: ZODB3-mvcc-2-branch
test_cache.py
Log Message:
Revise ClientCache implementation and integrate with one of Tim's in-memory caches.
The in-memory cache isn't the expected long-term solution, but it shows how to integrate a lower-level storage scheme with the necessary application-level interface.
Add some simple tests of eviction, which the previous cache did not implement.
Add code one the way towards serialization.
=== ZODB3/ZEO/tests/test_cache.py 1.1.2.1 => 1.1.2.2 ===
--- ZODB3/ZEO/tests/test_cache.py:1.1.2.1 Tue Nov 4 15:04:37 2003
+++ ZODB3/ZEO/tests/test_cache.py Mon Nov 10 17:42:54 2003
@@ -13,6 +13,8 @@
##############################################################################
"""Basic unit tests for a multi-version client cache."""
+import os
+import tempfile
import unittest
import ZEO.cache
@@ -27,7 +29,11 @@
class CacheTests(unittest.TestCase):
def setUp(self):
- self.cache = ZEO.cache.Cache()
+ self.cache = ZEO.cache.ClientCache()
+
+ def tearDown(self):
+ if self.cache.path:
+ os.remove(self.cache.path)
def testLastTid(self):
self.assertEqual(self.cache.getLastTid(), None)
@@ -87,7 +93,32 @@
self.assertRaises(ValueError,
self.cache.store,
n1, "version", n2, n2, n3, "data")
-
+
+ def testEviction(self):
+ # Manually override the current maxsize
+ maxsize = self.cache.size = self.cache.dll.maxsize = 1245
+
+ # Trivial test of eviction code. Doesn't test non-current
+ # eviction.
+ data = ["z" * i for i in range(100)]
+ for i in range(50):
+ n = p64(i)
+ self.cache.store(n, "", n, n, None, data[i])
+ self.assertEquals(len(self.cache), i + 1)
+ self.assert_(self.cache.dll.currentsize < maxsize)
+ # The cache now uses 1225 bytes. The next insert
+ # should delete some objects.
+ n = p64(50)
+ self.cache.store(n, "", n, n, None, data[51])
+ self.assert_(len(self.cache) < 51)
+ self.assert_(self.cache.dll.currentsize < maxsize)
+
+ def testSerialization(self):
+ self.cache.path = tempfile.mktemp()
+ self.cache._write()
+
+ copy = ZEO.cache.ClientCache(self.cache.path)
+ copy.open()
def test_suite():
return unittest.makeSuite(CacheTests)
More information about the Zodb-checkins
mailing list