1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "../common/mutex.c"
13 #include "tap-interface.h"
18 int main(int argc
, char *argv
[])
20 struct tdb_context
*tdb
;
24 key
.dsize
= strlen("hi");
25 key
.dptr
= discard_const_p(uint8_t, "hi");
27 tdb
= tdb_open_ex("run-nested-transactions.tdb",
28 1024, TDB_CLEAR_IF_FIRST
|TDB_DISALLOW_NESTING
,
29 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &taplogctx
, NULL
);
32 /* Nesting disallowed. */
33 ok1(tdb_transaction_start(tdb
) == 0);
34 data
.dptr
= discard_const_p(uint8_t, "world");
35 data
.dsize
= strlen("world");
36 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == 0);
37 data
= tdb_fetch(tdb
, key
);
38 ok1(data
.dsize
== strlen("world"));
39 ok1(memcmp(data
.dptr
, "world", strlen("world")) == 0);
41 ok1(tdb_transaction_start(tdb
) != 0);
42 ok1(tdb_error(tdb
) == TDB_ERR_NESTING
);
44 data
= tdb_fetch(tdb
, key
);
45 ok1(data
.dsize
== strlen("world"));
46 ok1(memcmp(data
.dptr
, "world", strlen("world")) == 0);
48 ok1(tdb_transaction_commit(tdb
) == 0);
49 data
= tdb_fetch(tdb
, key
);
50 ok1(data
.dsize
== strlen("world"));
51 ok1(memcmp(data
.dptr
, "world", strlen("world")) == 0);
55 /* Nesting allowed by default */
56 tdb
= tdb_open_ex("run-nested-transactions.tdb",
57 1024, TDB_DEFAULT
, O_RDWR
, 0, &taplogctx
, NULL
);
60 ok1(tdb_transaction_start(tdb
) == 0);
61 ok1(tdb_transaction_start(tdb
) == 0);
62 ok1(tdb_delete(tdb
, key
) == 0);
63 ok1(tdb_transaction_commit(tdb
) == 0);
64 ok1(!tdb_exists(tdb
, key
));
65 ok1(tdb_transaction_cancel(tdb
) == 0);
66 /* Surprise! Kills inner "committed" transaction. */
67 ok1(tdb_exists(tdb
, key
));
69 ok1(tdb_transaction_start(tdb
) == 0);
70 ok1(tdb_transaction_start(tdb
) == 0);
71 ok1(tdb_delete(tdb
, key
) == 0);
72 ok1(tdb_transaction_commit(tdb
) == 0);
73 ok1(!tdb_exists(tdb
, key
));
74 ok1(tdb_transaction_commit(tdb
) == 0);
75 ok1(!tdb_exists(tdb
, key
));