Commit e0942919 authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Improve the db_env_open_nocreate test so that it works on BDB

git-svn-id: file:///svn/tokudb@624 c7de825b-a66e-492c-adef-691d508d4ae1
parent 5fddd5db
// Try to open an environment where the directory does not exist
// Try when the dir exists but is not an initialized env
// Try when the dir exists and we do DB_CREATE: it should work.
// And after that the open should work without a DB_CREATE
// However, in BDB, after doing an DB_ENV->open and then a close, no state has changed
// One must actually create a DB I think...
#include <assert.h>
#include <db.h>
......@@ -9,28 +13,52 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
// DIR is defined in the Makefile
#define CKERR(r) if (r!=0) fprintf(stderr, "%s:%d error %d %s\n", __FILE__, __LINE__, r, db_strerror(r)); assert(r==0);
int main() {
DB *db;
DB_ENV *dbenv;
int r;
int do_private;
system("rm -rf " DIR);
r = db_env_create(&dbenv, 0);
assert(r == 0);
r = dbenv->open(dbenv, DIR, DB_PRIVATE|DB_INIT_MPOOL, 0);
assert(r==ENOENT);
dbenv->close(dbenv,0); // free memory
for (do_private=0; do_private<2; do_private++) {
int private_flags = do_private ? DB_PRIVATE : 0;
system("rm -rf " DIR);
r = db_env_create(&dbenv, 0);
CKERR(r);
r = dbenv->open(dbenv, DIR, private_flags|DB_INIT_MPOOL, 0);
assert(r==ENOENT);
dbenv->close(dbenv,0); // free memory
system("rm -rf " DIR);
mkdir(DIR, 0777);
r = db_env_create(&dbenv, 0);
CKERR(r);
r = dbenv->open(dbenv, DIR, private_flags|DB_INIT_MPOOL, 0);
assert(r==ENOENT);
dbenv->close(dbenv,0); // free memory
}
// Now make sure that if we have a non-private DB that we can tell if it opened or not.
system("rm -rf " DIR);
mkdir(DIR, 0777);
r = db_env_create(&dbenv, 0);
assert(r == 0);
r = dbenv->open(dbenv, DIR, DB_PRIVATE|DB_INIT_MPOOL, 0);
assert(r==ENOENT);
CKERR(r);
r = dbenv->open(dbenv, DIR, DB_CREATE|DB_INIT_MPOOL, 0);
CKERR(r);
r=db_create(&db, dbenv, 0);
CKERR(r);
dbenv->close(dbenv,0); // free memory
write(1,"d",1);
r = db_env_create(&dbenv, 0);
CKERR(r);
r = dbenv->open(dbenv, DIR, DB_INIT_MPOOL, 0);
CKERR(r);
dbenv->close(dbenv,0); // free memory
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