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 tdb1_context *tdb;
14 key.dsize = strlen("hi");
15 key.dptr = (void *)"hi";
17 tdb = tdb1_open_ex("run-nested-transactions.tdb",
18 1024, TDB1_CLEAR_IF_FIRST|TDB1_DISALLOW_NESTING,
19 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
22 ok1(tdb1_transaction_start(tdb) == 0);
23 data.dptr = (void *)"world";
24 data.dsize = strlen("world");
25 ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
26 data = tdb1_fetch(tdb, key);
27 ok1(data.dsize == strlen("world"));
28 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
30 ok1(tdb1_transaction_start(tdb) != 0);
31 ok1(tdb1_error(tdb) == TDB1_ERR_NESTING);
33 data = tdb1_fetch(tdb, key);
34 ok1(data.dsize == strlen("world"));
35 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
37 ok1(tdb1_transaction_commit(tdb) == 0);
38 data = tdb1_fetch(tdb, key);
39 ok1(data.dsize == strlen("world"));
40 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
44 /* Allow nesting by default. */
45 tdb = tdb1_open_ex("run-nested-transactions.tdb",
46 1024, TDB1_DEFAULT, 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));