summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/librdkafka-2.1.0/tests/0004-conf.c
blob: 51401e17d3fe3e02838f370ef3452fb64115f3d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
/*
 * librdkafka - Apache Kafka C library
 *
 * Copyright (c) 2012-2013, Magnus Edenhill
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/**
 * Tests various config related things
 */


#include "test.h"

/* Typical include path would be <librdkafka/rdkafka.h>, but this program
 * is built from within the librdkafka source tree and thus differs. */
#include "rdkafka.h" /* for Kafka driver */



static void dr_cb(rd_kafka_t *rk,
                  void *payload,
                  size_t len,
                  rd_kafka_resp_err_t err,
                  void *opaque,
                  void *msg_opaque) {
}

static void
error_cb(rd_kafka_t *rk, int err, const char *reason, void *opaque) {
}


static int32_t partitioner(const rd_kafka_topic_t *rkt,
                           const void *keydata,
                           size_t keylen,
                           int32_t partition_cnt,
                           void *rkt_opaque,
                           void *msg_opaque) {
        return 0;
}


static void
conf_verify(int line, const char **arr, size_t cnt, const char **confs) {
        int i, j;


        for (i = 0; confs[i]; i += 2) {
                for (j = 0; j < (int)cnt; j += 2) {
                        if (!strcmp(confs[i], arr[j])) {
                                if (strcmp(confs[i + 1], arr[j + 1]))
                                        TEST_FAIL(
                                            "%i: Property %s mismatch: "
                                            "expected %s != retrieved %s",
                                            line, confs[i], confs[i + 1],
                                            arr[j + 1]);
                        }
                        if (j == (int)cnt)
                                TEST_FAIL(
                                    "%i: "
                                    "Property %s not found in config\n",
                                    line, confs[i]);
                }
        }
}


static void conf_cmp(const char *desc,
                     const char **a,
                     size_t acnt,
                     const char **b,
                     size_t bcnt) {
        int i;

        if (acnt != bcnt)
                TEST_FAIL("%s config compare: count %" PRIusz " != %" PRIusz
                          " mismatch",
                          desc, acnt, bcnt);

        for (i = 0; i < (int)acnt; i += 2) {
                if (strcmp(a[i], b[i]))
                        TEST_FAIL("%s conf mismatch: %s != %s", desc, a[i],
                                  b[i]);
                else if (strcmp(a[i + 1], b[i + 1])) {
                        /* The default_topic_conf will be auto-created
                         * when global->topic fallthru is used, so its
                         * value will not match here. */
                        if (!strcmp(a[i], "default_topic_conf"))
                                continue;
                        TEST_FAIL("%s conf value mismatch for %s: %s != %s",
                                  desc, a[i], a[i + 1], b[i + 1]);
                }
        }
}


/**
 * @brief Not called, just used for config
 */
static int on_new_call_cnt;
static rd_kafka_resp_err_t my_on_new(rd_kafka_t *rk,
                                     const rd_kafka_conf_t *conf,
                                     void *ic_opaque,
                                     char *errstr,
                                     size_t errstr_size) {
        TEST_SAY("%s: on_new() called\n", rd_kafka_name(rk));
        on_new_call_cnt++;
        return RD_KAFKA_RESP_ERR_NO_ERROR;
}



/**
 * @brief When rd_kafka_new() succeeds it takes ownership of the config object,
 *        but when it fails the config object remains in application custody.
 *        These tests makes sure that's the case (preferably run with valgrind)
 */
