1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
6 #include "tdb1-logging.h"
8 int main(int argc, char *argv[])
10 struct tdb_context *tdb;
14 key.dsize = strlen("hi");
15 key.dptr = (void *)"hi";
17 tdb = tdb1_open_ex("run-nested-transactions.tdb",
19 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
22 /* No nesting by default. */
23 ok1(tdb1_transaction_start(tdb) == 0);
24 data.dptr = (void *)"world";
25 data.dsize = strlen("world");
26 ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
27 data = tdb1_fetch(tdb, key);
28 ok1(data.dsize == strlen("world"));
29 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
31 ok1(tdb1_transaction_start(tdb) != 0);
32 ok1(tdb_error(tdb) == TDB_ERR_EINVAL);
34 data = tdb1_fetch(tdb, key);
35 ok1(data.dsize == strlen("world"));
36 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
38 ok1(tdb1_transaction_commit(tdb) == 0);
39 data = tdb1_fetch(tdb, key);
40 ok1(data.dsize == strlen("world"));
41 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
45 tdb = tdb1_open_ex("run-nested-transactions.tdb",
46 1024, TDB_ALLOW_NESTING, O_RDWR, 0, &taplogctx, NULL);
49 ok1(tdb1_transaction_start(tdb) == 0);
50 ok1(tdb1_transaction_start(tdb) == 0);
51 ok1(tdb1_delete(tdb, key) == 0);
52 ok1(tdb1_transaction_commit(tdb) == 0);
53 ok1(!tdb1_exists(tdb, key));
54 ok1(tdb1_transaction_cancel(tdb) == 0);
55 /* Surprise! Kills inner "committed" transaction. */
56 ok1(tdb1_exists(tdb, key));
58 ok1(tdb1_transaction_start(tdb) == 0);
59 ok1(tdb1_transaction_start(tdb) == 0);
60 ok1(tdb1_delete(tdb, key) == 0);
61 ok1(tdb1_transaction_commit(tdb) == 0);
62 ok1(!tdb1_exists(tdb, key));
63 ok1(tdb1_transaction_commit(tdb) == 0);
64 ok1(!tdb1_exists(tdb, key));