rpc_server3: Use fdopen_keepfd()
[Samba.git] / source3 / torture / test_dbwrap_ctdb.c
blobe3a7c6a0035bd92d1d94c9b9af89157e67ee77f7
1 /*
2 * Unix SMB/CIFS implementation.
3 * Test dbwrap_ctdb API
4 * Copyright (C) Volker Lendecke 2012
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
21 #include "torture/proto.h"
22 #include "system/filesys.h"
23 #include "lib/dbwrap/dbwrap.h"
24 #include "lib/dbwrap/dbwrap_ctdb.h"
25 #include "messages.h"
26 #include "lib/messages_ctdb.h"
27 #include "lib/global_contexts.h"
29 bool run_local_dbwrap_ctdb1(int dummy)
31 struct db_context *db = NULL;
32 int res;
33 bool ret = false;
34 NTSTATUS status;
35 uint32_t val;
36 struct messaging_context *msg_ctx;
38 msg_ctx = global_messaging_context();
40 db = db_open_ctdb(
41 talloc_tos(),
42 msg_ctx,
43 "torture.tdb",
45 TDB_DEFAULT,
46 O_RDWR|O_CREAT,
47 0755,
48 DBWRAP_LOCK_ORDER_1,
49 DBWRAP_FLAG_NONE);
50 if (db == NULL) {
51 perror("db_open_ctdb failed");
52 goto fail;
55 res = dbwrap_transaction_start(db);
56 if (res != 0) {
57 fprintf(stderr, "dbwrap_transaction_start failed");
58 goto fail;
60 res = dbwrap_transaction_cancel(db);
61 if (res != 0) {
62 fprintf(stderr, "dbwrap_transaction_cancel failed");
63 goto fail;
66 res = dbwrap_transaction_start(db);
67 if (res != 0) {
68 fprintf(stderr, "dbwrap_transaction_start failed");
69 goto fail;
72 status = dbwrap_store_uint32_bystring(db, "foo", 1);
73 if (!NT_STATUS_IS_OK(status)) {
74 fprintf(stderr, "store_uint32 failed: %s\n",
75 nt_errstr(status));
76 goto fail;
78 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
79 if (!NT_STATUS_IS_OK(status)) {
80 fprintf(stderr, "fetch_uint32 failed: %s\n",
81 nt_errstr(status));
82 goto fail;
84 if (val != 1) {
85 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
86 (unsigned)val);
87 goto fail;
90 status = dbwrap_store_uint32_bystring(db, "bar", 5);
91 if (!NT_STATUS_IS_OK(status)) {
92 fprintf(stderr, "store_uint32 failed: %s\n",
93 nt_errstr(status));
94 goto fail;
96 status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
97 if (!NT_STATUS_IS_OK(status)) {
98 fprintf(stderr, "fetch_uint32 failed: %s\n",
99 nt_errstr(status));
100 goto fail;
102 if (val != 5) {
103 fprintf(stderr, "fetch_uint32 gave %u, expected 5",
104 (unsigned)val);
105 goto fail;
108 status = dbwrap_store_uint32_bystring(db, "foo", 2);
109 if (!NT_STATUS_IS_OK(status)) {
110 fprintf(stderr, "store_uint32 failed: %s\n",
111 nt_errstr(status));
112 goto fail;
114 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
115 if (!NT_STATUS_IS_OK(status)) {
116 fprintf(stderr, "fetch_uint32 failed: %s\n",
117 nt_errstr(status));
118 goto fail;
120 if (val != 2) {
121 fprintf(stderr, "fetch_uint32 gave %u, expected 2",
122 (unsigned)val);
123 goto fail;
126 res = dbwrap_transaction_commit(db);
127 if (res != 0) {
128 fprintf(stderr, "dbwrap_transaction_commit failed");
129 goto fail;
133 * check that the values have reached the disk
135 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
136 if (!NT_STATUS_IS_OK(status)) {
137 fprintf(stderr, "fetch_uint32 failed: %s\n",
138 nt_errstr(status));
139 goto fail;
141 if (val != 2) {
142 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
143 (unsigned)val);
144 goto fail;
147 status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
148 if (!NT_STATUS_IS_OK(status)) {
149 fprintf(stderr, "fetch_uint32 failed: %s\n",
150 nt_errstr(status));
151 goto fail;
153 if (val != 5) {
154 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
155 (unsigned)val);
156 goto fail;
159 ret = true;
160 fail:
161 TALLOC_FREE(db);
162 return ret;