![]() |
fuse_kafka
|
00001 00002 // LCOV_EXCL_START 00003 #include <string.h> 00004 #include <stdlib.h> 00005 #include <limits.h> 00006 static struct fuse_context* test_fuse_get_context() 00007 { 00008 static struct fuse_context ctx = { 0 }; 00009 return &ctx; 00010 } 00011 typedef struct { } rd_kafka_t; 00012 typedef struct { } rd_kafka_topic_t; 00013 typedef struct { } rd_kafka_conf_t; 00014 typedef struct { } rd_kafka_topic_conf_t; 00015 typedef int rd_kafka_conf_res_t; 00016 typedef int rd_kafka_type_t; 00017 #define RD_KAFKA_CONF_OK 1 00018 #define RD_KAFKA_PRODUCER 42 00019 #define RD_KAFKA_PARTITION_UA 42 00020 #define RD_KAFKA_MSG_F_COPY 42 00021 rd_kafka_conf_t *rd_kafka_conf_new () { return 0; } 00022 rd_kafka_topic_conf_t *rd_kafka_topic_conf_new () { return 0; } 00023 void rd_kafka_conf_set_dr_cb (rd_kafka_conf_t *conf, void *f) { } 00024 typedef struct 00025 { 00026 int setup; 00027 rd_kafka_conf_res_t rd_kafka_conf_set_returns; 00028 char* rd_kafka_conf_set_fails_for; 00029 int rd_kafka_new_returns_NULL; 00030 int rd_kafka_topic_new_returns_NULL; 00031 int rd_kafka_brokers_add_returns; 00032 int rd_kafka_produce_returns; 00033 int zoo_get_children_returns; 00034 int asprintf_sets_NULL; 00035 } test_config; 00036 static test_config* test_with() 00037 { 00038 static test_config conf; 00039 if(!conf.setup) 00040 { 00041 conf.rd_kafka_brokers_add_returns = 1; 00042 conf.zoo_get_children_returns = 1; 00043 conf.setup = 1; 00044 } 00045 return &conf; 00046 } 00047 #define asprintf(x, ...) (test_with()->asprintf_sets_NULL? (*x = NULL) == NULL : asprintf(x, __VA_ARGS__)) 00048 rd_kafka_conf_res_t rd_kafka_conf_set (rd_kafka_conf_t *conf, 00049 const char *name, 00050 const char *value, 00051 char *errstr, size_t errstr_size) 00052 { 00053 if(test_with()->rd_kafka_conf_set_fails_for == NULL) 00054 return test_with()->rd_kafka_conf_set_returns; 00055 else 00056 return strcmp(test_with()->rd_kafka_conf_set_fails_for, 00057 name) == 0?0:RD_KAFKA_CONF_OK; 00058 } 00059 rd_kafka_t *rd_kafka_new (rd_kafka_type_t type, rd_kafka_conf_t *conf, 00060 char *errstr, size_t errstr_size) 00061 { 00062 static rd_kafka_t rk; 00063 return test_with()->rd_kafka_new_returns_NULL ? NULL:&rk; 00064 } 00065 void rd_kafka_destroy(rd_kafka_t* to_destroy) 00066 { 00067 } 00068 void rd_kafka_wait_destroyed(int timeout_ms) 00069 { 00070 } 00071 void rd_kafka_topic_destroy (rd_kafka_topic_t *rkt) 00072 { 00073 } 00074 void rd_kafka_set_logger (rd_kafka_t *rk, void *f) { } 00075 void rd_kafka_set_log_level (rd_kafka_t *rk, int level) { } 00076 int rd_kafka_brokers_add (rd_kafka_t *rk, const char *brokerlist) 00077 { return test_with()->rd_kafka_brokers_add_returns; } 00078 rd_kafka_topic_t *rd_kafka_topic_new (rd_kafka_t *rk, const char *topic, 00079 rd_kafka_topic_conf_t *conf) 00080 { 00081 static rd_kafka_topic_t t; 00082 return test_with()->rd_kafka_topic_new_returns_NULL ? NULL:&t; 00083 } 00084 int rd_kafka_produce (rd_kafka_topic_t *rkt, int32_t partitition, 00085 int msgflags, 00086 void *payload, size_t len, 00087 const void *key, size_t keylen, 00088 void *msg_opaque) 00089 { return test_with()->rd_kafka_produce_returns; } 00090 int rd_kafka_poll (rd_kafka_t *rk, int timeout_ms) 00091 { 00092 return 0; 00093 } 00094 typedef struct _zhandle_t { 00095 int i; 00096 } zhandle_t; 00097 struct String_vector { 00098 int32_t count; 00099 char** data; 00100 }; 00101 #define ZOK 1 00102 #define ZOO_CHILD_EVENT 4 00103 #define ZOO_LOG_LEVEL_ERROR 1 00104 void zoo_set_debug_level(int level) 00105 { 00106 } 00107 typedef void (*watcher_fn)(zhandle_t *zh, int type, 00108 int state, const char *path,void *watcherCtx); 00109 zhandle_t *zookeeper_init(const char *host, watcher_fn fn, 00110 int recv_timeout, void *clientid, void *context, int flags) 00111 { 00112 if(host == NULL) return NULL; 00113 zhandle_t* zh = (zhandle_t*) malloc(sizeof(zhandle_t)); 00114 fn(zh, ZOO_CHILD_EVENT, 0, "/brokers/ids", context); 00115 return zh; 00116 } 00117 int zookeeper_close(zhandle_t *zh) 00118 { 00119 return 0; 00120 } 00121 int zoo_get_children(zhandle_t *zh, const char *path, int watch, 00122 struct String_vector *strings) 00123 { 00124 strings->count = 2; 00125 char* i = (char*) malloc(2 * sizeof(char*)); 00126 i[0] = '1'; 00127 i[1] = 0; 00128 strings->data = (char**) malloc(sizeof(char**)); 00129 strings->data[0] = i; 00130 strings->data[1] = i; 00131 return test_with()->zoo_get_children_returns; 00132 } 00133 int zoo_get(zhandle_t *zh, const char *path, int watch, char *buffer, 00134 int* buffer_len, void *stat) 00135 { 00136 strcpy(buffer, "{\"host\": \"a\", \"port\": 2181}"); 00137 return 1; 00138 } 00139 int deallocate_String_vector(struct String_vector *v) 00140 { 00141 free(v->data[0]); 00142 free(v->data); 00143 return 1; 00144 } 00145 // LCOV_EXCL_STOP