static void do_test_kafka_new_failures(void) {
        rd_kafka_conf_t *conf;
        rd_kafka_t *rk;
        char errstr[512];

        conf = rd_kafka_conf_new();

        rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
        TEST_ASSERT(rk, "kafka_new() failed: %s", errstr);
        rd_kafka_destroy(rk);

        /* Set an erroneous configuration value that is not checked
         * by conf_set() but by rd_kafka_new() */
        conf = rd_kafka_conf_new();
        if (rd_kafka_conf_set(conf, "partition.assignment.strategy",
                              "range,thiswillfail", errstr,
                              sizeof(errstr)) != RD_KAFKA_CONF_OK)
                TEST_FAIL("%s", errstr);

        rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
        TEST_ASSERT(!rk, "kafka_new() should have failed");

        /* config object should still belong to us,
         * correct the erroneous config and try again. */
        if (rd_kafka_conf_set(conf, "partition.assignment.strategy", NULL,
                              errstr, sizeof(errstr)) != RD_KAFKA_CONF_OK)
                TEST_FAIL("%s", errstr);

        rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
        TEST_ASSERT(rk, "kafka_new() failed: %s", errstr);
        rd_kafka_destroy(rk);

        /* set conflicting properties */
        conf = rd_kafka_conf_new();
        test_conf_set(conf, "acks", "1");
        test_conf_set(conf, "enable.idempotence", "true");
        rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr, sizeof(errstr));
        TEST_ASSERT(!rk, "kafka_new() should have failed");
        rd_kafka_conf_destroy(conf);
        TEST_SAY(_C_GRN "Ok: %s\n", errstr);
}


/**
 * @brief Verify that INVALID properties (such as for Java SSL properties)
 *        work, as well as INTERNAL properties.
 */
static void do_test_special_invalid_conf(void) {
        rd_kafka_conf_t *conf;
        char errstr[512];
        rd_kafka_conf_res_t res;

        conf = rd_kafka_conf_new();

        res = rd_kafka_conf_set(conf, "ssl.truststore.location", "abc", errstr,
                                sizeof(errstr));
        /* Existing apps might not print the error string when conf_set
         * returns UNKNOWN, only on INVALID, so make sure that is
         * what is being returned. */
        TEST_ASSERT(res == RD_KAFKA_CONF_INVALID,
                    "expected ssl.truststore.location to fail with INVALID, "
                    "not %d",
                    res);
        /* Make sure there is a link to documentation */
        TEST_ASSERT(strstr(errstr, "http"),
                    "expected ssl.truststore.location to provide link to "
                    "documentation, not \"%s\"",
                    errstr);
        TEST_SAY(_C_GRN "Ok: %s\n" _C_CLR, errstr);


        res = rd_kafka_conf_set(conf, "sasl.jaas.config", "abc", errstr,
                                sizeof(errstr));
        /* Existing apps might not print the error string when conf_set
         * returns UNKNOWN, only on INVALID, so make sure that is
         * what is being returned. */
        TEST_ASSERT(res == RD_KAFKA_CONF_INVALID,
                    "expected sasl.jaas.config to fail with INVALID, "
                    "not %d",
                    res);
        /* Make sure there is a link to documentation */
        TEST_ASSERT(strstr(errstr, "http"),
                    "expected sasl.jaas.config to provide link to "
                    "documentation, not \"%s\"",
                    errstr);
        TEST_SAY(_C_GRN "Ok: %s\n" _C_CLR, errstr);


        res = rd_kafka_conf_set(conf, "interceptors", "1", errstr,
                                sizeof(errstr));
        TEST_ASSERT(res == RD_KAFKA_CONF_INVALID,
                    "expected interceptors to fail with INVALID, "
                    "not %d",
                    res);
        TEST_SAY(_C_GRN "Ok: %s\n" _C_CLR, errstr);

        rd_kafka_conf_destroy(conf);
}


/**
 * @brief Verify idempotence configuration constraints
 */
