1 /*
2  * librdkafka - Apache Kafka C library
3  *
4  * Copyright (c) 2012-2015, 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 #include "rdkafka.h"
31 
32 
33 /**
34  * Make sure library behaves even if there is no broker connection.
35  */
36 
37 
38 
test_producer_no_connection(void)39 static void test_producer_no_connection (void) {
40 	rd_kafka_t *rk;
41 	rd_kafka_conf_t *conf;
42 	rd_kafka_topic_t *rkt;
43 	int i;
44 	const int partition_cnt = 2;
45 	int msgcnt = 0;
46 	test_timing_t t_destroy;
47 
48 	test_conf_init(&conf, NULL, 20);
49 
50 	test_conf_set(conf, "bootstrap.servers", NULL);
51 
52 	rk = test_create_handle(RD_KAFKA_PRODUCER, conf);
53 	rkt = test_create_topic_object(rk, __FUNCTION__,
54 				       "message.timeout.ms", "5000", NULL);
55 
56 	test_produce_msgs_nowait(rk, rkt, 0, RD_KAFKA_PARTITION_UA, 0, 100,
57 				 NULL, 100, 0, &msgcnt);
58 	for (i = 0 ; i < partition_cnt ; i++)
59 		test_produce_msgs_nowait(rk, rkt, 0, i,
60 					 0, 100, NULL, 100, 0, &msgcnt);
61 
62 	rd_kafka_poll(rk, 1000);
63 
64 	TEST_SAY("%d messages in queue\n", rd_kafka_outq_len(rk));
65 
66 	rd_kafka_topic_destroy(rkt);
67 
68 	TIMING_START(&t_destroy, "rd_kafka_destroy()");
69 	rd_kafka_destroy(rk);
70 	TIMING_STOP(&t_destroy);
71 }
72 
main_0043_no_connection(int argc,char ** argv)73 int main_0043_no_connection (int argc, char **argv) {
74 	test_producer_no_connection();
75 
76         return 0;
77 }
78