torture: Test compound request request counters
[Samba.git] / source3 / torture / test_dbwrap_ctdb.c
blob4512358bd93e822a3926932731d07ec1d6b311ea
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_ctdbd.h"
28 bool run_local_dbwrap_ctdb(int dummy)
30 struct db_context *db = NULL;
31 int res;
32 bool ret = false;
33 NTSTATUS status;
34 uint32_t val;
35 struct messaging_context *msg_ctx;
36 struct ctdbd_connection *conn;
38 msg_ctx = server_messaging_context();
39 conn = messaging_ctdbd_connection();
40 if (conn == NULL) {
41 fprintf(stderr, "no ctdbd connection\n");
42 goto fail;
45 db = db_open_ctdb(talloc_tos(), msg_ctx, conn, "torture.tdb",
46 0, TDB_DEFAULT,
47 O_RDWR, 0755, DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
48 if (db == NULL) {
49 perror("db_open_ctdb failed");
50 goto fail;
53 res = dbwrap_transaction_start(db);
54 if (res != 0) {
55 fprintf(stderr, "dbwrap_transaction_start failed");
56 goto fail;
58 res = dbwrap_transaction_cancel(db);
59 if (res != 0) {
60 fprintf(stderr, "dbwrap_transaction_cancel failed");
61 goto fail;
64 res = dbwrap_transaction_start(db);
65 if (res != 0) {
66 fprintf(stderr, "dbwrap_transaction_start failed");
67 goto fail;
70 status = dbwrap_store_uint32_bystring(db, "foo", 1);
71 if (!NT_STATUS_IS_OK(status)) {
72 fprintf(stderr, "store_uint32 failed: %s\n",
73 nt_errstr(status));
74 goto fail;
76 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
77 if (!NT_STATUS_IS_OK(status)) {
78 fprintf(stderr, "fetch_uint32 failed: %s\n",
79 nt_errstr(status));
80 goto fail;
82 if (val != 1) {
83 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
84 (unsigned)val);
85 goto fail;
88 status = dbwrap_store_uint32_bystring(db, "bar", 5);
89 if (!NT_STATUS_IS_OK(status)) {
90 fprintf(stderr, "store_uint32 failed: %s\n",
91 nt_errstr(status));
92 goto fail;
94 status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
95 if (!NT_STATUS_IS_OK(status)) {
96 fprintf(stderr, "fetch_uint32 failed: %s\n",
97 nt_errstr(status));
98 goto fail;
100 if (val != 5) {
101 fprintf(stderr, "fetch_uint32 gave %u, expected 5",
102 (unsigned)val);
103 goto fail;
106 status = dbwrap_store_uint32_bystring(db, "foo", 2);
107 if (!NT_STATUS_IS_OK(status)) {
108 fprintf(stderr, "store_uint32 failed: %s\n",
109 nt_errstr(status));
110 goto fail;
112 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
113 if (!NT_STATUS_IS_OK(status)) {
114 fprintf(stderr, "fetch_uint32 failed: %s\n",
115 nt_errstr(status));
116 goto fail;
118 if (val != 2) {
119 fprintf(stderr, "fetch_uint32 gave %u, expected 2",
120 (unsigned)val);
121 goto fail;
124 res = dbwrap_transaction_commit(db);
125 if (res != 0) {
126 fprintf(stderr, "dbwrap_transaction_commit failed");
127 goto fail;
131 * check that the values have reached the disk
133 status = dbwrap_fetch_uint32_bystring(db, "foo", &val);
134 if (!NT_STATUS_IS_OK(status)) {
135 fprintf(stderr, "fetch_uint32 failed: %s\n",
136 nt_errstr(status));
137 goto fail;
139 if (val != 2) {
140 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
141 (unsigned)val);
142 goto fail;
145 status = dbwrap_fetch_uint32_bystring(db, "bar", &val);
146 if (!NT_STATUS_IS_OK(status)) {
147 fprintf(stderr, "fetch_uint32 failed: %s\n",
148 nt_errstr(status));
149 goto fail;
151 if (val != 5) {
152 fprintf(stderr, "fetch_uint32 gave %u, expected 1",
153 (unsigned)val);
154 goto fail;
157 ret = true;
158 fail:
159 TALLOC_FREE(db);
160 return ret;