Commit 6530c1c2 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Improve testing. Addresses #179, #178.

git-svn-id: file:///svn/tokudb@1261 c7de825b-a66e-492c-adef-691d508d4ae1
parent f31f24c2
......@@ -17,11 +17,21 @@ int errors;
void db_put(DB *db, int k, int v, u_int32_t put_flags, int rexpect) {
DBT key, val;
// Turn off error messages if we expect there to be an error.
if (rexpect!=0) {
db->set_errfile(db, 0);
} else {
db->set_errfile(db, stderr);
}
int r = db->put(db, 0, dbt_init(&key, &k, sizeof k), dbt_init(&val, &v, sizeof v), put_flags);
if (r != rexpect) {
#if USE_TDB
if (r == EINVAL && put_flags == DB_NODUPDATA) {
printf("%s:%d:WARNING:tokdub does not support DB_NODUPDATA yet\n", __FILE__, __LINE__);
static int did_warn = 0;
if (!did_warn) {
printf("%s:%d:WARNING:tokdub does not support DB_NODUPDATA yet\n", __FILE__, __LINE__);
did_warn=1;
}
return;
}
#endif
......@@ -30,6 +40,19 @@ void db_put(DB *db, int k, int v, u_int32_t put_flags, int rexpect) {
}
}
int maybe_do_db_dup_warning (int r, int dup_mode) {
#if USE_TDB
static int did_warn=0;
if (r != 0 && dup_mode == DB_DUP) {
if (did_warn==0) {
did_warn=1;
printf("%s:%d:WARNING: tokudb does not support DB_DUP\n", __FILE__, __LINE__);
}
return 1;
}
#endif
return 0;
}
void test_dup_key(int dup_mode, u_int32_t put_flags, int rexpect, int rexpectdupdup) {
if (verbose) printf("test_dup_key: %d, %u, %d, %d\n", dup_mode, put_flags, rexpect, rexpectdupdup);
......@@ -45,13 +68,10 @@ void test_dup_key(int dup_mode, u_int32_t put_flags, int rexpect, int rexpectdup
r = db_create(&db, null_env, 0); assert(r == 0);
db->set_errfile(db, stderr);
r = db->set_flags(db, dup_mode);
#if USE_TDB
if (r != 0 && dup_mode == DB_DUP) {
printf("%s:%d:WARNING: tokudb does not support DB_DUP\n", __FILE__, __LINE__);
if (maybe_do_db_dup_warning(r, dup_mode)) {
r = db->close(db, 0); assert(r == 0);
return;
return;
}
#endif
assert(r == 0);
r = db->set_pagesize(db, 4096); assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
......@@ -96,13 +116,10 @@ void test_dup_dup(int dup_mode, u_int32_t put_flags, int rexpect, int rexpectdup
r = db_create(&db, null_env, 0); assert(r == 0);
db->set_errfile(db, stderr);
r = db->set_flags(db, dup_mode);
#if USE_TDB
if (r != 0 && dup_mode == DB_DUP) {
printf("%s:%d:WARNING: tokudb does not support DB_DUP\n", __FILE__, __LINE__);
if (maybe_do_db_dup_warning(r, dup_mode)) {
r = db->close(db, 0); assert(r == 0);
return;
return;
}
#endif
assert(r == 0);
r = db->set_pagesize(db, 4096); assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
......@@ -147,13 +164,10 @@ void test_put_00_01_01(int dup_mode, u_int32_t put_flags) {
r = db_create(&db, null_env, 0); assert(r == 0);
db->set_errfile(db, stderr);
r = db->set_flags(db, dup_mode);
#if USE_TDB
if (r != 0 && dup_mode == DB_DUP) {
printf("%s:%d:WARNING: tokudb does not support DB_DUP\n", __FILE__, __LINE__);
if (maybe_do_db_dup_warning(r, dup_mode)) {
r = db->close(db, 0); assert(r == 0);
return;
return;
}
#endif
assert(r == 0);
r = db->set_pagesize(db, 4096); assert(r == 0);
r = db->open(db, null_txn, fname, "main", DB_BTREE, DB_CREATE, 0666); assert(r == 0);
......@@ -194,6 +208,11 @@ void test_put_00_01_01(int dup_mode, u_int32_t put_flags) {
int main(int argc, const char *argv[]) {
int yes_overwrite=0;
#ifdef USE_TDB
yes_overwrite = DB_YESOVERWRITE;
#endif
parse_args(argc, argv);
system("rm -rf " DIR);
......@@ -202,11 +221,8 @@ int main(int argc, const char *argv[]) {
test_put_00_01_01(0, 0);
test_put_00_01_01(0, DB_NOOVERWRITE);
test_put_00_01_01(DB_DUP | DB_DUPSORT, 0);
test_put_00_01_01(DB_DUP | DB_DUPSORT, yes_overwrite);
test_put_00_01_01(DB_DUP | DB_DUPSORT, DB_NOOVERWRITE);
#if USE_TDB
test_put_00_01_01(DB_DUP | DB_DUPSORT, DB_YESOVERWRITE);
#endif
/* dup key uniq data */
test_dup_key(0, 0, 0, 0);
......@@ -218,8 +234,8 @@ int main(int argc, const char *argv[]) {
test_dup_key(DB_DUP, DB_NOOVERWRITE, 0, DB_KEYEXIST);
#if USE_TDB
// test_dup_key(DB_DUP | DB_DUPSORT, 0, EINVAL, EINVAL);
test_dup_key(DB_DUP | DB_DUPSORT, 0, 0, 0);
test_dup_key(DB_DUP | DB_DUPSORT, 0, EINVAL, EINVAL);
//test_dup_key(DB_DUP | DB_DUPSORT, 0, 0, 0);
test_dup_key(DB_DUP | DB_DUPSORT, DB_YESOVERWRITE, 0, 0);
#else
test_dup_key(DB_DUP | DB_DUPSORT, 0, 0, 0);
......@@ -238,7 +254,7 @@ int main(int argc, const char *argv[]) {
#if USE_TDB
// test_dup_dup(DB_DUP | DB_DUPSORT, 0, EINVAL, EINVAL);
test_dup_dup(DB_DUP | DB_DUPSORT, 0, 0, DB_KEYEXIST);
//test_dup_dup(DB_DUP | DB_DUPSORT, 0, 0, DB_KEYEXIST);
test_dup_dup(DB_DUP | DB_DUPSORT, DB_YESOVERWRITE, 0, 0);
#else
test_dup_dup(DB_DUP | DB_DUPSORT, 0 , 0, DB_KEYEXIST);
......
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