From 0f3931bee0867f97787d5bed105881a1e78f2a8f Mon Sep 17 00:00:00 2001 From: Joe Thornber Date: Fri, 22 Jul 2011 16:43:15 +0100 Subject: [PATCH] check reopening sm disk --- space_map_disk.h | 4 ++-- space_map_disk_t.cc | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/space_map_disk.h b/space_map_disk.h index 7ea69ce..180056f 100644 --- a/space_map_disk.h +++ b/space_map_disk.h @@ -129,8 +129,8 @@ namespace persistent_data { : tm_(tm), nr_blocks_(root.nr_blocks_), nr_allocated_(root.nr_allocated_), - bitmaps_(tm_, root.bitmap_root_, typename sm_disk::index_entry_traits::ref_counter()), - ref_counts_(tm_, root.ref_count_root_, typename ref_count_traits::ref_counter()) { + bitmaps_(tm_, root.bitmap_root_, typename sm_disk_detail::index_entry_traits::ref_counter()), + ref_counts_(tm_, root.ref_count_root_, ref_count_traits::ref_counter()) { } block_address get_nr_blocks() const { diff --git a/space_map_disk_t.cc b/space_map_disk_t.cc index ea8729f..6977a1e 100644 --- a/space_map_disk_t.cc +++ b/space_map_disk_t.cc @@ -119,4 +119,28 @@ BOOST_AUTO_TEST_CASE(test_set_effects_nr_allocated) } } +BOOST_AUTO_TEST_CASE(test_reopen) +{ + unsigned char buffer[128]; + + { + auto sm = create_sm_disk(); + for (unsigned i = 0, step = 1; i < NR_BLOCKS; i += step, step++) { + sm->inc(i); + } + + BOOST_CHECK(sm->root_size() <= sizeof(buffer)); + + sm->copy_root(buffer, sizeof(buffer)); + } + + { + auto tm = create_tm(); + auto sm = persistent_data::open_disk_sm(tm, buffer); + + for (unsigned i = 0, step = 1; i < NR_BLOCKS; i += step, step++) + BOOST_CHECK_EQUAL(sm->get_count(i), 1); + } +} + //----------------------------------------------------------------