1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
8 int main(int argc, char *argv[])
10 struct tdb_context *tdb;
12 union tdb_attribute hsize;
14 hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
15 hsize.base.next = &tap_log_attr;
16 hsize.tdb1_hashsize.hsize = 1024;
19 key.dsize = strlen("hi");
20 key.dptr = (void *)"hi";
22 tdb = tdb1_open("run-nested-transactions.tdb",
24 O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
27 /* No nesting by default. */
28 ok1(tdb1_transaction_start(tdb) == 0);
29 data.dptr = (void *)"world";
30 data.dsize = strlen("world");
31 ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
32 data = tdb1_fetch(tdb, key);
33 ok1(data.dsize == strlen("world"));
34 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
36 ok1(tdb1_transaction_start(tdb) != 0);
37 ok1(tdb_error(tdb) == TDB_ERR_EINVAL);
39 data = tdb1_fetch(tdb, key);
40 ok1(data.dsize == strlen("world"));
41 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
43 ok1(tdb1_transaction_commit(tdb) == 0);
44 data = tdb1_fetch(tdb, key);
45 ok1(data.dsize == strlen("world"));
46 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
50 tdb = tdb1_open("run-nested-transactions.tdb",
51 TDB_ALLOW_NESTING, O_RDWR, 0, &tap_log_attr);
54 ok1(tdb1_transaction_start(tdb) == 0);
55 ok1(tdb1_transaction_start(tdb) == 0);
56 ok1(tdb1_delete(tdb, key) == 0);
57 ok1(tdb1_transaction_commit(tdb) == 0);
58 ok1(!tdb1_exists(tdb, key));
59 ok1(tdb1_transaction_cancel(tdb) == 0);
60 /* Surprise! Kills inner "committed" transaction. */
61 ok1(tdb1_exists(tdb, key));
63 ok1(tdb1_transaction_start(tdb) == 0);
64 ok1(tdb1_transaction_start(tdb) == 0);
65 ok1(tdb1_delete(tdb, key) == 0);
66 ok1(tdb1_transaction_commit(tdb) == 0);
67 ok1(!tdb1_exists(tdb, key));
68 ok1(tdb1_transaction_commit(tdb) == 0);
69 ok1(!tdb1_exists(tdb, key));