static void do_test_idempotence_conf(void) {
        static const struct {
                const char *prop;
                const char *val;
                rd_bool_t topic_conf;
                rd_bool_t exp_rk_fail;
                rd_bool_t exp_rkt_fail;
        } check[] = {{"acks", "1", rd_true, rd_false, rd_true},
                     {"acks", "all", rd_true, rd_false, rd_false},
                     {"queuing.strategy", "lifo", rd_true, rd_false, rd_true},
                     {NULL}};
        int i;

        for (i = 0; check[i].prop; i++) {
                int j;

                for (j = 0; j < 1 + (check[i].topic_conf ? 1 : 0); j++) {
                        /* j = 0: set on global config
                         *  j = 1: set on topic config */
                        rd_kafka_conf_t *conf;
                        rd_kafka_topic_conf_t *tconf = NULL;
                        rd_kafka_t *rk;
                        rd_kafka_topic_t *rkt;
                        char errstr[512];

                        conf = rd_kafka_conf_new();
                        test_conf_set(conf, "enable.idempotence", "true");

                        if (j == 0)
                                test_conf_set(conf, check[i].prop,
                                              check[i].val);


                        rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr,
                                          sizeof(errstr));

                        if (!rk) {
                                /* default topic config (j=0) will fail. */
                                TEST_ASSERT(check[i].exp_rk_fail ||
                                                (j == 0 &&
                                                 check[i].exp_rkt_fail &&
                                                 check[i].topic_conf),
                                            "Did not expect config #%d.%d "
                                            "to fail: %s",
                                            i, j, errstr);

                                rd_kafka_conf_destroy(conf);
                                continue;

                        } else {
                                TEST_ASSERT(!check[i].exp_rk_fail,
                                            "Expect config #%d.%d to fail", i,
                                            j);
                        }

                        if (j == 1) {
                                tconf = rd_kafka_topic_conf_new();
                                test_topic_conf_set(tconf, check[i].prop,
                                                    check[i].val);
                        }

                        rkt = rd_kafka_topic_new(rk, "mytopic", tconf);
                        if (!rkt) {
                                TEST_ASSERT(
                                    check[i].exp_rkt_fail,
                                    "Did not expect topic config "
                                    "#%d.%d to fail: %s",
                                    i, j,
                                    rd_kafka_err2str(rd_kafka_last_error()));


                        } else {
                                TEST_ASSERT(!check[i].exp_rkt_fail,
                                            "Expect topic config "
                                            "#%d.%d to fail",
                                            i, j);
                                rd_kafka_topic_destroy(rkt);
                        }

                        rd_kafka_destroy(rk);
                }
        }
}


/**
 * @brief Verify that configuration properties can be extract
 *        from the instance config object.
 */
static void do_test_instance_conf(void) {
        rd_kafka_conf_t *conf;
        const rd_kafka_conf_t *iconf;
        rd_kafka_t *rk;
        rd_kafka_conf_res_t res;
        static const char *props[] = {
            "linger.ms",          "123",   "group.id", "test1",
            "enable.auto.commit", "false", NULL,
        };
        const char **p;

        conf = rd_kafka_conf_new();

        for (p = props; *p; p += 2) {
                res = rd_kafka_conf_set(conf, *p, *(p + 1), NULL, 0);
                TEST_ASSERT(res == RD_KAFKA_CONF_OK, "failed to set %s", *p);
        }

        rk = rd_kafka_new(RD_KAFKA_CONSUMER, conf, NULL, 0);
        TEST_ASSERT(rk, "failed to create consumer");

        iconf = rd_kafka_conf(rk);
        TEST_ASSERT(conf, "failed to get instance config");

        for (p = props; *p; p += 2) {
                char dest[512];
                size_t destsz = sizeof(dest);

                res = rd_kafka_conf_get(iconf, *p, dest, &destsz);
                TEST_ASSERT(res == RD_KAFKA_CONF_OK,
                            "failed to get %s: result %d", *p, res);

                TEST_SAY("Instance config %s=%s\n", *p, dest);
                TEST_ASSERT(!strcmp(*(p + 1), dest), "Expected %s=%s, not %s",
                            *p, *(p + 1), dest);
        }

        rd_kafka_destroy(rk);
}


/**
 * @brief Verify that setting and retrieving the default topic config works.
 */
static void do_test_default_topic_conf(void) {
        rd_kafka_conf_t *conf;
        rd_kafka_topic_conf_t *tconf;
        const char *val, *exp_val;

        SUB_TEST_QUICK();

        conf = rd_kafka_conf_new();

        /* Set topic-level property, this will create the default topic config*/
        exp_val = "1234";
        test_conf_set(conf, "message.timeout.ms", exp_val);

        /* Get the default topic config */
        tconf = rd_kafka_conf_get_default_topic_conf(conf);
        TEST_ASSERT(tconf != NULL, "");

        /* Get value from global config by fall-thru */
        val = test_conf_get(conf, "message.timeout.ms");
        TEST_ASSERT(val && !strcmp(val, exp_val),
                    "Expected (conf) message.timeout.ms=%s, not %s", exp_val,
                    val ? val : "(NULL)");

        /* Get value from default topic config */
        val = test_topic_conf_get(tconf, "message.timeout.ms");
        TEST_ASSERT(val && !strcmp(val, exp_val),
                    "Expected (topic conf) message.timeout.ms=%s, not %s",
                    exp_val, val ? val : "(NULL)");

        /* Now change the value, should be reflected in both. */
        exp_val = "4444";
        test_topic_conf_set(tconf, "message.timeout.ms", exp_val);

        /* Get value from global config by fall-thru */
        val = test_conf_get(conf, "message.timeout.ms");
        TEST_ASSERT(val && !strcmp(val, exp_val),
                    "Expected (conf) message.timeout.ms=%s, not %s", exp_val,
                    val ? val : "(NULL)");

        /* Get value from default topic config */
        val = test_topic_conf_get(tconf, "message.timeout.ms");
        TEST_ASSERT(val && !strcmp(val, exp_val),
                    "Expected (topic conf) message.timeout.ms=%s, not %s",
                    exp_val, val ? val : "(NULL)");


        rd_kafka_conf_destroy(conf);

        SUB_TEST_PASS();
}


