func.cpp 15.4 KB
Newer Older
S
Shengliang 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/**
 * @file func.cpp
 * @author slguan (slguan@taosdata.com)
 * @brief MNODE module func tests
 * @version 1.0
 * @date 2022-01-24
 *
 * @copyright Copyright (c) 2022
 *
 */

#include "sut.h"

class MndTestFunc : public ::testing::Test {
 protected:
  static void SetUpTestSuite() { test.Init("/tmp/mnode_test_func", 9038); }
  static void TearDownTestSuite() { test.Cleanup(); }

  static Testbase test;

 public:
  void SetUp() override {}
  void TearDown() override {}
24 25 26

  void SetCode(SCreateFuncReq* pReq, const char* pCode);
  void SetComment(SCreateFuncReq* pReq, const char* pComment);
S
Shengliang 已提交
27 28 29 30
};

Testbase MndTestFunc::test;

31 32 33 34 35 36 37 38 39 40 41 42
void MndTestFunc::SetCode(SCreateFuncReq* pReq, const char* pCode) {
  int32_t len = strlen(pCode);
  pReq->pCode = (char*)taosMemoryCalloc(1, len + 1);
  strcpy(pReq->pCode, pCode);
}

void MndTestFunc::SetComment(SCreateFuncReq* pReq, const char* pComment) {
  int32_t len = strlen(pComment);
  pReq->pComment = (char*)taosMemoryCalloc(1, len + 1);
  strcpy(pReq->pComment, pComment);
}

S
Shengliang 已提交
43
TEST_F(MndTestFunc, 01_Show_Func) {
S
Shengliang Guan 已提交
44
  test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
S
Shengliang 已提交
45 46 47 48 49
  EXPECT_EQ(test.GetShowRows(), 0);
}

TEST_F(MndTestFunc, 02_Create_Func) {
  {
S
Shengliang Guan 已提交
50 51 52 53 54 55
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "");

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
56
    tFreeSCreateFuncReq(&createReq);
S
Shengliang 已提交
57 58 59 60 61 62 63

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_NAME);
  }

  {
S
Shengliang Guan 已提交
64 65
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
66
    SetCode(&createReq, "code1");
S
Shengliang Guan 已提交
67 68 69 70

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
71
    tFreeSCreateFuncReq(&createReq);
S
Shengliang 已提交
72 73 74 75 76 77 78

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT);
  }

  {
S
Shengliang Guan 已提交
79 80
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
81
    SetComment(&createReq, "comment1");
S
Shengliang Guan 已提交
82 83 84 85

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
86
    tFreeSCreateFuncReq(&createReq);
S
Shengliang 已提交
87 88 89 90 91 92 93

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_CODE);
  }

  {
S
Shengliang Guan 已提交
94 95
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
96 97
    SetCode(&createReq, "code1");
    SetComment(&createReq, "");
S
Shengliang Guan 已提交
98 99 100 101

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
102
    tFreeSCreateFuncReq(&createReq);
S
Shengliang 已提交
103 104 105

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
106
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_COMMENT);
S
Shengliang 已提交
107 108 109
  }

  {
S
Shengliang Guan 已提交
110 111
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
112 113
    SetCode(&createReq, "");
    SetComment(&createReq, "comment1");
S
Shengliang Guan 已提交
114 115 116 117

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
118
    tFreeSCreateFuncReq(&createReq);
S
Shengliang 已提交
119 120 121 122 123 124 125

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_CODE);
  }

  {
S
Shengliang Guan 已提交
126 127
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
128 129
    SetCode(&createReq, "code1");
    SetComment(&createReq, "comment1");
S
Shengliang Guan 已提交
130 131 132 133

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
134
    tFreeSCreateFuncReq(&createReq);
S
Shengliang 已提交
135 136 137 138 139 140 141

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_BUFSIZE);
  }

  {
S
Shengliang Guan 已提交
142 143
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
144 145
    SetCode(&createReq, "code1");
    SetComment(&createReq, "comment1");
S
Shengliang Guan 已提交
146 147 148 149 150
    createReq.bufSize = TSDB_FUNC_BUF_SIZE + 1;

    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
151
    tFreeSCreateFuncReq(&createReq);
S
Shengliang Guan 已提交
152

S
Shengliang 已提交
153 154 155 156 157 158
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_BUFSIZE);
  }

  for (int32_t i = 0; i < 3; ++i) {
S
Shengliang Guan 已提交
159 160
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f1");
161 162
    SetCode(&createReq, "code1");
    SetComment(&createReq, "comment1");
S
Shengliang Guan 已提交
163 164 165 166 167 168 169 170 171
    createReq.bufSize = TSDB_FUNC_BUF_SIZE + 1;
    createReq.igExists = 0;
    if (i == 2) createReq.igExists = 1;
    createReq.funcType = 1;
    createReq.scriptType = 2;
    createReq.outputType = TSDB_DATA_TYPE_SMALLINT;
    createReq.outputLen = 12;
    createReq.bufSize = 4;
    createReq.signature = 5;
S
Shengliang 已提交
172

S
Shengliang Guan 已提交
173 174 175
    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
176
    tFreeSCreateFuncReq(&createReq);
S
Shengliang Guan 已提交
177

S
Shengliang 已提交
178 179 180 181 182 183 184 185 186
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    if (i == 0 || i == 2) {
      ASSERT_EQ(pRsp->code, 0);
    } else {
      ASSERT_EQ(pRsp->code, TSDB_CODE_MND_FUNC_ALREADY_EXIST);
    }
  }

