test: fix tmq test case

This commit is contained in:
Liu Jicong 2022-04-13 16:07:38 +08:00
parent 1a13affb13
commit 79bc579779
1 changed files with 109 additions and 117 deletions

View File

@ -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"
@ -81,7 +79,6 @@ static void printHelp() {
} }
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;
@ -128,23 +125,20 @@ void splitStr(char **arr, char *str, const char *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);
@ -173,7 +167,8 @@ void parseInputString() {
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,11 +176,9 @@ 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);
@ -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,7 +269,7 @@ 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++;
@ -288,9 +280,9 @@ void parallel_consume(tmq_t* tmq) {
} }
#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);