1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6
7
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22 ----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39 #include <toku_portability.h>
40 #include <memory.h>
41 #include <toku_portability.h>
42 #include <db.h>
43
44 #include <errno.h>
45 #include <sys/stat.h>
46
47 #include "test.h"
48
49 // TOKU_TEST_FILENAME is defined in the Makefile
50 #define FNAME "foo.tokudb"
51 const char *name = NULL;
52
53 #define NUM 8
54 #define MAX_LENGTH (1<<16)
55
56 DB_ENV *env;
57
58 DB *db;
59 DB_TXN *null_txn;
60
61 static void
open_db(void)62 open_db(void) {
63 int r = db_create(&db, env, 0);
64 CKERR(r);
65 r = db->open(db, null_txn, FNAME, name, DB_BTREE, DB_CREATE, 0666);
66 CKERR(r);
67 }
68
69 static void
delete_db(void)70 delete_db(void) {
71 int r = env->dbremove(env, NULL, FNAME, name, 0); CKERR(r);
72 }
73
74 static void
close_db(void)75 close_db(void) {
76 int r;
77 r = db->close(db, 0);
78 CKERR(r);
79 }
80
81 static void
setup_data(void)82 setup_data(void) {
83 int r = db_env_create(&env, 0); CKERR(r);
84 const int envflags = DB_CREATE|DB_INIT_MPOOL|DB_INIT_TXN|DB_INIT_LOCK |DB_THREAD |DB_PRIVATE;
85 r = env->open(env, TOKU_TEST_FILENAME, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
86 }
87
88 static void
runtest(void)89 runtest(void) {
90 int r;
91 toku_os_recursive_delete(TOKU_TEST_FILENAME);
92 r=toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO); assert(r==0);
93 setup_data();
94
95 name = "foo";
96 open_db();
97 close_db();
98 delete_db();
99
100 name = "foo1";
101 open_db();
102 close_db();
103 name = "foo2";
104 open_db();
105 close_db();
106 name = "foo1";
107 delete_db();
108 name = "foo2";
109 delete_db();
110
111 name = "foo1";
112 open_db();
113 close_db();
114 name = "foo2";
115 open_db();
116 close_db();
117 name = "foo2";
118 delete_db();
119 name = "foo1";
120 delete_db();
121
122 env->close(env, 0);
123 }
124
125
126 int
test_main(int argc,char * const argv[])127 test_main(int argc, char *const argv[]) {
128 parse_args(argc, argv);
129
130 runtest();
131 return 0;
132 }
133
134