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
|
/*
* librdkafka - Apache Kafka C library
*
* Copyright (c) 2016, 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.
*/
#include <iostream>
#include <cstring>
#include <cstdlib>
#include "testcpp.h"
#ifdef _WIN32
#include <direct.h>
#endif
extern "C" {
#include "interceptor_test/interceptor_test.h"
struct ictest ictest;
};
/**
* Verify plugin.library.paths and interceptors
* using interceptor_test/...
*
*/
static void do_test_plugin() {
std::string errstr;
std::string topic = Test::mk_topic_name("0066_plugins", 1);
static const char *config[] = {
"session.timeout.ms",
"6000", /* Before plugin */
"plugin.library.paths",
"interceptor_test/interceptor_test",
"socket.timeout.ms",
"12", /* After plugin */
"interceptor_test.config1",
"one",
"interceptor_test.config2",
"two",
"topic.metadata.refresh.interval.ms",
"1234",
NULL,
};
char cwd[512], *pcwd;
#ifdef _WIN32
pcwd = _getcwd(cwd, sizeof(cwd) - 1);
#else
pcwd = getcwd(cwd, sizeof(cwd) - 1);
#endif
if (pcwd)
Test::Say(tostr() << "running test from cwd " << cwd << "\n");
/* Interceptor back-channel config */
ictest_init(&ictest);
ictest_cnt_init(&ictest.conf_init, 1, 1000);
ictest_cnt_init(&ictest.on_new, 1, 1);
/* Config for intercepted client */
RdKafka::Conf *conf = RdKafka::Conf::create(RdKafka::Conf::CONF_GLOBAL);
for (int i = 0; config[i]; i += 2) {
Test::Say(tostr() << "set(" << config[i] << ", " << config[i + 1] << ")\n");
if (conf->set(config[i], config[i + 1], errstr))
Test::Fail(tostr() << "set(" << config[i] << ") failed: " << errstr);
}
/* Create producer */
RdKafka::Producer *p = RdKafka::Producer::create(conf, errstr);
if (!p)
Test::Fail("Failed to create producer: " + errstr);
if (ictest.on_new.cnt < ictest.on_new.min ||
ictest.on_new.cnt > ictest.on_new.max)
Test::Fail(tostr() << "on_new.cnt " << ictest.on_new.cnt
<< " not within range " << ictest.on_new.min << ".."
<< ictest.on_new.max);
/* Verification */
if (!ictest.config1 || strcmp(ictest.config1, "one"))
Test::Fail(tostr() << "config1 was " << ictest.config1);
if (!ictest.config2 || strcmp(ictest.config2, "two"))
Test::Fail(tostr() << "config2 was " << ictest.config2);
if (!ictest.session_timeout_ms || strcmp(ictest.session_timeout_ms, "6000"))
Test::Fail(tostr() << "session.timeout.ms was "
<< ictest.session_timeout_ms);
if (!ictest.socket_timeout_ms || strcmp(ictest.socket_timeout_ms, "12"))
Test::Fail(tostr() << "socket.timeout.ms was " << ictest.socket_timeout_ms);
delete conf;
delete p;
ictest_free(&ictest);
}
extern "C" {
int main_0066_plugins(int argc, char **argv) {
do_test_plugin();
return 0;
}
}
|