Skip to content
Snippets Groups Projects
Commit 49a118d5 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

ENH: added cache validation before loading to crawler

parent 6dbc7f6a
No related branches found
No related tags found
2 merge requests!59FIX: if multiple updates for one entity exist, the retrieve would result in an...,!46F cache version
......@@ -114,6 +114,7 @@ class Crawler(object):
if self.use_cache:
self.cache = Cache(db_file=cache_file)
self.cache.validate_cache()
def iteritems(self):
""" generates items to be crawled with an index"""
......
......@@ -174,3 +174,59 @@ class CacheTest2(unittest.TestCase):
for db_fn_defect in self.db_file_defect:
os.remove(db_fn_defect)
class InvalidationTest(unittest.TestCase):
"""
Test invalidation of cache entries.
"""
def setUp(self):
# Correct version:
self.cache = Cache(db_file=NamedTemporaryFile(delete=False).name,
force_creation=True)
def tearDown(self):
os.remove(self.cache.db_file)
def test_invalid(self):
assert len(self.cache.validate_cache()) == 0
ent = db.Record()
ent2 = db.Record()
ent2.add_parent(name="Experiment")
ent3 = db.Record()
ent3.add_parent(name="Analysis")
ent.id = 117
ent2.id = 328
ent3.id = 224
ent.version = db.common.versioning.Version("a")
ent2.version = db.common.versioning.Version("b")
ent3.version = db.common.versioning.Version("a")
el = [ent, ent2, ent3]
for e in el:
self.cache.insert(Cache.hash_entity(e), e.id, e.version.id)
for e in el:
res = self.cache.check_existing(Cache.hash_entity(e))
assert e.id == res[0]
assert e.version.id == res[1]
ent2.version.id = "c"
ent3.version.id = "b"
for e in el[1:]:
res = self.cache.check_existing(Cache.hash_entity(e))
assert res is None
invalidated_entries = self.cache.validate_cache(el)
assert 328 in invalidated_entries
assert 224 in invalidated_entries
assert 117 not in invalidated_entries
res = self.cache.run_sql_commands([
("SELECT * FROM identifiables", ())], fetchall=True)
assert len(res) == 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment