提交 96089657 编写于 作者: S Shengliang

ut for udf manage

上级 022b5f85
...@@ -539,8 +539,8 @@ typedef struct { ...@@ -539,8 +539,8 @@ typedef struct {
} SCreateFuncReq; } SCreateFuncReq;
typedef struct { typedef struct {
char name[TSDB_FUNC_NAME_LEN]; char name[TSDB_FUNC_NAME_LEN];
int8_t igNotExists; int8_t igNotExists;
} SDropFuncReq; } SDropFuncReq;
typedef struct { typedef struct {
......
...@@ -405,7 +405,7 @@ static int32_t mndProcessRetrieveFuncReq(SMnodeMsg *pReq) { ...@@ -405,7 +405,7 @@ static int32_t mndProcessRetrieveFuncReq(SMnodeMsg *pReq) {
pFuncInfo->codeSize = htonl(pFunc->codeSize); pFuncInfo->codeSize = htonl(pFunc->codeSize);
memcpy(pFuncInfo->pCont, pFunc->pComment, pFunc->commentSize); memcpy(pFuncInfo->pCont, pFunc->pComment, pFunc->commentSize);
memcpy(pFuncInfo->pCont + pFunc->commentSize, pFunc->pCode, pFunc->codeSize); memcpy(pFuncInfo->pCont + pFunc->commentSize, pFunc->pCode, pFunc->codeSize);
pOutput += sizeof(SFuncInfo) + pFunc->commentSize + pFunc->codeSize; pOutput += (sizeof(SFuncInfo) + pFunc->commentSize + pFunc->codeSize);
mndReleaseFunc(pMnode, pFunc); mndReleaseFunc(pMnode, pFunc);
} }
......
...@@ -363,7 +363,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -363,7 +363,7 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
contLen = (contLen + numOfFuncs * TSDB_FUNC_NAME_LEN); contLen = (contLen + numOfFuncs * TSDB_FUNC_NAME_LEN);
SRetrieveFuncReq* pReq = (SRetrieveFuncReq*)rpcMallocCont(contLen); SRetrieveFuncReq* pReq = (SRetrieveFuncReq*)rpcMallocCont(contLen);
pReq->numOfFuncs = htonl(1); pReq->numOfFuncs = htonl(numOfFuncs);
strcpy(pReq->pFuncNames, "f2"); strcpy(pReq->pFuncNames, "f2");
strcpy((char*)pReq->pFuncNames + TSDB_FUNC_NAME_LEN, "f1"); strcpy((char*)pReq->pFuncNames + TSDB_FUNC_NAME_LEN, "f1");
...@@ -425,41 +425,54 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) { ...@@ -425,41 +425,54 @@ TEST_F(MndTestFunc, 03_Retrieve_Func) {
EXPECT_EQ(pFuncInfo->commentSize, TSDB_FUNC_COMMENT_LEN); EXPECT_EQ(pFuncInfo->commentSize, TSDB_FUNC_COMMENT_LEN);
EXPECT_EQ(pFuncInfo->codeSize, TSDB_FUNC_CODE_LEN); EXPECT_EQ(pFuncInfo->codeSize, TSDB_FUNC_CODE_LEN);
// char* pComment = pFuncInfo->pCont; char* pComment = pFuncInfo->pCont;
// char* pCode = pFuncInfo->pCont + pFuncInfo->commentSize; char* pCode = pFuncInfo->pCont + pFuncInfo->commentSize;
// char comments[TSDB_FUNC_COMMENT_LEN] = {0}; char comments[TSDB_FUNC_COMMENT_LEN] = {0};
// for (int32_t i = 0; i < TSDB_FUNC_COMMENT_LEN - 1; ++i) { for (int32_t i = 0; i < TSDB_FUNC_COMMENT_LEN - 1; ++i) {
// comments[i] = 'm'; comments[i] = 'm';
// } }
// char codes[TSDB_FUNC_CODE_LEN] = {0}; char codes[TSDB_FUNC_CODE_LEN] = {0};
// for (int32_t i = 0; i < TSDB_FUNC_CODE_LEN - 1; ++i) { for (int32_t i = 0; i < TSDB_FUNC_CODE_LEN - 1; ++i) {
// codes[i] = 'd'; codes[i] = 'd';
// } }
// EXPECT_STREQ(pComment, comments); EXPECT_STREQ(pComment, comments);
// EXPECT_STREQ(pCode, codes); EXPECT_STREQ(pCode, codes);
} }
} }
}
#if 0 {
int32_t contLen = sizeof(SRetrieveFuncReq);
int32_t numOfFuncs = 2;
contLen = (contLen + numOfFuncs * TSDB_FUNC_NAME_LEN);
SRetrieveFuncReq* pReq = (SRetrieveFuncReq*)rpcMallocCont(contLen);
pReq->numOfFuncs = htonl(numOfFuncs);
strcpy(pReq->pFuncNames, "f2");
strcpy((char*)pReq->pFuncNames + TSDB_FUNC_NAME_LEN, "f3");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC);
}
}
TEST_F(MndTestFunc, 04_Drop_Func) { TEST_F(MndTestFunc, 04_Drop_Func) {
{ {
int32_t contLen = sizeof(SDropFuncReq); int32_t contLen = sizeof(SDropFuncReq);
SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen); SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, ""); strcpy(pReq->name, "");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_FORMAT); ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_NAME);
} }
{ {
int32_t contLen = sizeof(SDropFuncReq); int32_t contLen = sizeof(SDropFuncReq);
SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen); SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u4"); strcpy(pReq->name, "f3");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -470,100 +483,19 @@ TEST_F(MndTestFunc, 04_Drop_Func) { ...@@ -470,100 +483,19 @@ TEST_F(MndTestFunc, 04_Drop_Func) {
int32_t contLen = sizeof(SDropFuncReq); int32_t contLen = sizeof(SDropFuncReq);
SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen); SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1"); strcpy(pReq->name, "f3");
pReq->igNotExists = 1;
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0); ASSERT_EQ(pRsp->code, 0);
} }
test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, "");
CHECK_META("show functions", 4);
test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 1);
}
TEST_F(MndTestFunc, 05_Create_Drop_Alter_Func) {
{
int32_t contLen = sizeof(SCreateFuncReq);
SCreateFuncReq* pReq = (SCreateFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p1");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
int32_t contLen = sizeof(SCreateFuncReq);
SCreateFuncReq* pReq = (SCreateFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u2");
strcpy(pReq->pass, "p2");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, "");
CHECK_META("show functions", 4);
test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 3);
CheckBinary("u1", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("u2", TSDB_FUNC_LEN);
CheckBinary("normal", 10);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
{
int32_t contLen = sizeof(SAlterFuncReq);
SAlterFuncReq* pReq = (SAlterFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1");
strcpy(pReq->pass, "p2");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, "");
CHECK_META("show functions", 4);
test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 3);
CheckBinary("u1", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("u2", TSDB_FUNC_LEN);
CheckBinary("normal", 10);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp();
CheckTimestamp();
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
{ {
int32_t contLen = sizeof(SDropFuncReq); int32_t contLen = sizeof(SDropFuncReq);
SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen); SDropFuncReq* pReq = (SDropFuncReq*)rpcMallocCont(contLen);
strcpy(pReq->user, "u1"); strcpy(pReq->name, "f1");
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen); SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
ASSERT_NE(pRsp, nullptr); ASSERT_NE(pRsp, nullptr);
...@@ -571,37 +503,19 @@ TEST_F(MndTestFunc, 05_Create_Drop_Alter_Func) { ...@@ -571,37 +503,19 @@ TEST_F(MndTestFunc, 05_Create_Drop_Alter_Func) {
} }
test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, "");
CHECK_META("show functions", 4); CHECK_META("show functions", 7);
test.SendShowRetrieveReq(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("u2", TSDB_FUNC_LEN);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp();
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
// restart // restart
test.Restart(); test.Restart();
test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, ""); test.SendShowMetaReq(TSDB_MGMT_TABLE_FUNC, "");
CHECK_META("show functions", 4); CHECK_META("show functions", 7);
test.SendShowRetrieveReq(); test.SendShowRetrieveReq();
EXPECT_EQ(test.GetShowRows(), 2); EXPECT_EQ(test.GetShowRows(), 1);
CheckBinary("root", TSDB_FUNC_LEN); CheckBinary("f2", TSDB_FUNC_NAME_LEN);
CheckBinary("u2", TSDB_FUNC_LEN);
CheckBinary("super", 10);
CheckBinary("normal", 10);
CheckTimestamp();
CheckTimestamp();
CheckBinary("root", TSDB_FUNC_LEN);
CheckBinary("root", TSDB_FUNC_LEN);
} }
#endif
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册