Commit 3f97de8b authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul Committed by Yoni Fogel

Fix #2326 (cxx/check_test_get_not_found failed). close[t:2326]

git-svn-id: file:///svn/toku/tokudb@17173 c7de825b-a66e-492c-adef-691d508d4ae1
parent df060cd5
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
Db::Db(DbEnv *env, u_int32_t flags) Db::Db(DbEnv *env, u_int32_t flags)
: the_Env(env) : the_Env(env)
{ {
assert(env); // modern versions of TokuDB require an env.
the_db = 0; the_db = 0;
is_private_env = (the_Env == 0); is_private_env = (the_Env == 0);
......
...@@ -4,8 +4,11 @@ ...@@ -4,8 +4,11 @@
#include <db_cxx.h> #include <db_cxx.h>
#include <assert.h> #include <assert.h>
#include <stdlib.h>
#include <memory.h>
const char *test_file_name = "test_get_not_found.tdb"; #define DIR __FILE__ ".dir"
#define fname "foo.tdb"
void db_put(Db *db, int k, int v) { void db_put(Db *db, int k, int v) {
Dbt key(&k, sizeof k); Dbt key(&k, sizeof k);
...@@ -33,12 +36,21 @@ void db_get(Db *db, int k, int v, int expectr) { ...@@ -33,12 +36,21 @@ void db_get(Db *db, int k, int v, int expectr) {
} }
} }
void test_not_found() { DbEnv *env = NULL;
int r; void reset_env (void) {
system("rm -rf " DIR);
toku_os_mkdir(DIR, 0777);
if (env) delete env;
env = new DbEnv(DB_CXX_NO_EXCEPTIONS);
int r = env->open(DIR, DB_INIT_MPOOL + DB_CREATE + DB_PRIVATE, 0777);
assert(r == 0);
}
unlink(test_file_name); void test_not_found(void) {
Db *db = new Db(0, DB_CXX_NO_EXCEPTIONS); assert(db); int r;
r = db->open(0, test_file_name, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); reset_env();
Db *db = new Db(env, DB_CXX_NO_EXCEPTIONS); assert(db);
r = db->open(0, fname, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
db_put(db, 1, 2); db_put(db, 1, 2);
db_get(db, 1, 2, 0); db_get(db, 1, 2, 0);
db_del(db, 1); db_del(db, 1);
...@@ -47,12 +59,12 @@ void test_not_found() { ...@@ -47,12 +59,12 @@ void test_not_found() {
delete db; delete db;
} }
void test_exception_not_found() { void test_exception_not_found(void) {
int r; int r;
unlink(test_file_name); reset_env();
Db *db = new Db(0, 0); assert(db); Db *db = new Db(env, 0); assert(db);
r = db->open(0, test_file_name, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0); r = db->open(0, fname, 0, DB_BTREE, DB_CREATE, 0777); assert(r == 0);
db_put(db, 1, 2); db_put(db, 1, 2);
db_get(db, 1, 2, 0); db_get(db, 1, 2, 0);
db_del(db, 1); db_del(db, 1);
...@@ -68,5 +80,6 @@ void test_exception_not_found() { ...@@ -68,5 +80,6 @@ void test_exception_not_found() {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
test_not_found(); test_not_found();
test_exception_not_found(); test_exception_not_found();
if (env) delete env;
return 0; return 0;
} }
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