/**
 * @brief Verify behaviour of checking that message.timeout.ms fits within
 *        configured linger.ms. By larry-cdn77.
 */
static void do_message_timeout_linger_checks(void) {
        rd_kafka_conf_t *conf;
        rd_kafka_topic_conf_t *tconf;
        rd_kafka_t *rk;
        char errstr[512];
        int i;
        const char values[7][3][40] = {
            {"-", "-", "default and L and M"},
            {"100", "-", "set L such that L<M"},
            {"-", "300000", "set M such that L<M"},
            {"100", "300000", "set L and M such that L<M"},
            {"500000", "-", "!set L such that L>=M"},
            {"-", "10", "set M such that L>=M"},
            {"500000", "10", "!set L and M such that L>=M"}};

        SUB_TEST_QUICK();

        for (i = 0; i < 7; i++) {
                const char *linger     = values[i][0];
                const char *msgtimeout = values[i][1];
                const char *desc       = values[i][2];
                rd_bool_t expect_fail  = *desc == '!';

                if (expect_fail)
                        desc++; /* Push past the '!' */

                conf  = rd_kafka_conf_new();
                tconf = rd_kafka_topic_conf_new();

                if (*linger != '-')
                        test_conf_set(conf, "linger.ms", linger);

                if (*msgtimeout != '-')
                        test_topic_conf_set(tconf, "message.timeout.ms",
                                            msgtimeout);

                rd_kafka_conf_set_default_topic_conf(conf, tconf);

                rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr,
                                  sizeof(errstr));

                if (!rk)
                        TEST_SAY("#%d \"%s\": rd_kafka_new() failed: %s\n", i,
                                 desc, errstr);
                else
                        TEST_SAY("#%d \"%s\": rd_kafka_new() succeeded\n", i,
                                 desc);

                if (!expect_fail) {
                        TEST_ASSERT(rk != NULL,
                                    "Expected success: "
                                    "message timeout linger: %s: %s",
                                    desc, errstr);

                        rd_kafka_destroy(rk);

                } else {
                        TEST_ASSERT(rk == NULL,
                                    "Expected failure: "
                                    "message timeout linger: %s",
                                    desc);

                        rd_kafka_conf_destroy(conf);
                }
        }

        SUB_TEST_PASS();
}


