test_log3_abort.c 1.64 KB
Newer Older
1 2
/* -*- mode: C; c-basic-offset: 4 -*- */
#ident "Copyright (c) 2007 Tokutek Inc.  All rights reserved."
Yoni Fogel's avatar
Yoni Fogel committed
3 4
#include "test.h"

Yoni Fogel's avatar
Yoni Fogel committed
5

6 7 8 9 10 11 12
/* Like test_log3 except do abort */

#include <assert.h>
#include <db.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
13
#include <memory.h>
14 15 16 17 18 19 20 21 22 23

// ENVDIR is defined in the Makefile

static void make_db (void) {
    DB_ENV *env;
    DB *db;
    DB_TXN *tid;
    int r;

    system("rm -rf " ENVDIR);
24
    r=toku_os_mkdir(ENVDIR, S_IRWXU+S_IRWXG+S_IRWXO);       assert(r==0);
25
    r=db_env_create(&env, 0); assert(r==0);
26
    r=env->open(env, ENVDIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_PRIVATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
27 28
    r=db_create(&db, env, 0); CKERR(r);
    r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
29
    r=db->open(db, tid, "foo.db", 0, DB_BTREE, DB_CREATE, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    r=tid->commit(tid, 0);    assert(r==0);
    r=env->txn_begin(env, 0, &tid, 0); assert(r==0);
    {
	DBT key,data;
	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));
	key.data  = "hello"; key.size=6;
	data.data = "there"; data.size=6;
	r=db->put(db, tid, &key, &data, 0);  assert(r==0);
    }
    r=tid->abort(tid);    assert(r==0);

    // Now see that the string isn't there.
    {
	DBT key,data;
	memset(&key, 0, sizeof(key));
	memset(&data, 0, sizeof(data));
	key.data  = "hello"; key.size=6;
	r=db->get(db, 0, &key, &data, 0);
	assert(r==DB_NOTFOUND);
    }

    r=db->close(db, 0);       assert(r==0);
    r=env->close(env, 0);     assert(r==0);
}

Yoni Fogel's avatar
Yoni Fogel committed
56
int
57
test_main (int argc __attribute__((__unused__)), char *argv[] __attribute__((__unused__))) {
58 59 60
    make_db();
    return 0;
}