Commit e4434b81 authored by Christian Rober's avatar Christian Rober Committed by Yoni Fogel

refs #5374 added checkpoint end unit test for checkpointer class.

git-svn-id: file:///svn/toku/tokudb@47504 c7de825b-a66e-492c-adef-691d508d4ae1
parent f73d5490
......@@ -14,10 +14,17 @@
struct checkpointer_test {
checkpointer m_cp;
pair_list m_pl;
// Tests
void test_begin_checkpoint();
void test_pending_bits();
void test_update_cachefiles();
void test_end_checkpoint();
// Test Helper
void add_pairs(struct cachefile *cf,
ctpair pairs[],
uint32_t count,
uint32_t k);
};
//
......@@ -182,24 +189,8 @@ void checkpointer_test::test_pending_bits() {
// 3. Many hash chain entries.
//
const uint32_t count = 3;
ctpair pairs[count];
for (uint32_t i = 0; i < count; ++i) {
CACHEKEY key;
key.b = i;
uint32_t full_hash = toku_cachetable_hash(&cf, key);
pair_init(&(pairs[i]),
&cf,
key,
NULL,
attr,
CACHETABLE_CLEAN,
full_hash,
cb,
NULL,
&ctbl.list);
m_cp.m_ct->list.put(&pairs[i]);
}
ctpair pairs[count];
add_pairs(&cf, pairs, count, 0);
m_cp.turn_on_pending_bits();
......@@ -214,34 +205,142 @@ void checkpointer_test::test_pending_bits() {
assert(pp);
m_cp.m_ct->list.evict(pp);
}
int r = ctbl.list.destroy();
assert_zero(r);
}
//------------------------------------------------------------------------------
// test_update_cachefiles() -
// add_pairs() -
//
// Description:
// Description: Adds data (pairs) to the list referenced in the checkpoitner.
//
void checkpointer_test::test_update_cachefiles() {
void checkpointer_test::add_pairs(struct cachefile *cf,
ctpair pairs[],
uint32_t count,
uint32_t k)
{
pair_attr_s attr;
attr.size = 0;
attr.nonleaf_size = 0;
attr.leaf_size = 0;
attr.rollback_size = 0;
attr.cache_pressure_size = 0;
attr.is_valid = true;
CACHETABLE_WRITE_CALLBACK cb;
for (uint32_t i = k; i < count + k; ++i) {
CACHEKEY key;
key.b = i;
uint32_t full_hash = toku_cachetable_hash(cf, key);
pair_init(&(pairs[i]),
cf,
key,
NULL,
attr,
CACHETABLE_CLEAN,
full_hash,
cb,
NULL,
&m_cp.m_ct->list);
m_cp.m_ct->list.put(&pairs[i]);
}
}
//------------------------------------------------------------------------------
// get_number_pending_pairs() -
//
// Description: Helper function that iterates over pending list, and returns
// the number of pairs discovered.
//
static uint32_t get_number_pending_pairs(pair_list *list)
{
PAIR p;
uint32_t count = 0;
PAIR head = list->m_pending_head;
while((p = list->m_pending_head) != 0)
{
list->m_pending_head = list->m_pending_head->pending_next;
count++;
}
list->m_pending_head = head;
return count;
}
//------------------------------------------------------------------------------
// test_end_checkpoint() -
//
// Description:
// Description: Adds pairs to the list, before and after a checkpoint.
//
void checkpointer_test::test_end_checkpoint() {
// 1. Init test.
cachetable ctbl;
ctbl.list.init();
m_cp.m_ct = &ctbl;
cachefile_list cfl;
cfl.init();
struct cachefile cf;
memset(&cf, 0, sizeof(cf));
cf.next = NULL;
cf.for_checkpoint = true;
create_dummy_functions(&cf);
m_cp.init(&ctbl, NULL, &cfl);
m_cp.m_cf_list->m_head = &cf;
// 2. Add data before running checkpoint.
const uint32_t count = 6;
ctpair pairs[count];
add_pairs(&cf, pairs, count / 2, 0);
assert(m_cp.m_ct->list.m_n_in_table == count / 2);
// 3. Call begin checkpoint.
m_cp.begin_checkpoint();
assert(m_cp.m_checkpoint_num_files == 1);
for (uint32_t i = 0; i < count / 2; ++i)
{
assert(pairs[i].checkpoint_pending);
}
// 4. Add new data between starting and stopping checkpoint.
add_pairs(&cf, pairs, count / 2, count / 2);
assert(m_cp.m_ct->list.m_n_in_table == count);
for (uint32_t i = count / 2; i < count / 2; ++i)
{
assert(!pairs[i].checkpoint_pending);
}
uint32_t pending_pairs = 0;
pending_pairs = get_number_pending_pairs(&m_cp.m_ct->list);
assert(pending_pairs == count / 2);
// 5. Call end checkpoint
m_cp.end_checkpoint(NULL, NULL);
pending_pairs = get_number_pending_pairs(&m_cp.m_ct->list);
assert(pending_pairs == 0);
// Verify that none of the pairs are pending a checkpoint.
for (uint32_t i = 0; i < count; ++i)
{
assert(!pairs[i].checkpoint_pending);
}
/************
-add data
-call begin checkpoint
-add data
-call end checkpoint
-verify that 2nd added data NOT checkpointed
-verify that 1st added data WAS checkpointed
*************/
// 6. Cleanup
for (uint32_t i = 0; i < count; ++i) {
CACHEKEY key;
key.b = i;
uint32_t full_hash = toku_cachetable_hash(&cf, key);
PAIR pp = m_cp.m_ct->list.find_pair(&cf, key, full_hash);
assert(pp);
m_cp.m_ct->list.evict(pp);
}
int r = ctbl.list.destroy();
assert_zero(r);
}
......@@ -259,7 +358,7 @@ test_main(int argc, const char *argv[]) {
// Run the tests.
cp_test.test_begin_checkpoint();
cp_test.test_pending_bits();
cp_test.test_update_cachefiles();
cp_test.test_end_checkpoint();
return r;
}
......
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