Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
79bc5797
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
79bc5797
编写于
4月 13, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test: fix tmq test case
上级
1a13affb
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
110 addition
and
118 deletion
+110
-118
tests/test/c/tmqSim.c
tests/test/c/tmqSim.c
+110
-118
未找到文件。
tests/test/c/tmqSim.c
浏览文件 @
79bc5797
...
@@ -13,17 +13,15 @@
...
@@ -13,17 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
// clang-format off
#include <assert.h>
#include <assert.h>
#include <dirent.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <unistd.h>
#include <stdlib.h>
#include <dirent.h>
#include "taos.h"
#include "taos.h"
#include "taoserror.h"
#include "taoserror.h"
...
@@ -56,8 +54,8 @@ typedef struct {
...
@@ -56,8 +54,8 @@ typedef struct {
static
SConfInfo
g_stConfInfo
;
static
SConfInfo
g_stConfInfo
;
//char* g_pRowValue = NULL;
//
char* g_pRowValue = NULL;
//TdFilePtr g_fp = NULL;
//
TdFilePtr g_fp = NULL;
static
void
printHelp
()
{
static
void
printHelp
()
{
char
indent
[
10
]
=
" "
;
char
indent
[
10
]
=
" "
;
...
@@ -80,8 +78,7 @@ static void printHelp() {
...
@@ -80,8 +78,7 @@ static void printHelp() {
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
void
parseArgument
(
int32_t
argc
,
char
*
argv
[])
{
void
parseArgument
(
int32_t
argc
,
char
*
argv
[])
{
memset
(
&
g_stConfInfo
,
0
,
sizeof
(
SConfInfo
));
memset
(
&
g_stConfInfo
,
0
,
sizeof
(
SConfInfo
));
g_stConfInfo
.
showMsgFlag
=
0
;
g_stConfInfo
.
showMsgFlag
=
0
;
g_stConfInfo
.
consumeDelay
=
8000
;
g_stConfInfo
.
consumeDelay
=
8000
;
...
@@ -120,60 +117,58 @@ void parseArgument(int32_t argc, char *argv[]) {
...
@@ -120,60 +117,58 @@ void parseArgument(int32_t argc, char *argv[]) {
#endif
#endif
}
}
void
splitStr
(
char
**
arr
,
char
*
str
,
const
char
*
del
)
{
void
splitStr
(
char
**
arr
,
char
*
str
,
const
char
*
del
)
{
char
*
s
=
strtok
(
str
,
del
);
char
*
s
=
strtok
(
str
,
del
);
while
(
s
!=
NULL
)
{
while
(
s
!=
NULL
)
{
*
arr
++
=
s
;
*
arr
++
=
s
;
s
=
strtok
(
NULL
,
del
);
s
=
strtok
(
NULL
,
del
);
}
}
}
}
void
ltrim
(
char
*
str
)
void
ltrim
(
char
*
str
)
{
{
if
(
str
==
NULL
||
*
str
==
'\0'
)
{
if
(
str
==
NULL
||
*
str
==
'\0'
)
{
return
;
return
;
}
}
int
len
=
0
;
int
len
=
0
;
char
*
p
=
str
;
char
*
p
=
str
;
while
(
*
p
!=
'\0'
&&
isspace
(
*
p
))
while
(
*
p
!=
'\0'
&&
isspace
(
*
p
))
{
{
++
p
;
++
p
;
++
len
;
++
len
;
}
}
memmove
(
str
,
p
,
strlen
(
str
)
-
len
+
1
);
memmove
(
str
,
p
,
strlen
(
str
)
-
len
+
1
);
//return str;
// return str;
}
}
void
parseInputString
()
{
void
parseInputString
()
{
//printf("topicString: %s\n", g_stConfInfo.topicString);
//
printf("topicString: %s\n", g_stConfInfo.topicString);
//
printf("keyString: %s\n\n", g_stConfInfo.keyString);
//
printf("keyString: %s\n\n", g_stConfInfo.keyString);
char
*
token
;
char
*
token
;
const
char
delim
[
2
]
=
","
;
const
char
delim
[
2
]
=
","
;
const
char
ch
=
':'
;
const
char
ch
=
':'
;
token
=
strtok
(
g_stConfInfo
.
topicString
,
delim
);
token
=
strtok
(
g_stConfInfo
.
topicString
,
delim
);
while
(
token
!=
NULL
)
{
while
(
token
!=
NULL
)
{
//printf("%s\n", token );
//
printf("%s\n", token );
strcpy
(
g_stConfInfo
.
topics
[
g_stConfInfo
.
numOfTopic
],
token
);
strcpy
(
g_stConfInfo
.
topics
[
g_stConfInfo
.
numOfTopic
],
token
);
ltrim
(
g_stConfInfo
.
topics
[
g_stConfInfo
.
numOfTopic
]);
ltrim
(
g_stConfInfo
.
topics
[
g_stConfInfo
.
numOfTopic
]);
//
printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]);
//
printf("%s\n", g_stConfInfo.topics[g_stConfInfo.numOfTopic]);
g_stConfInfo
.
numOfTopic
++
;
g_stConfInfo
.
numOfTopic
++
;
token
=
strtok
(
NULL
,
delim
);
token
=
strtok
(
NULL
,
delim
);
}
}
token
=
strtok
(
g_stConfInfo
.
keyString
,
delim
);
token
=
strtok
(
g_stConfInfo
.
keyString
,
delim
);
while
(
token
!=
NULL
)
{
while
(
token
!=
NULL
)
{
//printf("%s\n", token );
//
printf("%s\n", token );
{
{
char
*
pstr
=
token
;
char
*
pstr
=
token
;
ltrim
(
pstr
);
ltrim
(
pstr
);
char
*
ret
=
strchr
(
pstr
,
ch
);
char
*
ret
=
strchr
(
pstr
,
ch
);
memcpy
(
g_stConfInfo
.
key
[
g_stConfInfo
.
numOfKey
],
pstr
,
ret
-
pstr
);
memcpy
(
g_stConfInfo
.
key
[
g_stConfInfo
.
numOfKey
],
pstr
,
ret
-
pstr
);
strcpy
(
g_stConfInfo
.
value
[
g_stConfInfo
.
numOfKey
],
ret
+
1
);
strcpy
(
g_stConfInfo
.
value
[
g_stConfInfo
.
numOfKey
],
ret
+
1
);
//printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey], g_stConfInfo.value[g_stConfInfo.numOfKey]);
// printf("key: %s, value: %s\n", g_stConfInfo.key[g_stConfInfo.numOfKey],
// g_stConfInfo.value[g_stConfInfo.numOfKey]);
g_stConfInfo
.
numOfKey
++
;
g_stConfInfo
.
numOfKey
++
;
}
}
...
@@ -181,22 +176,20 @@ void parseInputString() {
...
@@ -181,22 +176,20 @@ void parseInputString() {
}
}
}
}
static
int
running
=
1
;
static
int
running
=
1
;
/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/
/*static void msg_process(tmq_message_t* message) { tmqShowMsg(message); }*/
int
queryDB
(
TAOS
*
taos
,
char
*
command
)
{
int
queryDB
(
TAOS
*
taos
,
char
*
command
)
{
TAOS_RES
*
pRes
=
taos_query
(
taos
,
command
);
TAOS_RES
*
pRes
=
taos_query
(
taos
,
command
);
int
code
=
taos_errno
(
pRes
);
int
code
=
taos_errno
(
pRes
);
//
if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) {
//
if ((code != 0) && (code != TSDB_CODE_RPC_AUTH_REQUIRED)) {
if
(
code
!=
0
)
{
if
(
code
!=
0
)
{
pError
(
"failed to reason:%s, sql: %s"
,
tstrerror
(
code
),
command
);
pError
(
"failed to reason:%s, sql: %s"
,
tstrerror
(
code
),
command
);
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
return
-
1
;
return
-
1
;
}
}
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
return
0
;
return
0
;
}
}
tmq_t
*
build_consumer
()
{
tmq_t
*
build_consumer
()
{
...
@@ -215,7 +208,7 @@ tmq_t* build_consumer() {
...
@@ -215,7 +208,7 @@ tmq_t* build_consumer() {
taos_free_result
(
pRes
);
taos_free_result
(
pRes
);
tmq_conf_t
*
conf
=
tmq_conf_new
();
tmq_conf_t
*
conf
=
tmq_conf_new
();
//tmq_conf_set(conf, "group.id", "tg2");
//
tmq_conf_set(conf, "group.id", "tg2");
for
(
int32_t
i
=
0
;
i
<
g_stConfInfo
.
numOfKey
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
g_stConfInfo
.
numOfKey
;
i
++
)
{
tmq_conf_set
(
conf
,
g_stConfInfo
.
key
[
i
],
g_stConfInfo
.
value
[
i
]);
tmq_conf_set
(
conf
,
g_stConfInfo
.
key
[
i
],
g_stConfInfo
.
value
[
i
]);
}
}
...
@@ -225,7 +218,7 @@ tmq_t* build_consumer() {
...
@@ -225,7 +218,7 @@ tmq_t* build_consumer() {
tmq_list_t
*
build_topic_list
()
{
tmq_list_t
*
build_topic_list
()
{
tmq_list_t
*
topic_list
=
tmq_list_new
();
tmq_list_t
*
topic_list
=
tmq_list_new
();
//tmq_list_append(topic_list, "test_stb_topic_1");
//
tmq_list_append(topic_list, "test_stb_topic_1");
for
(
int32_t
i
=
0
;
i
<
g_stConfInfo
.
numOfTopic
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
g_stConfInfo
.
numOfTopic
;
i
++
)
{
tmq_list_append
(
topic_list
,
g_stConfInfo
.
topics
[
i
]);
tmq_list_append
(
topic_list
,
g_stConfInfo
.
topics
[
i
]);
}
}
...
@@ -243,12 +236,12 @@ void loop_consume(tmq_t* tmq) {
...
@@ -243,12 +236,12 @@ void loop_consume(tmq_t* tmq) {
if
(
tmqMsg
)
{
if
(
tmqMsg
)
{
totalMsgs
++
;
totalMsgs
++
;
#if 0
#if 0
TAOS_ROW row;
TAOS_ROW row;
while (NULL != (row = tmq_get_row(tmqMsg))) {
while (NULL != (row = tmq_get_row(tmqMsg))) {
totalRows++;
totalRows++;
}
}
#endif
#endif
/*skipLogNum += tmqGetSkipLogNum(tmqMsg);*/
/*skipLogNum += tmqGetSkipLogNum(tmqMsg);*/
if
(
0
!=
g_stConfInfo
.
showMsgFlag
)
{
if
(
0
!=
g_stConfInfo
.
showMsgFlag
)
{
...
@@ -269,7 +262,6 @@ void loop_consume(tmq_t* tmq) {
...
@@ -269,7 +262,6 @@ void loop_consume(tmq_t* tmq) {
printf
(
"{consume success: %d, %d}"
,
totalMsgs
,
totalRows
);
printf
(
"{consume success: %d, %d}"
,
totalMsgs
,
totalRows
);
}
}
void
parallel_consume
(
tmq_t
*
tmq
)
{
void
parallel_consume
(
tmq_t
*
tmq
)
{
tmq_resp_err_t
err
;
tmq_resp_err_t
err
;
...
@@ -277,20 +269,20 @@ void parallel_consume(tmq_t* tmq) {
...
@@ -277,20 +269,20 @@ void parallel_consume(tmq_t* tmq) {
int32_t
totalRows
=
0
;
int32_t
totalRows
=
0
;
int32_t
skipLogNum
=
0
;
int32_t
skipLogNum
=
0
;
while
(
running
)
{
while
(
running
)
{
tmq_message_t
*
tmqMsg
=
tmq_consumer_poll
(
tmq
,
g_stConfInfo
.
consumeDelay
*
1000
);
TAOS_RES
*
tmqMsg
=
tmq_consumer_poll
(
tmq
,
g_stConfInfo
.
consumeDelay
*
1000
);
if
(
tmqMsg
)
{
if
(
tmqMsg
)
{
totalMsgs
++
;
totalMsgs
++
;
#if 0
#if 0
TAOS_ROW row;
TAOS_ROW row;
while (NULL != (row = tmq_get_row(tmqMsg))) {
while (NULL != (row = tmq_get_row(tmqMsg))) {
totalRows++;
totalRows++;
}
}
#endif
#endif
skipLogNum
+=
tmqGetSkipLogNum
(
tmqMsg
);
/*skipLogNum += tmqGetSkipLogNum(tmqMsg);*/
if
(
0
!=
g_stConfInfo
.
showMsgFlag
)
{
if
(
0
!=
g_stConfInfo
.
showMsgFlag
)
{
msg_process
(
tmqMsg
);
/*msg_process(tmqMsg);*/
}
}
tmq_message_destroy
(
tmqMsg
);
tmq_message_destroy
(
tmqMsg
);
...
@@ -311,13 +303,13 @@ void parallel_consume(tmq_t* tmq) {
...
@@ -311,13 +303,13 @@ void parallel_consume(tmq_t* tmq) {
printf
(
"%d"
,
totalMsgs
);
// output to sim for check result
printf
(
"%d"
,
totalMsgs
);
// output to sim for check result
}
}
int
main
(
int32_t
argc
,
char
*
argv
[])
{
int
main
(
int32_t
argc
,
char
*
argv
[])
{
parseArgument
(
argc
,
argv
);
parseArgument
(
argc
,
argv
);
parseInputString
();
parseInputString
();
tmq_t
*
tmq
=
build_consumer
();
tmq_t
*
tmq
=
build_consumer
();
tmq_list_t
*
topic_list
=
build_topic_list
();
tmq_list_t
*
topic_list
=
build_topic_list
();
if
((
NULL
==
tmq
)
||
(
NULL
==
topic_list
)){
if
((
NULL
==
tmq
)
||
(
NULL
==
topic_list
))
{
return
-
1
;
return
-
1
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录