|
Packit |
2997f0 |
/*
|
|
Packit |
2997f0 |
* librdkafka - Apache Kafka C library
|
|
Packit |
2997f0 |
*
|
|
Packit |
2997f0 |
* Copyright (c) 2012-2015, Magnus Edenhill
|
|
Packit |
2997f0 |
* All rights reserved.
|
|
Packit |
2997f0 |
*
|
|
Packit |
2997f0 |
* Redistribution and use in source and binary forms, with or without
|
|
Packit |
2997f0 |
* modification, are permitted provided that the following conditions are met:
|
|
Packit |
2997f0 |
*
|
|
Packit |
2997f0 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
Packit |
2997f0 |
* this list of conditions and the following disclaimer.
|
|
Packit |
2997f0 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
Packit |
2997f0 |
* this list of conditions and the following disclaimer in the documentation
|
|
Packit |
2997f0 |
* and/or other materials provided with the distribution.
|
|
Packit |
2997f0 |
*
|
|
Packit |
2997f0 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Packit |
2997f0 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Packit |
2997f0 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
Packit |
2997f0 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
Packit |
2997f0 |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
Packit |
2997f0 |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
Packit |
2997f0 |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
Packit |
2997f0 |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
Packit |
2997f0 |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
Packit |
2997f0 |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
Packit |
2997f0 |
* POSSIBILITY OF SUCH DAMAGE.
|
|
Packit |
2997f0 |
*/
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
#include "test.h"
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
/* Typical include path would be <librdkafka/rdkafka.h>, but this program
|
|
Packit |
2997f0 |
* is built from within the librdkafka source tree and thus differs. */
|
|
Packit |
2997f0 |
#include "rdkafka.h" /* for Kafka driver */
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
/**
|
|
Packit |
2997f0 |
* Consumer partition assignment test, without consumer group balancing.
|
|
Packit |
2997f0 |
*/
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
int main_0016_assign_partition (int argc, char **argv) {
|
|
Packit |
2997f0 |
const char *topic = test_mk_topic_name(__FUNCTION__, 1);
|
|
Packit |
2997f0 |
rd_kafka_t *rk_p, *rk_c;
|
|
Packit |
2997f0 |
rd_kafka_topic_t *rkt_p;
|
|
Packit |
2997f0 |
int msg_cnt = 1000;
|
|
Packit |
2997f0 |
int msg_base = 0;
|
|
Packit |
2997f0 |
int partition_cnt = 2;
|
|
Packit |
2997f0 |
int partition;
|
|
Packit |
2997f0 |
uint64_t testid;
|
|
Packit |
2997f0 |
rd_kafka_topic_conf_t *default_topic_conf;
|
|
Packit |
2997f0 |
rd_kafka_topic_partition_list_t *partitions;
|
|
Packit |
2997f0 |
char errstr[512];
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
testid = test_id_generate();
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
/* Produce messages */
|
|
Packit |
2997f0 |
rk_p = test_create_producer();
|
|
Packit |
2997f0 |
rkt_p = test_create_producer_topic(rk_p, topic, NULL);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
for (partition = 0 ; partition < partition_cnt ; partition++) {
|
|
Packit |
2997f0 |
test_produce_msgs(rk_p, rkt_p, testid, partition,
|
|
Packit |
2997f0 |
msg_base+(partition*msg_cnt), msg_cnt,
|
|
Packit |
2997f0 |
NULL, 0);
|
|
Packit |
2997f0 |
}
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
rd_kafka_topic_destroy(rkt_p);
|
|
Packit |
2997f0 |
rd_kafka_destroy(rk_p);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
test_conf_init(NULL, &default_topic_conf, 0);
|
|
Packit |
2997f0 |
if (rd_kafka_topic_conf_set(default_topic_conf, "auto.offset.reset",
|
|
Packit |
2997f0 |
"smallest", errstr, sizeof(errstr)) !=
|
|
Packit |
2997f0 |
RD_KAFKA_CONF_OK)
|
|
Packit |
2997f0 |
TEST_FAIL("%s\n", errstr);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
rk_c = test_create_consumer(topic/*group_id*/, NULL,
|
|
Packit |
2997f0 |
default_topic_conf);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
/* Fill in partition set */
|
|
Packit |
2997f0 |
partitions = rd_kafka_topic_partition_list_new(partition_cnt);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
for (partition = 0 ; partition < partition_cnt ; partition++)
|
|
Packit |
2997f0 |
rd_kafka_topic_partition_list_add(partitions, topic, partition);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
test_consumer_assign("assign.partition", rk_c, partitions);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
/* Make sure all messages are available */
|
|
Packit |
2997f0 |
test_consumer_poll("verify.all", rk_c, testid, partition_cnt,
|
|
Packit |
2997f0 |
msg_base, partition_cnt * msg_cnt);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
/* Stop assignments */
|
|
Packit |
2997f0 |
test_consumer_unassign("unassign.partitions", rk_c);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
#if 0 // FIXME when get_offset() is functional
|
|
Packit |
2997f0 |
/* Acquire stored offsets */
|
|
Packit |
2997f0 |
for (partition = 0 ; partition < partition_cnt ; partition++) {
|
|
Packit |
2997f0 |
rd_kafka_resp_err_t err;
|
|
Packit |
2997f0 |
rd_kafka_topic_t *rkt_c = rd_kafka_topic_new(rk_c, topic, NULL);
|
|
Packit |
2997f0 |
int64_t offset;
|
|
Packit |
2997f0 |
test_timing_t t_offs;
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
TIMING_START(&t_offs, "GET.OFFSET");
|
|
Packit |
2997f0 |
err = rd_kafka_consumer_get_offset(rkt_c, partition,
|
|
Packit |
2997f0 |
&offset, 5000);
|
|
Packit |
2997f0 |
TIMING_STOP(&t_offs);
|
|
Packit |
2997f0 |
if (err)
|
|
Packit |
2997f0 |
TEST_FAIL("Failed to get offsets for %s [%"PRId32"]: "
|
|
Packit |
2997f0 |
"%s\n",
|
|
Packit |
2997f0 |
rd_kafka_topic_name(rkt_c), partition,
|
|
Packit |
2997f0 |
rd_kafka_err2str(err));
|
|
Packit |
2997f0 |
TEST_SAY("get_offset for %s [%"PRId32"] returned %"PRId64"\n",
|
|
Packit |
2997f0 |
rd_kafka_topic_name(rkt_c), partition, offset);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
rd_kafka_topic_destroy(rkt_c);
|
|
Packit |
2997f0 |
}
|
|
Packit |
2997f0 |
#endif
|
|
Packit |
2997f0 |
test_consumer_close(rk_c);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
rd_kafka_destroy(rk_c);
|
|
Packit |
2997f0 |
|
|
Packit |
2997f0 |
return 0;
|
|
Packit |
2997f0 |
}
|