S
Shengliang Guan 已提交
187
  test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
S
Shengliang 已提交
188 189 190 191 192
  EXPECT_EQ(test.GetShowRows(), 1);
}

TEST_F(MndTestFunc, 03_Retrieve_Func) {
  {
S
Shengliang Guan 已提交
193 194 195 196
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = 1;
    retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
    taosArrayPush(retrieveReq.pFuncNames, "f1");
S
Shengliang 已提交
197

S
Shengliang Guan 已提交
198 199 200
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
201
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
202 203 204 205 206

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
207 208 209 210
    SRetrieveFuncRsp retrieveRsp = {0};
    tDeserializeSRetrieveFuncRsp(pRsp->pCont, pRsp->contLen, &retrieveRsp);
    EXPECT_EQ(retrieveRsp.numOfFuncs, 1);
    EXPECT_EQ(retrieveRsp.numOfFuncs, (int32_t)taosArrayGetSize(retrieveRsp.pFuncInfos));
S
Shengliang 已提交
211

S
Shengliang Guan 已提交
212
    SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0);
S
Shengliang 已提交
213 214 215 216 217 218 219 220

    EXPECT_STREQ(pFuncInfo->name, "f1");
    EXPECT_EQ(pFuncInfo->funcType, 1);
    EXPECT_EQ(pFuncInfo->scriptType, 2);
    EXPECT_EQ(pFuncInfo->outputType, TSDB_DATA_TYPE_SMALLINT);
    EXPECT_EQ(pFuncInfo->outputLen, 12);
    EXPECT_EQ(pFuncInfo->bufSize, 4);
    EXPECT_EQ(pFuncInfo->signature, 5);
221 222
    EXPECT_STREQ("comment1", pFuncInfo->pComment);
    EXPECT_STREQ("code1", pFuncInfo->pCode);
S
Shengliang 已提交
223

224
    tFreeSRetrieveFuncRsp(&retrieveRsp);
S
Shengliang 已提交
225 226 227
  }

  {
S
Shengliang Guan 已提交
228 229 230
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = 0;
    retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
S
Shengliang 已提交
231

S
Shengliang Guan 已提交
232 233 234
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
235
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
236 237 238 239 240 241 242

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_RETRIEVE);
  }

  {
S
Shengliang Guan 已提交
243 244 245 246 247 248
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = TSDB_FUNC_MAX_RETRIEVE + 1;
    retrieveReq.pFuncNames = taosArrayInit(TSDB_FUNC_MAX_RETRIEVE + 1, TSDB_FUNC_NAME_LEN);
    for (int32_t i = 0; i < TSDB_FUNC_MAX_RETRIEVE + 1; ++i) {
      taosArrayPush(retrieveReq.pFuncNames, "1");
    }
S
Shengliang 已提交
249

S
Shengliang Guan 已提交
250 251 252
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
253
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
254 255 256 257 258 259 260

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_RETRIEVE);
  }

  {
S
Shengliang Guan 已提交
261 262 263 264
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = 1;
    retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
    taosArrayPush(retrieveReq.pFuncNames, "f2");
S
Shengliang 已提交
265

S
Shengliang Guan 已提交
266 267 268
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
269
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
270 271 272 273 274 275 276

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC);
  }

  {
S
Shengliang Guan 已提交
277 278 279 280 281 282 283 284 285
    SCreateFuncReq createReq = {0};
    strcpy(createReq.name, "f2");
    createReq.igExists = 1;
    createReq.funcType = 2;
    createReq.scriptType = 3;
    createReq.outputType = TSDB_DATA_TYPE_BINARY;
    createReq.outputLen = 24;
    createReq.bufSize = 6;
    createReq.signature = 18;
286 287
    SetCode(&createReq, "code2");
    SetComment(&createReq, "comment2");
S
Shengliang 已提交
288

S
Shengliang Guan 已提交
289 290 291
    int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSCreateFuncReq(pReq, contLen, &createReq);
292
    tFreeSCreateFuncReq(&createReq);
S
Shengliang Guan 已提交
293

S
Shengliang 已提交
294 295 296 297
    SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
298
    test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
S
Shengliang 已提交
299 300 301 302
    EXPECT_EQ(test.GetShowRows(), 2);
  }

  {
S
Shengliang Guan 已提交
303 304 305 306
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = 1;
    retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
    taosArrayPush(retrieveReq.pFuncNames, "f2");
S
Shengliang 已提交
307

S
Shengliang Guan 已提交
308 309 310
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
311
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
312 313 314 315 316

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
317 318 319 320
    SRetrieveFuncRsp retrieveRsp = {0};
    tDeserializeSRetrieveFuncRsp(pRsp->pCont, pRsp->contLen, &retrieveRsp);
    EXPECT_EQ(retrieveRsp.numOfFuncs, 1);
    EXPECT_EQ(retrieveRsp.numOfFuncs, (int32_t)taosArrayGetSize(retrieveRsp.pFuncInfos));
S
Shengliang 已提交
321

S
Shengliang Guan 已提交
322
    SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0);
