Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cuckoo test replacing expired item #1

Merged
merged 5 commits into from
Oct 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/ccommon/include/cc_metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extern "C" {
metric_decr_n((_base)->_metric, _delta); \
} \
} while(0)
#define DECR(_base, _metric) INCR_N(_base, _metric, 1)
#define DECR(_base, _metric) DECR_N(_base, _metric, 1)


#define METRIC_DECLARE(_name, _type, _description) \
Expand Down
97 changes: 97 additions & 0 deletions test/storage/cuckoo/check_cuckoo.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ test_expire_basic(uint32_t policy, bool cas)

it = cuckoo_get(&key);
ck_assert_msg(it == NULL, "cuckoo_get returned not NULL after expiration");
#undef NOW
#undef KEY
#undef VAL
}
Expand Down Expand Up @@ -322,6 +323,100 @@ START_TEST(test_expire_basic_random_false)
}
END_TEST

START_TEST(test_insert_replace_expired)
{
#define NOW 12345678

struct bstring key;
struct val val;
rstatus_t status;
char keystring[30];
uint64_t i;
cuckoo_metrics_st metrics;

cuckoo_teardown();
status = cuckoo_setup(CUCKOO_ITEM_SIZE, CUCKOO_NITEM, CUCKOO_POLICY_RANDOM, true, &metrics);
ck_assert_msg(status == CC_OK,
"could not setup cuckoo module");

now = NOW;
for (i = 0; metrics.item_curr.counter < CUCKOO_NITEM; i++) {
key.len = sprintf(keystring, "%llu", i);
key.data = keystring;

val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
}

// dict is full, all items will expire in now + 1
now += 2;
key.len = sprintf(keystring, "%llu", i);
key.data = keystring;

val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
ck_assert_int_eq(metrics.item_expire.counter, 1);
#undef NOW
}
END_TEST

START_TEST(test_insert_insert_expire_swap)
{
#define NOW 12345678
struct bstring key;
struct val val;
rstatus_t status;
char keystring[30];
uint64_t i;
cuckoo_metrics_st metrics;
int hits = 0;

cuckoo_teardown();
status = cuckoo_setup(CUCKOO_ITEM_SIZE, CUCKOO_NITEM, CUCKOO_POLICY_EXPIRE, false, &metrics);
ck_assert_msg(status == CC_OK,
"could not setup cuckoo module");

now = NOW;
for (i = 0; metrics.item_curr.counter < CUCKOO_NITEM; i++) {
key.len = sprintf(keystring, "%llu", i);
key.data = keystring;

val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + i);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
}

key.len = sprintf(keystring, "%llu", i);
key.data = keystring;

val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + i);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);

for (;i > 0 && hits < CUCKOO_NITEM;i--) {
if (cuckoo_get(&key) != NULL) {
hits++;
}
}
ck_assert_msg(hits == CUCKOO_NITEM, "expected %d hits, got %d",
CUCKOO_NITEM, hits);
#undef NOW
}
END_TEST
/*
* test suite
*/
Expand All @@ -348,6 +443,8 @@ cuckoo_suite(void)
tcase_add_test(tc_basic_req, test_delete_basic_random_false);
tcase_add_test(tc_basic_req, test_expire_basic_random_true);
tcase_add_test(tc_basic_req, test_expire_basic_random_false);
tcase_add_test(tc_basic_req, test_insert_replace_expired);
tcase_add_test(tc_basic_req, test_insert_insert_expire_swap);

return s;
}
Expand Down