]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
added --num-clients option to ctdb_messaging test
authorAndrew Tridgell <tridge@samba.org>
Wed, 11 Apr 2007 05:23:50 +0000 (15:23 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 11 Apr 2007 05:23:50 +0000 (15:23 +1000)
(This used to be ctdb commit 2f4e7e34071c8950f6c4d64469c5eb15d0888113)

ctdb/tests/ctdb_messaging.c

index 11cdd5e6a8a6e73048ee302b580b0716a8944471..54259642cbb5576eb40785571ec51b28c46f5fa6 100644 (file)
@@ -27,6 +27,7 @@ static int timelimit = 10;
 static int num_records = 10;
 static int num_msgs = 1;
 static int num_repeats = 100;
+static int num_clients = 2;
 
 
 /*
@@ -36,6 +37,7 @@ static void message_handler(struct ctdb_context *ctdb, uint32_t srvid,
                                 TDB_DATA data, void *private)
 {
        printf("client vnn:%d received a message to srvid:%d\n",ctdb_get_vnn(ctdb),srvid);
+       fflush(stdout);
 }
 
 /*
@@ -61,16 +63,17 @@ int main(int argc, const char *argv[])
                { "timelimit", 't', POPT_ARG_INT, &timelimit, 0, "timelimit", "integer" },
                { "num-records", 'r', POPT_ARG_INT, &num_records, 0, "num_records", "integer" },
                { "num-msgs", 'n', POPT_ARG_INT, &num_msgs, 0, "num_msgs", "integer" },
+               { "num-clients", 0, POPT_ARG_INT, &num_clients, 0, "num_clients", "integer" },
                POPT_TABLEEND
        };
        int opt;
        const char **extra_argv;
        int extra_argc = 0;
-       int ret;
+       int ret, i, j;
        poptContext pc;
        struct event_context *ev;
        pid_t pid;
-       uint32_t srvid;
+       int srvid;
        TDB_DATA data;
 
        pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST);
@@ -142,11 +145,16 @@ int main(int argc, const char *argv[])
        /* start the protocol running */
        ret = ctdb_start(ctdb);
 
-       pid=fork();
-       if (pid) {
-               srvid=0;
-       } else {
-               srvid=1;
+       srvid = -1;
+       for (i=0;i<num_clients-1;i++) {
+               pid=fork();
+               if (pid) {
+                       srvid = i;
+                       break;
+               }
+       }
+       if (srvid == -1) {
+               srvid = num_clients-1;
        }
 
        /* wait until all nodes are connected (should not be needed
@@ -157,12 +165,17 @@ int main(int argc, const char *argv[])
 
        ctdb_connect_wait(ctdb);
 
-       sleep(2);
+       sleep(1);
 
        printf("sending message from vnn:%d to vnn:%d/srvid:%d\n",ctdb_get_vnn(ctdb),ctdb_get_vnn(ctdb), 1-srvid);
-       ctdb_send_message(ctdb, ctdb_get_vnn(ctdb), 1-srvid, data);
+       for (i=0;i<ctdb_get_num_nodes(ctdb);i++) {
+               for (j=0;j<num_clients;j++) {
+                       printf("sending message to %d:%d\n", i, j);
+                       ctdb_send_message(ctdb, i, j, data);
+               }
+       }
 
-       while(1){
+       while (1) {
                event_loop_once(ev);
        }