S
Shengliang 已提交
323 324 325 326 327 328 329 330

    EXPECT_STREQ(pFuncInfo->name, "f2");
    EXPECT_EQ(pFuncInfo->funcType, 2);
    EXPECT_EQ(pFuncInfo->scriptType, 3);
    EXPECT_EQ(pFuncInfo->outputType, TSDB_DATA_TYPE_BINARY);
    EXPECT_EQ(pFuncInfo->outputLen, 24);
    EXPECT_EQ(pFuncInfo->bufSize, 6);
    EXPECT_EQ(pFuncInfo->signature, 18);
331 332
    EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1);
    EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1);
S
Shengliang 已提交
333

334 335
    EXPECT_STREQ("comment2", pFuncInfo->pComment);
    EXPECT_STREQ("code2", pFuncInfo->pCode);
S
Shengliang Guan 已提交
336

337
    tFreeSRetrieveFuncRsp(&retrieveRsp);
S
Shengliang 已提交
338 339 340
  }

  {
S
Shengliang Guan 已提交
341 342 343 344 345
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = 2;
    retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
    taosArrayPush(retrieveReq.pFuncNames, "f2");
    taosArrayPush(retrieveReq.pFuncNames, "f1");
S
Shengliang 已提交
346

S
Shengliang Guan 已提交
347 348 349
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
350
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
351 352 353 354 355

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);

S
Shengliang Guan 已提交
356 357 358 359
    SRetrieveFuncRsp retrieveRsp = {0};
    tDeserializeSRetrieveFuncRsp(pRsp->pCont, pRsp->contLen, &retrieveRsp);
    EXPECT_EQ(retrieveRsp.numOfFuncs, 2);
    EXPECT_EQ(retrieveRsp.numOfFuncs, (int32_t)taosArrayGetSize(retrieveRsp.pFuncInfos));
S
Shengliang 已提交
360 361

    {
S
Shengliang Guan 已提交
362
      SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0);
S
Shengliang 已提交
363 364 365 366 367 368 369
      EXPECT_STREQ(pFuncInfo->name, "f2");
      EXPECT_EQ(pFuncInfo->funcType, 2);
      EXPECT_EQ(pFuncInfo->scriptType, 3);
      EXPECT_EQ(pFuncInfo->outputType, TSDB_DATA_TYPE_BINARY);
      EXPECT_EQ(pFuncInfo->outputLen, 24);
      EXPECT_EQ(pFuncInfo->bufSize, 6);
      EXPECT_EQ(pFuncInfo->signature, 18);
370 371 372 373
      EXPECT_EQ(pFuncInfo->commentSize, strlen("comment2") + 1);
      EXPECT_EQ(pFuncInfo->codeSize, strlen("code2") + 1);
      EXPECT_STREQ("comment2", pFuncInfo->pComment);
      EXPECT_STREQ("code2", pFuncInfo->pCode);
