1 /*
2 * librdkafka - Apache Kafka C library
3 *
4 * Copyright (c) 2018, Magnus Edenhill
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "test.h"
30
31
32 /**
33 * @name Mixed MsgVersions.
34 *
35 * - Create producer.
36 * - Produce N/2 m essages. (with MsgVer2)
37 * - Change the topic message.format.version to a MsgVer1 version.
38 * - Consume the messages to verify all can be read.
39 */
40
41
42
main_0092_mixed_msgver(int argc,char ** argv)43 int main_0092_mixed_msgver (int argc, char **argv) {
44 rd_kafka_t *rk;
45 const char *topic = test_mk_topic_name("0092_mixed_msgver", 1);
46 int32_t partition = 0;
47 const int msgcnt = 60;
48 int cnt;
49 int64_t testid;
50 int msgcounter = msgcnt;
51
52 if (test_idempotent_producer) {
53 TEST_SKIP("Idempotent producer requires MsgVersion >= 2\n");
54 return 0;
55 }
56
57 testid = test_id_generate();
58
59 rk = test_create_producer();
60
61 /* Produce messages */
62 for (cnt = 0 ; cnt < msgcnt ; cnt++) {
63 rd_kafka_resp_err_t err;
64 char buf[230];
65
66 test_msg_fmt(buf, sizeof(buf), testid, partition, cnt);
67
68 err = rd_kafka_producev(
69 rk,
70 RD_KAFKA_V_TOPIC(topic),
71 RD_KAFKA_V_PARTITION(partition),
72 RD_KAFKA_V_VALUE(buf, sizeof(buf)),
73 RD_KAFKA_V_MSGFLAGS(RD_KAFKA_MSG_F_COPY),
74 RD_KAFKA_V_OPAQUE(&msgcounter),
75 RD_KAFKA_V_END);
76 TEST_ASSERT(!err, "producev() #%d failed: %s",
77 cnt, rd_kafka_err2str(err));
78
79 /* One message per batch */
80 rd_kafka_flush(rk, 30*1000);
81
82 if (cnt == msgcnt / 2) {
83 const char *msgconf[] = {
84 "message.format.version",
85 "0.10.0.0"
86 };
87 TEST_SAY("Changing message.format.version\n");
88 err = test_AlterConfigs_simple(
89 rk,
90 RD_KAFKA_RESOURCE_TOPIC, topic,
91 msgconf, 1);
92 TEST_ASSERT(!err,
93 "AlterConfigs failed: %s",
94 rd_kafka_err2str(err));
95 }
96 }
97
98 rd_kafka_destroy(rk);
99
100 /* Consume messages */
101 test_consume_msgs_easy(NULL, topic, testid, -1, msgcnt, NULL);
102
103 return 0;
104 }
105