int main_0004_conf(int argc, char **argv) {
        rd_kafka_t *rk;
        rd_kafka_topic_t *rkt;
        rd_kafka_conf_t *ignore_conf, *conf, *conf2;
        rd_kafka_topic_conf_t *ignore_topic_conf, *tconf, *tconf2;
        char errstr[512];
        rd_kafka_resp_err_t err;
        const char **arr_orig, **arr_dup;
        size_t cnt_orig, cnt_dup;
        int i;
        const char *topic;
        static const char *gconfs[] = {
                "message.max.bytes",
                "12345", /* int property */
                "client.id",
                "my id", /* string property */
                "debug",
                "topic,metadata,interceptor", /* S2F property */
                "topic.blacklist",
                "__.*", /* #778 */
                "auto.offset.reset",
                "earliest", /* Global->Topic fallthru */
#if WITH_ZLIB
                "compression.codec",
                "gzip", /* S2I property */
#endif
#if defined(_WIN32)
                "ssl.ca.certificate.stores",
                "Intermediate ,, Root ,",
#endif
                NULL
        };
        static const char *tconfs[] = {"request.required.acks",
                                       "-1", /* int */
                                       "auto.commit.enable",
                                       "false", /* bool */
                                       "auto.offset.reset",
                                       "error", /* S2I */
                                       "offset.store.path",
                                       "my/path", /* string */
                                       NULL};

        test_conf_init(&ignore_conf, &ignore_topic_conf, 10);
        rd_kafka_conf_destroy(ignore_conf);
        rd_kafka_topic_conf_destroy(ignore_topic_conf);

        topic = test_mk_topic_name("0004", 0);

        /* Set up a global config object */
        conf = rd_kafka_conf_new();

        for (i = 0; gconfs[i]; i += 2) {
                if (rd_kafka_conf_set(conf, gconfs[i], gconfs[i + 1], errstr,
                                      sizeof(errstr)) != RD_KAFKA_CONF_OK)
                        TEST_FAIL("%s\n", errstr);
        }

        rd_kafka_conf_set_dr_cb(conf, dr_cb);
        rd_kafka_conf_set_error_cb(conf, error_cb);
        /* interceptor configs are not exposed as strings or in dumps
         * so the dump verification step will not cover them, but valgrind
         * will help track down memory leaks/use-after-free etc. */
        err = rd_kafka_conf_interceptor_add_on_new(conf, "testic", my_on_new,
                                                   NULL);
        TEST_ASSERT(!err, "add_on_new() failed: %s", rd_kafka_err2str(err));

        /* Set up a topic config object */
        tconf = rd_kafka_topic_conf_new();

        rd_kafka_topic_conf_set_partitioner_cb(tconf, partitioner);
        rd_kafka_topic_conf_set_opaque(tconf, (void *)0xbeef);

        for (i = 0; tconfs[i]; i += 2) {
                if (rd_kafka_topic_conf_set(tconf, tconfs[i], tconfs[i + 1],
                                            errstr,
                                            sizeof(errstr)) != RD_KAFKA_CONF_OK)
                        TEST_FAIL("%s\n", errstr);
        }


        /* Verify global config */
        arr_orig = rd_kafka_conf_dump(conf, &cnt_orig);
        conf_verify(__LINE__, arr_orig, cnt_orig, gconfs);

        /* Verify copied global config */
        conf2   = rd_kafka_conf_dup(conf);
        arr_dup = rd_kafka_conf_dump(conf2, &cnt_dup);
        conf_verify(__LINE__, arr_dup, cnt_dup, gconfs);
        conf_cmp("global", arr_orig, cnt_orig, arr_dup, cnt_dup);
        rd_kafka_conf_dump_free(arr_orig, cnt_orig);
        rd_kafka_conf_dump_free(arr_dup, cnt_dup);

        /* Verify topic config */
        arr_orig = rd_kafka_topic_conf_dump(tconf, &cnt_orig);
        conf_verify(__LINE__, arr_orig, cnt_orig, tconfs);

        /* Verify copied topic config */
        tconf2  = rd_kafka_topic_conf_dup(tconf);
        arr_dup = rd_kafka_topic_conf_dump(tconf2, &cnt_dup);
        conf_verify(__LINE__, arr_dup, cnt_dup, tconfs);
        conf_cmp("topic", arr_orig, cnt_orig, arr_dup, cnt_dup);
        rd_kafka_conf_dump_free(arr_orig, cnt_orig);
        rd_kafka_conf_dump_free(arr_dup, cnt_dup);


        /*
         * Create kafka instances using original and copied confs
         */

        /* original */
        TEST_ASSERT(on_new_call_cnt == 0, "expected 0 on_new call, not %d",
                    on_new_call_cnt);
        on_new_call_cnt = 0;
        rk              = test_create_handle(RD_KAFKA_PRODUCER, conf);
        TEST_ASSERT(on_new_call_cnt == 1, "expected 1 on_new call, not %d",
                    on_new_call_cnt);

        rkt = rd_kafka_topic_new(rk, topic, tconf);
        if (!rkt)
                TEST_FAIL("Failed to create topic: %s\n", rd_strerror(errno));

        rd_kafka_topic_destroy(rkt);
        rd_kafka_destroy(rk);

        /* copied */
        on_new_call_cnt = 0; /* interceptors are not copied. */
        rk              = test_create_handle(RD_KAFKA_PRODUCER, conf2);
        TEST_ASSERT(on_new_call_cnt == 0, "expected 0 on_new call, not %d",
                    on_new_call_cnt);

        rkt = rd_kafka_topic_new(rk, topic, tconf2);
        if (!rkt)
                TEST_FAIL("Failed to create topic: %s\n", rd_strerror(errno));
        rd_kafka_topic_destroy(rkt);
        rd_kafka_destroy(rk);


        /* Incremental S2F property.
         * NOTE: The order of fields returned in get() is hardcoded here. */
        {
                static const char *s2fs[] = {"generic,broker,queue,cgrp",
                                             "generic,broker,queue,cgrp",

                                             "-broker,+queue,topic",
                                             "generic,topic,queue,cgrp",

                                             "-all,security,-fetch,+metadata",
                                             "metadata,security",

                                             NULL};

                TEST_SAY("Incremental S2F tests\n");
                conf = rd_kafka_conf_new();

                for (i = 0; s2fs[i]; i += 2) {
                        const char *val;

                        TEST_SAY("  Set: %s\n", s2fs[i]);
                        test_conf_set(conf, "debug", s2fs[i]);
                        val = test_conf_get(conf, "debug");
                        TEST_SAY("  Now: %s\n", val);

                        if (strcmp(val, s2fs[i + 1]))
                                TEST_FAIL_LATER(
                                    "\n"
                                    "Expected: %s\n"
                                    "     Got: %s",
                                    s2fs[i + 1], val);
                }
                rd_kafka_conf_destroy(conf);
        }

        {
                rd_kafka_conf_res_t res;

                TEST_SAY("Error reporting for S2F properties\n");
                conf = rd_kafka_conf_new();

                res =
                    rd_kafka_conf_set(conf, "debug", "cgrp,invalid-value,topic",
                                      errstr, sizeof(errstr));

                TEST_ASSERT(
                    res == RD_KAFKA_CONF_INVALID,
                    "expected 'debug=invalid-value' to fail with INVALID, "
                    "not %d",
                    res);
                TEST_ASSERT(strstr(errstr, "invalid-value"),
                            "expected invalid value to be mentioned in error, "
                            "not \"%s\"",
                            errstr);
                TEST_ASSERT(!strstr(errstr, "cgrp") && !strstr(errstr, "topic"),
                            "expected only invalid value to be mentioned, "
                            "not \"%s\"",
                            errstr);
                TEST_SAY(_C_GRN "Ok: %s\n" _C_CLR, errstr);

                rd_kafka_conf_destroy(conf);
        }

#if WITH_SSL
        {
                TEST_SAY(
                    "Verifying that ssl.ca.location is not "
                    "overwritten (#3566)\n");

                conf = rd_kafka_conf_new();

                test_conf_set(conf, "security.protocol", "SSL");
                test_conf_set(conf, "ssl.ca.location", "/?/does/!/not/exist!");

                rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr,
                                  sizeof(errstr));
                TEST_ASSERT(!rk,
                            "Expected rd_kafka_new() to fail with "
                            "invalid ssl.ca.location");
                TEST_SAY("rd_kafka_new() failed as expected: %s\n", errstr);
                rd_kafka_conf_destroy(conf);
        }

