diff --git a/test/testquorum.c b/test/testquorum.c index ebcbf07c..1323b25a 100644 --- a/test/testquorum.c +++ b/test/testquorum.c @@ -1,65 +1,64 @@ #include #include #include #include #include #include #include #include #include static quorum_handle_t g_handle; static void quorum_notification_fn( quorum_handle_t handle, uint32_t quorate, uint64_t ring_id, uint32_t view_list_entries, uint32_t *view_list) { int i; printf("quorum notification called \n"); printf(" quorate = %lu\n", (long unsigned int) quorate); printf(" ring id = " CS_PRI_RING_ID_SEQ "\n", ring_id); printf(" num nodes = %lu ", (long unsigned int) view_list_entries); for (i=0; i #include #include #include #include #include #include #include #include #include static quorum_handle_t g_handle; static void quorum_notification_fn( quorum_handle_t handle, uint32_t quorate, struct quorum_ring_id ring_id, uint32_t view_list_entries, const uint32_t *view_list) { int i; printf("quorum notification called \n"); printf(" quorate = %lu\n", (long unsigned int) quorate); printf(" ring id = " CS_PRI_RING_ID "\n", ring_id.nodeid, ring_id.seq); printf(" num nodes = %lu ", (long unsigned int) view_list_entries); for (i=0; i #include #include #include #include #include #include #include #include #include static votequorum_handle_t g_handle; static const char *node_state(int state) { switch (state) { case VOTEQUORUM_NODESTATE_MEMBER: return "Member"; break; case VOTEQUORUM_NODESTATE_DEAD: return "Dead"; break; case VOTEQUORUM_NODESTATE_LEAVING: return "Leaving"; break; default: return "UNKNOWN"; break; } } static void votequorum_expectedvotes_notification_fn( votequorum_handle_t handle, uint64_t context, uint32_t expected_votes ) { printf("votequorum expectedvotes notification called \n"); printf(" expected_votes = %d\n", expected_votes); } static void votequorum_quorum_notification_fn( votequorum_handle_t handle, uint64_t context, uint32_t quorate, uint32_t node_list_entries, votequorum_node_t node_list[] ) { int i; printf("votequorum quorum notification called \n"); printf(" number of nodes = %d\n", node_list_entries); printf(" quorate = %d\n", quorate); for (i = 0; i< node_list_entries; i++) { printf(" " CS_PRI_NODE_ID ": %s\n", node_list[i].nodeid, node_state(node_list[i].state)); } } static void votequorum_nodelist_notification_fn( votequorum_handle_t handle, uint64_t context, votequorum_ring_id_t ring_id, uint32_t node_list_entries, uint32_t node_list[] ) { int i; printf("votequorum nodelist notification called \n"); printf(" number of nodes = %d\n", node_list_entries); printf(" current ringid = (" CS_PRI_RING_ID ")\n", ring_id.nodeid, ring_id.seq); printf(" nodes: "); for (i = 0; i< node_list_entries; i++) { printf(CS_PRI_NODE_ID " ", node_list[i]); } printf("\n\n"); } int main(int argc, char *argv[]) { struct votequorum_info info; votequorum_callbacks_t callbacks; int err; if (argc > 1 && strcmp(argv[1], "-h")==0) { fprintf(stderr, "usage: %s [new-expected] [new-votes]\n", argv[0]); return 0; } callbacks.votequorum_quorum_notify_fn = votequorum_quorum_notification_fn; callbacks.votequorum_nodelist_notify_fn = votequorum_nodelist_notification_fn; callbacks.votequorum_expectedvotes_notify_fn = votequorum_expectedvotes_notification_fn; if ( (err=votequorum_initialize(&g_handle, &callbacks)) != CS_OK) fprintf(stderr, "votequorum_initialize FAILED: %d\n", err); if ( (err = votequorum_trackstart(g_handle, g_handle, CS_TRACK_CHANGES)) != CS_OK) fprintf(stderr, "votequorum_trackstart FAILED: %d\n", err); if ( (err=votequorum_getinfo(g_handle, 0, &info)) != CS_OK) fprintf(stderr, "votequorum_getinfo FAILED: %d\n", err); else { printf("node votes %d\n", info.node_votes); printf("expected votes %d\n", info.node_expected_votes); printf("highest expected %d\n", info.highest_expected); printf("total votes %d\n", info.total_votes); printf("quorum %d\n", info.quorum); printf("flags "); if (info.flags & VOTEQUORUM_INFO_TWONODE) printf("2Node "); if (info.flags & VOTEQUORUM_INFO_QUORATE) printf("Quorate "); if (info.flags & VOTEQUORUM_INFO_WAIT_FOR_ALL) printf("WaitForAll "); if (info.flags & VOTEQUORUM_INFO_LAST_MAN_STANDING) printf("LastManStanding "); if (info.flags & VOTEQUORUM_INFO_AUTO_TIE_BREAKER) printf("AutoTieBreaker "); if (info.flags & VOTEQUORUM_INFO_ALLOW_DOWNSCALE) printf("AllowDownscale "); printf("\n"); } if (argc >= 2 && atoi(argv[1])) { if ( (err=votequorum_setexpected(g_handle, atoi(argv[1]))) != CS_OK) fprintf(stderr, "set expected votes FAILED: %d\n", err); } if (argc >= 3 && atoi(argv[2])) { if ( (err=votequorum_setvotes(g_handle, 0, atoi(argv[2]))) != CS_OK) fprintf(stderr, "set votes FAILED: %d\n", err); } if (argc >= 2) { if ( (err=votequorum_getinfo(g_handle, 0, &info)) != CS_OK) fprintf(stderr, "votequorum_getinfo2 FAILED: %d\n", err); else { printf("-------------------\n"); printf("node votes %d\n", info.node_votes); printf("expected votes %d\n", info.node_expected_votes); printf("highest expected %d\n", info.highest_expected); printf("total votes %d\n", info.total_votes); printf("votequorum %d\n", info.quorum); printf("flags "); if (info.flags & VOTEQUORUM_INFO_TWONODE) printf("2Node "); if (info.flags & VOTEQUORUM_INFO_QUORATE) printf("Quorate "); if (info.flags & VOTEQUORUM_INFO_WAIT_FOR_ALL) printf("WaitForAll "); if (info.flags & VOTEQUORUM_INFO_LAST_MAN_STANDING) printf("LastManStanding "); if (info.flags & VOTEQUORUM_INFO_AUTO_TIE_BREAKER) printf("AutoTieBreaker "); if (info.flags & VOTEQUORUM_INFO_ALLOW_DOWNSCALE) printf("AllowDownscale "); printf("\n"); } } printf("Waiting for votequorum events, press ^C to finish\n"); printf("-------------------\n"); - while (1) { - if (votequorum_dispatch(g_handle, CS_DISPATCH_ALL) != CS_OK) { - fprintf(stderr, "votequorum_dispatch error\n"); - return -1; - } + if (votequorum_dispatch(g_handle, CS_DISPATCH_BLOCKING) != CS_OK) { + fprintf(stderr, "votequorum_dispatch error\n"); + return -1; } return 0; }