S
Shengliang 已提交
374 375 376
    }

    {
S
Shengliang Guan 已提交
377
      SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 1);
S
Shengliang 已提交
378 379 380 381 382 383 384
      EXPECT_STREQ(pFuncInfo->name, "f1");
      EXPECT_EQ(pFuncInfo->funcType, 1);
      EXPECT_EQ(pFuncInfo->scriptType, 2);
      EXPECT_EQ(pFuncInfo->outputType, TSDB_DATA_TYPE_SMALLINT);
      EXPECT_EQ(pFuncInfo->outputLen, 12);
      EXPECT_EQ(pFuncInfo->bufSize, 4);
      EXPECT_EQ(pFuncInfo->signature, 5);
385 386
      EXPECT_STREQ("comment1", pFuncInfo->pComment);
      EXPECT_STREQ("code1", pFuncInfo->pCode);
S
Shengliang 已提交
387
    }
388 389

    tFreeSRetrieveFuncRsp(&retrieveRsp);
S
Shengliang 已提交
390 391
  }

S
Shengliang Guan 已提交
392 393 394 395 396 397
  {
    SRetrieveFuncReq retrieveReq = {0};
    retrieveReq.numOfFuncs = 2;
    retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
    taosArrayPush(retrieveReq.pFuncNames, "f2");
    taosArrayPush(retrieveReq.pFuncNames, "f3");
S
Shengliang 已提交
398

S
Shengliang Guan 已提交
399 400 401
    int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
402
    tFreeSRetrieveFuncReq(&retrieveReq);
S
Shengliang 已提交
403 404 405 406

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC);
S
Shengliang Guan 已提交
407
  }
S
Shengliang 已提交
408
}
S
Shengliang 已提交
409 410 411

TEST_F(MndTestFunc, 04_Drop_Func) {
  {
S
Shengliang Guan 已提交
412 413
    SDropFuncReq dropReq = {0};
    strcpy(dropReq.name, "");
S
Shengliang 已提交
414

S
Shengliang Guan 已提交
415 416 417
    int32_t contLen = tSerializeSDropFuncReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDropFuncReq(pReq, contLen, &dropReq);
S
Shengliang 已提交
418 419 420

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
S
Shengliang 已提交
421
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_FUNC_NAME);
S
Shengliang 已提交
422 423 424
  }

  {
S
Shengliang Guan 已提交
425 426
    SDropFuncReq dropReq = {0};
    strcpy(dropReq.name, "f3");
S
Shengliang 已提交
427

S
Shengliang Guan 已提交
428 429 430
    int32_t contLen = tSerializeSDropFuncReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDropFuncReq(pReq, contLen, &dropReq);
S
Shengliang 已提交
431 432 433 434 435 436 437

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, TSDB_CODE_MND_FUNC_NOT_EXIST);
  }

  {
S
Shengliang Guan 已提交
438 439 440
    SDropFuncReq dropReq = {0};
    strcpy(dropReq.name, "f3");
    dropReq.igNotExists = 1;
S
Shengliang 已提交
441

S
Shengliang Guan 已提交
442 443 444
    int32_t contLen = tSerializeSDropFuncReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDropFuncReq(pReq, contLen, &dropReq);
S
Shengliang 已提交
445 446 447 448 449 450 451

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

  {
S
Shengliang Guan 已提交
452 453 454
    SDropFuncReq dropReq = {0};
    strcpy(dropReq.name, "f1");
    dropReq.igNotExists = 1;
S
Shengliang 已提交
455

S
Shengliang Guan 已提交
456 457 458
    int32_t contLen = tSerializeSDropFuncReq(NULL, 0, &dropReq);
    void*   pReq = rpcMallocCont(contLen);
    tSerializeSDropFuncReq(pReq, contLen, &dropReq);
S
Shengliang 已提交
459 460 461 462 463 464

    SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_FUNC, pReq, contLen);
    ASSERT_NE(pRsp, nullptr);
    ASSERT_EQ(pRsp->code, 0);
  }

S
Shengliang Guan 已提交
465
  test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
S
Shengliang 已提交
466
  EXPECT_EQ(test.GetShowRows(), 1);
S
Shengliang 已提交
467 468 469 470

  // restart
  test.Restart();

S
Shengliang Guan 已提交
471
  test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
S
Shengliang 已提交
472
  EXPECT_EQ(test.GetShowRows(), 1);
S
Shengliang 已提交
473
}