ctdb-tests: Implement --interactive/-i option in fetch ring
authorMartin Schwenke <martin@meltin.net>
Tue, 2 Aug 2016 04:36:45 +0000 (14:36 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 8 Aug 2016 06:17:32 +0000 (08:17 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12109

Pair-programmed-with: Amitay Isaacs <amitay@gmail.com>
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/src/fetch_ring.c

index b5a63dff188f099c1d155b1993b57f6b22cb71d9..c875aed3a283f05056d7126e13f1c488ee3ddd80 100644 (file)
@@ -43,6 +43,7 @@ struct fetch_ring_state {
        struct ctdb_db_context *ctdb_db;
        int num_nodes;
        int timelimit;
+       int interactive;
        TDB_DATA key;
        int msg_count;
        struct timeval start_time;
@@ -61,7 +62,8 @@ static struct tevent_req *fetch_ring_send(TALLOC_CTX *mem_ctx,
                                          struct tevent_context *ev,
                                          struct ctdb_client_context *client,
                                          struct ctdb_db_context *ctdb_db,
-                                         int num_nodes, int timelimit)
+                                         int num_nodes, int timelimit,
+                                         int interactive)
 {
        struct tevent_req *req, *subreq;
        struct fetch_ring_state *state;
@@ -76,6 +78,7 @@ static struct tevent_req *fetch_ring_send(TALLOC_CTX *mem_ctx,
        state->ctdb_db = ctdb_db;
        state->num_nodes = num_nodes;
        state->timelimit = timelimit;
+       state->interactive = interactive;
        state->key.dptr = discard_const(TESTKEY);
        state->key.dsize = strlen(TESTKEY);
 
@@ -294,7 +297,9 @@ static void fetch_ring_final_read(struct tevent_req *subreq)
                return;
        }
 
-       printf("DATA:\n%s\n", (char *)data.dptr);
+       if (state->interactive == 1) {
+               printf("DATA:\n%s\n", (char *)data.dptr);
+       }
        talloc_free(data.dptr);
        talloc_free(h);
 
@@ -361,7 +366,8 @@ int main(int argc, const char *argv[])
        }
 
        req = fetch_ring_send(mem_ctx, ev, client, ctdb_db,
-                              opts->num_nodes, opts->timelimit);
+                             opts->num_nodes, opts->timelimit,
+                             opts->interactive);
        if (req == NULL) {
                fprintf(stderr, "Memory allocation error\n");
                exit(1);