Commit 8e70c116 authored by Toby Dickenson's avatar Toby Dickenson

rearranged checkLRU to use more than one transaction

parent b96b07b0
...@@ -123,30 +123,42 @@ class LRUCacheTests(CacheTestBase): ...@@ -123,30 +123,42 @@ class LRUCacheTests(CacheTestBase):
def checkLRU(self): def checkLRU(self):
# verify the LRU behavior of the cache # verify the LRU behavior of the cache
CACHE_SIZE = 5 dataset_size = 5
CACHE_SIZE = dataset_size*2+1
# a cache big enough to hold the objects added in two
# transactions, plus the root object
self.db.setCacheSize(CACHE_SIZE) self.db.setCacheSize(CACHE_SIZE)
c = self.db.open() c = self.db.open()
r = c.root() r = c.root()
l = [None] * 10 l = {}
for i in range(10):
l[i] = r[i] = MinPO(i)
# the root is the only thing in the cache, because all the # the root is the only thing in the cache, because all the
# other objects are new # other objects are new
self.assertEqual(len(c._cache), 1) self.assertEqual(len(c._cache), 1)
get_transaction().commit() # run several transactions
# commit() will register the objects, placing them in the cache. for t in range(5):
# at the end of commit, the cache will be reduced down to CACHE_SIZE for i in range(dataset_size):
# items l[(t,i)] = r[i] = MinPO(i)
self.assertEqual(c._cache.ringlen(), CACHE_SIZE) get_transaction().commit()
x = c._cache.get(p64(0), None) # commit() will register the objects, placing them in the cache.
self.assertEqual(x._p_changed, None) # the root is ghosted # at the end of commit, the cache will be reduced down to CACHE_SIZE
for i in range(len(l)): # items
if i < CACHE_SIZE: if len(l)>CACHE_SIZE:
# Changes are flushed but objects not ghostified self.assertEqual(c._cache.ringlen(), CACHE_SIZE)
self.assertEqual(l[i]._p_changed, 0) for i in range(dataset_size):
else: # Check objects added in the first two transactions.
# Objects are ghostified and evicted from the cache # They must all be ghostified.
self.assertEqual(l[i]._p_changed, None) self.assertEqual(l[(0,i)]._p_changed, None)
self.assertEqual(l[(1,i)]._p_changed, None)
# Check objects added in the last two transactions.
# They must all still exist in memory, but have
# had their changes flushed
self.assertEqual(l[(3,i)]._p_changed, 0)
self.assertEqual(l[(4,i)]._p_changed, 0)
# Of the objects added in the middle transaction, most
# will have been ghostified. There is one cache slot
# that may be occupied by either one of those objects or
# the root, depending on precise order of access. We do
# not bother to check this
def checkSize(self): def checkSize(self):
self.assertEqual(self.db.cacheSize(), 0) self.assertEqual(self.db.cacheSize(), 0)
......
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