From ae0d8f432ef98a72c85a6cd42c503b718bef0e4e Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Sun, 25 Aug 2013 21:43:29 +1000 Subject: [PATCH] tests: Do not use libctdb code in tests Signed-off-by: Amitay Isaacs --- Makefile.in | 4 +- tests/src/ctdb_fetch_readonly_once.c | 73 +++++++++------------------- tests/src/ctdb_tool_libctdb.c | 1 - 3 files changed, 24 insertions(+), 54 deletions(-) diff --git a/Makefile.in b/Makefile.in index b40fc5d4..46b7a39c 100755 --- a/Makefile.in +++ b/Makefile.in @@ -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 $@ diff --git a/tests/src/ctdb_fetch_readonly_once.c b/tests/src/ctdb_fetch_readonly_once.c index 2f7cabe0..5dc64e0e 100644 --- a/tests/src/ctdb_fetch_readonly_once.c +++ b/tests/src/ctdb_fetch_readonly_once.c @@ -22,53 +22,26 @@ #include "system/filesys.h" #include "popt.h" #include -#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); diff --git a/tests/src/ctdb_tool_libctdb.c b/tests/src/ctdb_tool_libctdb.c index 9b86bdad..e7e191a1 100644 --- a/tests/src/ctdb_tool_libctdb.c +++ b/tests/src/ctdb_tool_libctdb.c @@ -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); -- 2.34.1