fix:[TD-33272]add test case
This commit is contained in:
parent
d927e8c31a
commit
a1e20680f7
|
@ -276,6 +276,7 @@ TEST(testCase, smlParseCols_Test) {
|
|||
info->dataFormat = false;
|
||||
SSmlLineInfo elements = {0};
|
||||
info->msgBuf = msgBuf;
|
||||
ASSERT_EQ(smlInitHandle(NULL),
|
||||
|
||||
const char *data =
|
||||
"st,t=1 cb\\=in=\"pass\\,it "
|
||||
|
|
|
@ -11141,6 +11141,7 @@ void tOffsetCopy(STqOffsetVal *pLeft, const STqOffsetVal *pRight) {
|
|||
}
|
||||
|
||||
void tOffsetDestroy(void *param) {
|
||||
if (param == NULL) return;
|
||||
STqOffsetVal *pVal = (STqOffsetVal *)param;
|
||||
if (IS_VAR_DATA_TYPE(pVal->primaryKey.type)) {
|
||||
taosMemoryFreeClear(pVal->primaryKey.pData);
|
||||
|
@ -11148,6 +11149,7 @@ void tOffsetDestroy(void *param) {
|
|||
}
|
||||
|
||||
void tDeleteSTqOffset(void *param) {
|
||||
if (param == NULL) return;
|
||||
STqOffset *pVal = (STqOffset *)param;
|
||||
tOffsetDestroy(&pVal->val);
|
||||
}
|
||||
|
|
|
@ -152,10 +152,9 @@ void tqClose(STQ* pTq) {
|
|||
taosMemoryFree(pTq->path);
|
||||
tqMetaClose(pTq);
|
||||
|
||||
int32_t vgId = pTq->pStreamMeta->vgId;
|
||||
streamMetaClose(pTq->pStreamMeta);
|
||||
|
||||
qDebug("vgId:%d end to close tq", vgId);
|
||||
qDebug("vgId:%d end to close tq", pTq->pStreamMeta != NULL ? pTq->pStreamMeta->vgId : -1);
|
||||
taosMemoryFree(pTq);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,33 +17,41 @@
|
|||
#include "tq.h"
|
||||
|
||||
int32_t tqBuildFName(char** data, const char* path, char* name) {
|
||||
if (data == NULL || path == NULL || name == NULL) {
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
char* fname = NULL;
|
||||
TSDB_CHECK_NULL(data, code, lino, END, TSDB_CODE_INVALID_MSG);
|
||||
TSDB_CHECK_NULL(path, code, lino, END, TSDB_CODE_INVALID_MSG);
|
||||
TSDB_CHECK_NULL(name, code, lino, END, TSDB_CODE_INVALID_MSG);
|
||||
int32_t len = strlen(path) + strlen(name) + 2;
|
||||
char* fname = taosMemoryCalloc(1, len);
|
||||
if(fname == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
int32_t code = tsnprintf(fname, len, "%s%s%s", path, TD_DIRSEP, name);
|
||||
if (code < 0){
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
taosMemoryFree(fname);
|
||||
return code;
|
||||
}
|
||||
fname = taosMemoryCalloc(1, len);
|
||||
TSDB_CHECK_NULL(fname, code, lino, END, terrno);
|
||||
code = tsnprintf(fname, len, "%s%s%s", path, TD_DIRSEP, name);
|
||||
TSDB_CHECK_CODE(code, lino, END);
|
||||
|
||||
*data = fname;
|
||||
return TDB_CODE_SUCCESS;
|
||||
fname = NULL;
|
||||
|
||||
END:
|
||||
if (code != 0){
|
||||
tqError("%s failed at %d since %s", __func__, lino, tstrerror(code));
|
||||
}
|
||||
taosMemoryFree(fname);
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
|
||||
if (pTq == NULL || name == NULL) {
|
||||
return TSDB_CODE_INVALID_MSG;
|
||||
}
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
void* pMemBuf = NULL;
|
||||
int32_t code = TDB_CODE_SUCCESS;
|
||||
int32_t lino = 0;
|
||||
void* pMemBuf = NULL;
|
||||
TdFilePtr pFile = NULL;
|
||||
STqOffset *pOffset = NULL;
|
||||
void *pIter = NULL;
|
||||
|
||||
TdFilePtr pFile = taosOpenFile(name, TD_FILE_READ);
|
||||
TSDB_CHECK_NULL(pTq, code, lino, END, TSDB_CODE_INVALID_MSG);
|
||||
TSDB_CHECK_NULL(name, code, lino, END, TSDB_CODE_INVALID_MSG);
|
||||
|
||||
pFile = taosOpenFile(name, TD_FILE_READ);
|
||||
TSDB_CHECK_NULL(pFile, code, lino, END, TDB_CODE_SUCCESS);
|
||||
|
||||
int64_t ret = 0;
|
||||
|
@ -68,25 +76,20 @@ int32_t tqOffsetRestoreFromFile(STQ* pTq, char* name) {
|
|||
STqOffset offset = {0};
|
||||
code = tqMetaDecodeOffsetInfo(&offset, pMemBuf, size);
|
||||
TSDB_CHECK_CODE(code, lino, END);
|
||||
code = taosHashPut(pTq->pOffset, offset.subKey, strlen(offset.subKey), &offset, sizeof(STqOffset));
|
||||
if (code != TDB_CODE_SUCCESS) {
|
||||
tDeleteSTqOffset(&offset);
|
||||
goto END;
|
||||
}
|
||||
pOffset = &offset;
|
||||
code = taosHashPut(pTq->pOffset, pOffset->subKey, strlen(pOffset->subKey), pOffset, sizeof(STqOffset));
|
||||
TSDB_CHECK_CODE(code, lino, END);
|
||||
pOffset = NULL;
|
||||
|
||||
tqInfo("tq: offset restore from file to tdb, size:%d, hash size:%d subkey:%s", total, taosHashGetSize(pTq->pOffset), offset.subKey);
|
||||
taosMemoryFree(pMemBuf);
|
||||
pMemBuf = NULL;
|
||||
}
|
||||
|
||||
void *pIter = NULL;
|
||||
while ((pIter = taosHashIterate(pTq->pOffset, pIter))) {
|
||||
STqOffset* pOffset = (STqOffset*)pIter;
|
||||
code = tqMetaSaveOffset(pTq, pOffset);
|
||||
if(code != 0){
|
||||
taosHashCancelIterate(pTq->pOffset, pIter);
|
||||
goto END;
|
||||
}
|
||||
STqOffset* offset = (STqOffset*)pIter;
|
||||
code = tqMetaSaveOffset(pTq, offset);
|
||||
TSDB_CHECK_CODE(code, lino, END);
|
||||
}
|
||||
|
||||
END:
|
||||
|
@ -96,5 +99,8 @@ END:
|
|||
taosCloseFile(&pFile);
|
||||
taosMemoryFree(pMemBuf);
|
||||
|
||||
tDeleteSTqOffset(pOffset);
|
||||
taosHashCancelIterate(pTq->pOffset, pIter);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -1,29 +1,25 @@
|
|||
MESSAGE(STATUS "vnode unit test")
|
||||
MESSAGE(STATUS "tq unit test")
|
||||
|
||||
# GoogleTest requires at least C++11
|
||||
SET(CMAKE_CXX_STANDARD 11)
|
||||
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
||||
|
||||
# add_executable(tqTest "")
|
||||
# target_sources(tqTest
|
||||
# PRIVATE
|
||||
# "tqMetaTest.cpp"
|
||||
# )
|
||||
# target_include_directories(tqTest
|
||||
# PUBLIC
|
||||
# "${TD_SOURCE_DIR}/include/server/vnode/tq"
|
||||
# "${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
# )
|
||||
add_executable(tqTest tqTest.cpp)
|
||||
target_include_directories(tqTest
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||
)
|
||||
|
||||
# target_link_libraries(tqTest
|
||||
# tq
|
||||
# gtest_main
|
||||
# )
|
||||
# enable_testing()
|
||||
# add_test(
|
||||
# NAME tq_test
|
||||
# COMMAND tqTest
|
||||
# )
|
||||
TARGET_LINK_LIBRARIES(
|
||||
tqTest
|
||||
PUBLIC os util common vnode gtest_main
|
||||
)
|
||||
|
||||
enable_testing()
|
||||
|
||||
add_test(
|
||||
NAME tq_test
|
||||
COMMAND tqTest
|
||||
)
|
||||
|
||||
# ADD_EXECUTABLE(tsdbSmaTest tsdbSmaTest.cpp)
|
||||
# TARGET_LINK_LIBRARIES(
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include <vnodeInt.h>
|
||||
|
||||
#include <taoserror.h>
|
||||
#include <tglobal.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <tmsg.h>
|
||||
#include <vnodeInt.h>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wwrite-strings"
|
||||
#pragma GCC diagnostic ignored "-Wunused-function"
|
||||
#pragma GCC diagnostic ignored "-Wunused-variable"
|
||||
#pragma GCC diagnostic ignored "-Wsign-compare"
|
||||
|
||||
SDmNotifyHandle dmNotifyHdl = {.state = 0};
|
||||
|
||||
#include "tq.h"
|
||||
int main(int argc, char **argv) {
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
||||
STqOffset offset = {.subKey = "testtest", .val = {.type = TMQ_OFFSET__LOG, .version = 8923}};
|
||||
|
||||
void tqWriteOffset() {
|
||||
TdFilePtr pFile = taosOpenFile(TQ_OFFSET_NAME, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
|
||||
|
||||
int32_t bodyLen;
|
||||
int32_t code;
|
||||
tEncodeSize(tEncodeSTqOffset, &offset, bodyLen, code);
|
||||
int32_t totLen = INT_BYTES + bodyLen;
|
||||
void* buf = taosMemoryCalloc(1, totLen);
|
||||
void* abuf = POINTER_SHIFT(buf, INT_BYTES);
|
||||
|
||||
*(int32_t*)buf = htonl(bodyLen);
|
||||
SEncoder encoder;
|
||||
tEncoderInit(&encoder, (uint8_t*)abuf, bodyLen);
|
||||
tEncodeSTqOffset(&encoder, &offset);
|
||||
taosWriteFile(pFile, buf, totLen);
|
||||
|
||||
taosMemoryFree(buf);
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
}
|
||||
|
||||
TEST(testCase, tqOffsetTest) {
|
||||
STQ* pTq = (STQ*)taosMemoryCalloc(1, sizeof(STQ));
|
||||
pTq->path = taosStrdup("./");
|
||||
|
||||
pTq->pOffset = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_ENTRY_LOCK);
|
||||
taosHashSetFreeFp(pTq->pOffset, (FDelete)tDeleteSTqOffset);
|
||||
|
||||
tdbOpen(pTq->path, 16 * 1024, 1, &pTq->pMetaDB, 0, 0, NULL);
|
||||
tdbTbOpen("tq.offset.db", -1, -1, NULL, pTq->pMetaDB, &pTq->pOffsetStore, 0);
|
||||
|
||||
tqWriteOffset();
|
||||
tqOffsetRestoreFromFile(pTq, TQ_OFFSET_NAME);
|
||||
taosRemoveFile(TQ_OFFSET_NAME);
|
||||
tqClose(pTq);
|
||||
}
|
||||
|
||||
#pragma GCC diagnostic pop
|
|
@ -357,10 +357,11 @@ end:
|
|||
int32_t smlInitHandle(SQuery** query) {
|
||||
int32_t lino = 0;
|
||||
int32_t code = 0;
|
||||
*query = NULL;
|
||||
SQuery* pQuery = NULL;
|
||||
SVnodeModifyOpStmt* stmt = NULL;
|
||||
TSDB_CHECK_NULL(query, code, lino, end, TSDB_CODE_INVALID_PARA);
|
||||
|
||||
*query = NULL;
|
||||
code = nodesMakeNode(QUERY_NODE_QUERY, (SNode**)&pQuery);
|
||||
TSDB_CHECK_CODE(code, lino, end);
|
||||
pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE;
|
||||
|
|
|
@ -1939,6 +1939,20 @@ int sml_td24559_Test() {
|
|||
}
|
||||
taos_free_result(pRes);
|
||||
|
||||
const char *sql2[] = {
|
||||
"stb,t1=1 f1=283i32,f2=g\"Point(4.343 89.342)\" 1632299375000",
|
||||
};
|
||||
|
||||
pRes = taos_query(taos, "use td24559");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql2, sizeof(sql2) / sizeof(sql2[0]), TSDB_SML_LINE_PROTOCOL,
|
||||
TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||
|
||||
code = taos_errno(pRes);
|
||||
printf("%s result0:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(taos, "drop database if exists td24559");
|
||||
taos_free_result(pRes);
|
||||
|
||||
|
@ -2325,6 +2339,17 @@ int sml_td17324_Test() {
|
|||
ASSERT(code == 0);
|
||||
taos_free_result(pRes);
|
||||
|
||||
const char *sql1[] = {
|
||||
"st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"pa3ssit\",c2=false,c4=4f64 1732700000394000000",
|
||||
};
|
||||
|
||||
pRes = taos_schemaless_insert(taos, (char **)sql1, sizeof(sql1) / sizeof(sql1[0]), TSDB_SML_LINE_PROTOCOL,
|
||||
TSDB_SML_TIMESTAMP_NANO_SECONDS);
|
||||
code = taos_errno(pRes);
|
||||
printf("%s result0:%s\n", __FUNCTION__, taos_errstr(pRes));
|
||||
ASSERT(code == 0);
|
||||
taos_free_result(pRes);
|
||||
|
||||
taos_close(taos);
|
||||
|
||||
return code;
|
||||
|
|
Loading…
Reference in New Issue