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 = tdb_open("run-nested-transactions.tdb1",
23 TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
26 /* No nesting by default. */
27 ok1(tdb1_transaction_start(tdb) == 0);
28 data.dptr = (void *)"world";
29 data.dsize = strlen("world");
30 ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
31 ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
32 ok1(data.dsize == strlen("world"));
33 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
35 ok1(tdb1_transaction_start(tdb) != 0);
36 ok1(tdb_error(tdb) == TDB_ERR_EINVAL);
38 ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
39 ok1(data.dsize == strlen("world"));
40 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
42 ok1(tdb1_transaction_commit(tdb) == 0);
43 ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS);
44 ok1(data.dsize == strlen("world"));
45 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
49 tdb = tdb_open("run-nested-transactions.tdb1",
50 TDB_ALLOW_NESTING, O_RDWR, 0, &tap_log_attr);
53 ok1(tdb1_transaction_start(tdb) == 0);
54 ok1(tdb1_transaction_start(tdb) == 0);
55 ok1(tdb1_delete(tdb, key) == 0);
56 ok1(tdb1_transaction_commit(tdb) == 0);
57 ok1(!tdb1_exists(tdb, key));
58 ok1(tdb1_transaction_cancel(tdb) == 0);
59 /* Surprise! Kills inner "committed" transaction. */
60 ok1(tdb1_exists(tdb, key));
62 ok1(tdb1_transaction_start(tdb) == 0);
63 ok1(tdb1_transaction_start(tdb) == 0);
64 ok1(tdb1_delete(tdb, key) == 0);
65 ok1(tdb1_transaction_commit(tdb) == 0);
66 ok1(!tdb1_exists(tdb, key));
67 ok1(tdb1_transaction_commit(tdb) == 0);
68 ok1(!tdb1_exists(tdb, key));