tests: Do not use libctdb code in tests
authorAmitay Isaacs <amitay@gmail.com>
Sun, 25 Aug 2013 11:43:29 +0000 (21:43 +1000)
committerAmitay Isaacs <amitay@gmail.com>
Fri, 4 Oct 2013 05:15:34 +0000 (15:15 +1000)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Makefile.in
tests/src/ctdb_fetch_readonly_once.c
tests/src/ctdb_tool_libctdb.c

index b40fc5d4a46a96f3320e7dfac768a73fd2cfa824..46b7a39ce58f2bebee3586657a12063ab258df49 100755 (executable)
@@ -238,9 +238,9 @@ tests/bin/ctdb_fetch_one: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch_one.o
        @echo Linking $@
        $(WRAPPER) $(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_one.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
 
-tests/bin/ctdb_fetch_readonly_once: tests/src/ctdb_fetch_readonly_once.o $(CTDB_EXTERNAL_OBJ)
+tests/bin/ctdb_fetch_readonly_once: tests/src/ctdb_fetch_readonly_once.o $(CTDB_CLIENT_OBJ)
        @echo Linking $@
-       $(WRAPPER) $(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_readonly_once.o $(CTDB_EXTERNAL_OBJ) $(LIB_FLAGS)
+       $(WRAPPER) $(CC) $(CFLAGS) -o $@ tests/src/ctdb_fetch_readonly_once.o $(CTDB_CLIENT_OBJ) $(LIB_FLAGS)
 
 tests/bin/ctdb_fetch_readonly_loop: $(CTDB_CLIENT_OBJ) tests/src/ctdb_fetch_readonly_loop.o
        @echo Linking $@
index 2f7cabe0af94a208575484c95a0c3899ddfb34ef..5dc64e0e0639fce648406274d69429c8b98dc9ad 100644 (file)
 #include "system/filesys.h"
 #include "popt.h"
 #include <poll.h>
-#include "ctdb.h"
 
 const char *TESTKEY = "testkey";
 
-static void rorl_cb(struct ctdb_db *ctdb_db,
-                  struct ctdb_lock *lock, TDB_DATA outdata, void *private)
-{
-       int *finished = private;
-
-       printf("Record fetchlocked.\n");
-       printf("Press enter to release the record ...\n");
-       (void)getchar();
-
-       *finished = 1;
-}
-
 /*
        Just try locking/unlocking a single record once
 */
-static void fetch_readonly_once(struct ctdb_connection *ctdb, struct ctdb_db *ctdb_db, TDB_DATA key)
+static void fetch_readonly_once(struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, TDB_DATA key)
 {
-       int finished;
+       TDB_DATA data;
+       struct ctdb_record_handle *h;
 
-       printf("Trying to fetch lock the record ...\n");
+       printf("Trying to readonly fetch lock the record ...\n");
 
-       finished = 0;
-       if (!ctdb_readonlyrecordlock_async(ctdb_db, key,
-                                      rorl_cb, &finished)) {
-               printf("Failed to send READONLYRECORDLOCK\n");
-               exit(10);
-       }
-
-       while (!finished) {
-               struct pollfd pfd;
-
-               pfd.fd = ctdb_get_fd(ctdb);
-               pfd.events = ctdb_which_events(ctdb);
-               if (poll(&pfd, 1, -1) < 0) {
-                       fprintf(stderr, "Poll failed");
-                       exit(10);
-               }
-               if (ctdb_service(ctdb, pfd.revents) < 0) {
-                       fprintf(stderr, "Failed to service");
-                       exit(10);
-               }
+       h = ctdb_fetch_readonly_lock(ctdb_db, ctdb, key, &data, 1);
+       if (h == NULL) {
+               fprintf(stderr, "Failed to get readonly lock\n");
+               exit(1);
        }
 
+       talloc_free(h);
        printf("Record released.\n");
 }
 
@@ -77,9 +50,9 @@ static void fetch_readonly_once(struct ctdb_connection *ctdb, struct ctdb_db *ct
 */
 int main(int argc, const char *argv[])
 {
-       struct ctdb_connection *ctdb;
-       struct ctdb_db *ctdb_db;
-       const char *socket_name;
+       struct ctdb_context *ctdb;
+       struct ctdb_db_context *ctdb_db;
+       struct event_context *ev;
 
        TDB_DATA key;
 
@@ -111,33 +84,31 @@ int main(int argc, const char *argv[])
                while (extra_argv[extra_argc]) extra_argc++;
        }
 
-       socket_name = getenv("CTDB_SOCKET");
-       if (socket_name == NULL) {
-               socket_name = "/tmp/ctdb.socket";
-       }
-       ctdb = ctdb_connect(socket_name, ctdb_log_file, stderr);
+       ev = event_context_init(NULL);
 
-       if (!ctdb) {
-               fprintf(stderr, "Connecting to /tmp/ctdb.socket");
-               exit(10);
+       ctdb = ctdb_cmdline_client(ev, timeval_current_ofs(3, 0));
+       if (ctdb == NULL) {
+               printf("failed to connect to ctdb daemon.\n");
+               exit(1);
        }
 
        key.dptr  = discard_const(TESTKEY);
        key.dsize = strlen(TESTKEY);
 
        /* attach to a specific database */
-       ctdb_db = ctdb_attachdb(ctdb, "test.tdb", false, 0);
+       ctdb_db = ctdb_attach(ctdb, timeval_current_ofs(3, 0), "test.tdb",
+                             false, 0);
        if (!ctdb_db) {
-               fprintf(stderr, "ctdb_attachdb failed\n");
+               fprintf(stderr, "ctdb_attach failed - %s\n", ctdb_errstr(ctdb));
                exit(10);
        }
 
        printf("Waiting for cluster\n");
        while (1) {
                uint32_t recmode=1;
-               ctdb_getrecmode(ctdb, CTDB_CURRENT_NODE, &recmode);
+               ctdb_ctrl_getrecmode(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, &recmode);
                if (recmode == 0) break;
-               sleep(1);
+               event_loop_once(ev);
        }
 
        fetch_readonly_once(ctdb, ctdb_db, key);
index 9b86bdad7ce5a62d3ef05fda9a80e97c82226eda..e7e191a1bad4770431fa4fec264fbaacb826f956 100644 (file)
@@ -143,7 +143,6 @@ static void test_parse_nodestring(const char *nodestring_s,
        }
 
        ctdb  = ctdb_connect("foo", NULL, NULL);
-       ctdb_connection = ctdb;
 
        libctdb_test_read_nodemap(ctdb);