1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-24 21:34:56 +03:00

ctdb-tests: Add support for multiple ctdb connections in dummy_client

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
Amitay Isaacs 2017-09-22 14:14:00 +10:00 committed by Volker Lendecke
parent 6ed2ed7e2d
commit 90f7e06c25

View File

@ -31,6 +31,7 @@
static struct {
const char *sockpath;
const char *debuglevel;
int num_connections;
int timelimit;
const char *srvidstr;
} options;
@ -41,6 +42,8 @@ static struct poptOption cmdline_options[] = {
"Unix domain socket path", "filename" },
{ "debug", 'd', POPT_ARG_STRING, &options.debuglevel, 0,
"debug level", "ERR|WARNING|NOTICE|INFO|DEBUG" } ,
{ "nconn", 'n', POPT_ARG_INT, &options.num_connections, 0,
"number of connections", "" },
{ "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0,
"time limit", "seconds" },
{ "srvid", 'S', POPT_ARG_STRING, &options.srvidstr, 0,
@ -59,16 +62,18 @@ int main(int argc, const char *argv[])
{
TALLOC_CTX *mem_ctx;
struct tevent_context *ev;
struct ctdb_client_context *client;
struct ctdb_client_context **client;
struct ctdb_client_context *last_client;
const char *ctdb_socket;
poptContext pc;
int opt, ret;
int opt, ret, i;
int log_level;
bool status, done;
/* Set default options */
options.sockpath = CTDB_SOCKET;
options.debuglevel = "ERR";
options.num_connections = 1;
options.timelimit = 60;
options.srvidstr = NULL;
@ -112,19 +117,32 @@ int main(int argc, const char *argv[])
setup_logging("dummy_client", DEBUG_STDERR);
DEBUGLEVEL = log_level;
ret = ctdb_client_init(mem_ctx, ev, options.sockpath, &client);
if (ret != 0) {
D_ERR("Failed to initialize client, ret=%d\n", ret);
client = talloc_array(mem_ctx, struct ctdb_client_context *,
options.num_connections);
if (client == NULL) {
fprintf(stderr, "Memory allocation error\n");
exit(1);
}
for (i=0; i<options.num_connections; i++) {
ret = ctdb_client_init(client, ev, options.sockpath,
&client[i]);
if (ret != 0) {
D_ERR("Failed to initialize client %d, ret=%d\n",
i, ret);
exit(1);
}
}
last_client = client[options.num_connections-1];
done = false;
if (options.srvidstr != NULL) {
uint64_t srvid;
srvid = strtoull(options.srvidstr, NULL, 0);
ret = ctdb_client_set_message_handler(ev, client, srvid,
ret = ctdb_client_set_message_handler(ev, last_client, srvid,
dummy_handler, &done);
if (ret != 0) {
D_ERR("Failed to register srvid, ret=%d\n", ret);
@ -143,6 +161,6 @@ int main(int argc, const char *argv[])
exit(1);
}
talloc_free(client);
talloc_free(mem_ctx);
exit(0);
}