static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err, rd_kafka_topic_partition_list_t *parts, void *opaque) { int i; TEST_SAY("rebalance_cb: %s:\n", rd_kafka_err2str(err)); test_print_partition_list(parts); if (parts->cnt < partitions) TEST_FAIL("rebalance_cb: Expected %d partitions, not %d", partitions, parts->cnt); switch (err) { case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS: for (i = 0 ; i < parts->cnt ; i++) { if (i < partitions) parts->elems[i].offset = msgcnt / 2; else parts->elems[i].offset = RD_KAFKA_OFFSET_END; } TEST_SAY("Use these offsets:\n"); test_print_partition_list(parts); test_consumer_assign("HL.REBALANCE", rk, parts); break; case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS: test_consumer_unassign("HL.REBALANCE", rk); break; default: TEST_FAIL("rebalance_cb: error: %s", rd_kafka_err2str(err)); } }
static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err, rd_kafka_topic_partition_list_t *partitions, void *opaque) { char *memberid = rd_kafka_memberid(rk); TEST_SAY("%s: MemberId \"%s\": Consumer group rebalanced: %s\n", rd_kafka_name(rk), memberid, rd_kafka_err2str(err)); if (memberid) free(memberid); test_print_partition_list(partitions); switch (err) { case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS: assign_cnt++; rd_kafka_assign(rk, partitions); break; case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS: if (assign_cnt == 0) TEST_FAIL("asymetric rebalance_cb\n"); assign_cnt--; rd_kafka_assign(rk, NULL); break; default: TEST_FAIL("rebalance failed: %s\n", rd_kafka_err2str(err)); break; } }
static void rebalance_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err, rd_kafka_topic_partition_list_t *partitions, void *opaque) { int i; char *memberid = rd_kafka_memberid(rk); TEST_SAY("%s: MemberId \"%s\": Consumer group rebalanced: %s\n", rd_kafka_name(rk), memberid, rd_kafka_err2str(err)); if (memberid) free(memberid); test_print_partition_list(partitions); switch (err) { case RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS: assign_cnt++; rd_kafka_assign(rk, partitions); mtx_lock(&lock); consumers_running = 1; mtx_unlock(&lock); for (i = 0; i < partitions->cnt && i < MAX_THRD_CNT; ++i) { rd_kafka_topic_partition_t part = partitions->elems[i]; rd_kafka_queue_t *rkqu; /* This queue is loosed in partition-consume. */ rkqu = rd_kafka_queue_get_partition(rk, part.topic, part.partition); rd_kafka_queue_forward(rkqu, NULL); tids[part.partition] = spawn_thread(rkqu, part.partition); } rebalanced = 1; break; case RD_KAFKA_RESP_ERR__REVOKE_PARTITIONS: if (assign_cnt == 0) TEST_FAIL("asymetric rebalance_cb"); assign_cnt--; rd_kafka_assign(rk, NULL); mtx_lock(&lock); consumers_running = 0; mtx_unlock(&lock); break; default: TEST_FAIL("rebalance failed: %s", rd_kafka_err2str(err)); break; } }
/** * Wait for REBALANCE ASSIGN event and perform assignment * * Va-args are \p topic_cnt tuples of the expected assignment: * { const char *topic, int partition_cnt } */ static void await_assignment (const char *pfx, rd_kafka_t *rk, rd_kafka_queue_t *queue, int topic_cnt, ...) { rd_kafka_event_t *rkev; rd_kafka_topic_partition_list_t *tps; int i; va_list ap; int fails = 0; int exp_part_cnt = 0; TEST_SAY("%s: waiting for assignment\n", pfx); rkev = test_wait_event(queue, RD_KAFKA_EVENT_REBALANCE, 30000); if (!rkev) TEST_FAIL("timed out waiting for assignment"); TEST_ASSERT(rd_kafka_event_error(rkev) == RD_KAFKA_RESP_ERR__ASSIGN_PARTITIONS, "expected ASSIGN, got %s", rd_kafka_err2str(rd_kafka_event_error(rkev))); tps = rd_kafka_event_topic_partition_list(rkev); TEST_SAY("%s: assignment:\n", pfx); test_print_partition_list(tps); va_start(ap, topic_cnt); for (i = 0 ; i < topic_cnt ; i++) { const char *topic = va_arg(ap, const char *); int partition_cnt = va_arg(ap, int); int p; TEST_SAY("%s: expecting %s with %d partitions\n", pfx, topic, partition_cnt); for (p = 0 ; p < partition_cnt ; p++) { if (!rd_kafka_topic_partition_list_find(tps, topic, p)) { TEST_FAIL_LATER("%s: expected partition %s [%d] " "not found in assginment", pfx, topic, p); fails++; } } exp_part_cnt += partition_cnt; } va_end(ap); TEST_ASSERT(exp_part_cnt == tps->cnt, "expected assignment of %d partitions, got %d", exp_part_cnt, tps->cnt); if (fails > 0) TEST_FAIL("%s: assignment mismatch: see above", pfx); rd_kafka_assign(rk, tps); rd_kafka_event_destroy(rkev); }
static void offset_commit_cb (rd_kafka_t *rk, rd_kafka_resp_err_t err, rd_kafka_topic_partition_list_t *offsets, void *opaque) { rd_kafka_topic_partition_t *rktpar; TEST_SAYL(3, "Offset committed: %s:\n", rd_kafka_err2str(err)); if (err == RD_KAFKA_RESP_ERR__NO_OFFSET) return; test_print_partition_list(offsets); if (err) TEST_FAIL("Offset commit failed: %s", rd_kafka_err2str(err)); if (offsets->cnt == 0) TEST_FAIL("Expected at least one partition in offset_commit_cb"); /* Find correct partition */ if (!(rktpar = rd_kafka_topic_partition_list_find(offsets, topic, partition))) return; if (rktpar->err) TEST_FAIL("Offset commit failed for partitioń : %s", rd_kafka_err2str(rktpar->err)); if (rktpar->offset > expected_offset) TEST_FAIL("Offset committed %"PRId64 " > expected offset %"PRId64, rktpar->offset, expected_offset); if (rktpar->offset <= committed_offset) TEST_FAIL("Old offset %"PRId64" (re)committed: " "should be above committed_offset %"PRId64, rktpar->offset, committed_offset); committed_offset = rktpar->offset; if (rktpar->offset < expected_offset) { TEST_SAYL(3, "Offset committed %"PRId64 " < expected offset %"PRId64"\n", rktpar->offset, expected_offset); return; } TEST_SAYL(3, "Expected offset committed: %"PRId64"\n", rktpar->offset); }
static rd_kafka_resp_err_t on_commit ( rd_kafka_t *rk, const rd_kafka_topic_partition_list_t *offsets, rd_kafka_resp_err_t err, void *ic_opaque) { int ic_id = (int)(intptr_t)ic_opaque; /* Since on_commit is triggered a bit randomly and not per * message we only try to make sure it gets fully set at least once. */ TEST_ASSERT(ic_opaque != NULL); /* Verify opaque (base | ic id) */ TEST_ASSERT((ic_id & base_mask) == on_commit_base); ic_id &= ~base_mask; TEST_ASSERT(ic_opaque != NULL); TEST_SAYL(3, "on_commit: interceptor #%d called: %s\n", ic_id, rd_kafka_err2str(err)); if (test_level >= 4) test_print_partition_list(offsets); /* Check for rollover where a previous on_commit stint was * succesful and it just now started over */ if (on_commit_bits > 0 && ic_id == 0) { /* Verify completeness of previous stint */ verify_ic_cnt("on_commit", on_commit_bits, consumer_ic_cnt); /* Reset */ on_commit_bits = 0; } verify_ic_cnt("on_commit", on_commit_bits, ic_id); /* Set this interceptor's bit */ on_commit_bits |= 1 << ic_id; return RD_KAFKA_RESP_ERR_NO_ERROR; }