add a cache to the block manager

This commit is contained in:
Joe Thornber
2011-10-24 18:04:19 +01:00
parent 97f8d913e2
commit d02fcde793
7 changed files with 396 additions and 300 deletions

View File

@@ -18,7 +18,7 @@ namespace {
desc_("default constructed") {
}
Thing(unsigned n)
explicit Thing(unsigned n)
: key_(n),
desc_("foo bar") {
}
@@ -58,21 +58,35 @@ BOOST_AUTO_TEST_CASE(cache_caches)
unsigned const COUNT = 16;
cache<ThingTraits> c(COUNT);
for (unsigned i = 0; i < COUNT; i++)
for (unsigned i = 0; i < COUNT; i++) {
c.insert(Thing(i));
c.put(Thing(i));
}
for (unsigned i = 0; i < COUNT; i++)
BOOST_ASSERT(c.get(i));
}
BOOST_AUTO_TEST_CASE(new_entries_have_a_ref_count_of_one)
{
cache<ThingTraits> c(16);
c.insert(Thing(0));
c.put(Thing(0));
BOOST_CHECK_THROW(c.put(Thing(0)), runtime_error);
}
BOOST_AUTO_TEST_CASE(cache_drops_elements)
{
unsigned const COUNT = 1024;
unsigned const CACHE_SIZE = 16;
cache<ThingTraits> c(CACHE_SIZE);
for (unsigned i = 0; i < COUNT; i++)
for (unsigned i = 0; i < COUNT; i++) {
c.insert(Thing(i));
c.put(Thing(i));
}
for (unsigned i = 0; i < COUNT - CACHE_SIZE; i++)
BOOST_ASSERT(!c.get(i));
@@ -87,10 +101,8 @@ BOOST_AUTO_TEST_CASE(held_entries_count_towards_the_cache_limit)
cache<ThingTraits> c(CACHE_SIZE);
unsigned i;
for (i = 0; i < CACHE_SIZE; i++) {
for (i = 0; i < CACHE_SIZE; i++)
c.insert(Thing(i));
c.get(i);
}
BOOST_CHECK_THROW(c.insert(Thing(i)), runtime_error);
}
@@ -103,7 +115,6 @@ BOOST_AUTO_TEST_CASE(put_works)
unsigned i;
for (i = 0; i < CACHE_SIZE; i++) {
c.insert(Thing(i));
c.get(i);
c.put(Thing(i));
}