#ifdef _WIN32
        {
                FILE *fp;
                TEST_SAY(
                    "Verifying that OpenSSL_AppLink "
                    "is not needed (#3554)\n");

                /* Create dummy file so the file open works,
                 * but parsing fails. */
                fp = fopen("_tmp_0004", "w");
                TEST_ASSERT(fp != NULL, "Failed to create dummy file: %s",
                            rd_strerror(errno));
                if (fwrite("?", 1, 1, fp) != 1)
                        TEST_FAIL("Failed to write to dummy file _tmp_0004: %s",
                                  rd_strerror(errno));
                fclose(fp);

                conf = rd_kafka_conf_new();

                test_conf_set(conf, "security.protocol", "SSL");
                test_conf_set(conf, "ssl.keystore.location", "_tmp_0004");
                test_conf_set(conf, "ssl.keystore.password", "x");

                /* Prior to the fix OpenSSL will assert with a message like
                 * this: "OPENSSL_Uplink(00007FF9C0229D30,08): no
                 * OPENSSL_Applink"
                 * and the program will exit with error code 1. */
                rk = rd_kafka_new(RD_KAFKA_PRODUCER, conf, errstr,
                                  sizeof(errstr));
                _unlink("tmp_0004");

                TEST_ASSERT(!rk,
                            "Expected rd_kafka_new() to fail due to "
                            "dummy ssl.keystore.location");
                TEST_ASSERT(strstr(errstr, "ssl.keystore.location") != NULL,
                            "Expected rd_kafka_new() to fail with "
                            "dummy ssl.keystore.location, not: %s",
                            errstr);

                TEST_SAY("rd_kafka_new() failed as expected: %s\n", errstr);
        }
#endif /* _WIN32 */

#endif /* WITH_SSL */

        /* Canonical int values, aliases, s2i-verified strings, doubles */
        {
                static const struct {
                        const char *prop;
                        const char *val;
                        const char *exp;
                        int is_global;
                } props[] = {
                        {"request.required.acks", "0", "0"},
                        {"request.required.acks", "-1", "-1"},
                        {"request.required.acks", "1", "1"},
                        {"acks", "3", "3"}, /* alias test */
                        {"request.required.acks", "393", "393"},
                        {"request.required.acks", "bad", NULL},
                        {"request.required.acks", "all", "-1"},
                        {"request.required.acks", "all", "-1", 1 /*fallthru*/},
                        {"acks", "0", "0"}, /* alias test */
#if WITH_SASL
                        {"sasl.mechanisms", "GSSAPI", "GSSAPI", 1},
                        {"sasl.mechanisms", "PLAIN", "PLAIN", 1},
                        {"sasl.mechanisms", "GSSAPI,PLAIN", NULL, 1},
                        {"sasl.mechanisms", "", NULL, 1},
#endif
                        {"linger.ms", "12555.3", "12555.3", 1},
                        {"linger.ms", "1500.000", "1500", 1},
                        {"linger.ms", "0.0001", "0.0001", 1},
                        {NULL}
                };

                TEST_SAY("Canonical tests\n");
                tconf = rd_kafka_topic_conf_new();
                conf  = rd_kafka_conf_new();

                for (i = 0; props[i].prop; i++) {
                        char dest[64];
                        size_t destsz;
                        rd_kafka_conf_res_t res;

                        TEST_SAY("  Set: %s=%s expect %s (%s)\n", props[i].prop,
                                 props[i].val, props[i].exp,
                                 props[i].is_global ? "global" : "topic");


                        /* Set value */
                        if (props[i].is_global)
                                res = rd_kafka_conf_set(conf, props[i].prop,
                                                        props[i].val, errstr,
                                                        sizeof(errstr));
                        else
                                res = rd_kafka_topic_conf_set(
                                    tconf, props[i].prop, props[i].val, errstr,
                                    sizeof(errstr));
                        if ((res == RD_KAFKA_CONF_OK ? 1 : 0) !=
                            (props[i].exp ? 1 : 0))
                                TEST_FAIL("Expected %s, got %s",
                                          props[i].exp ? "success" : "failure",
                                          (res == RD_KAFKA_CONF_OK
                                               ? "OK"
                                               : (res == RD_KAFKA_CONF_INVALID
                                                      ? "INVALID"
                                                      : "UNKNOWN")));

                        if (!props[i].exp)
                                continue;

                        /* Get value and compare to expected result */
                        destsz = sizeof(dest);
                        if (props[i].is_global)
                                res = rd_kafka_conf_get(conf, props[i].prop,
                                                        dest, &destsz);
                        else
                                res = rd_kafka_topic_conf_get(
                                    tconf, props[i].prop, dest, &destsz);
                        TEST_ASSERT(res == RD_KAFKA_CONF_OK,
                                    ".._conf_get(%s) returned %d",
                                    props[i].prop, res);

                        TEST_ASSERT(!strcmp(props[i].exp, dest),
                                    "Expected \"%s\", got \"%s\"", props[i].exp,
                                    dest);
                }
                rd_kafka_topic_conf_destroy(tconf);
                rd_kafka_conf_destroy(conf);
        }

        do_test_kafka_new_failures();

        do_test_special_invalid_conf();

        do_test_idempotence_conf();

        do_test_instance_conf();

        do_test_default_topic_conf();

        do_message_timeout_linger_checks();

        return 0;
}