setConfigTest.cpp 2.0 KB
Newer Older
wmmhello's avatar
wmmhello 已提交
1 2 3 4 5
#include <gtest/gtest.h>
#include <inttypes.h>

#include "taos.h"
#include "tglobal.h"
wmmhello's avatar
wmmhello 已提交
6
#include "tconfig.h"
wmmhello's avatar
wmmhello 已提交
7

wmmhello's avatar
wmmhello 已提交
8 9
/* test set config function */
TEST(testCase, set_config_test1) {
wmmhello's avatar
wmmhello 已提交
10
  const char *config = "{\"debugFlag\":\"131\"}";
wmmhello's avatar
wmmhello 已提交
11 12 13
  setConfRet ret = taos_set_config(config);
  ASSERT_EQ(ret.retCode, 0);
  printf("msg:%d->%s", ret.retCode, ret.retMsg);
wmmhello's avatar
wmmhello 已提交
14 15

  const char *config2 = "{\"debugFlag\":\"199\"}";
wmmhello's avatar
wmmhello 已提交
16
  ret = taos_set_config(config2);  // not take effect
wmmhello's avatar
wmmhello 已提交
17
  ASSERT_EQ(ret.retCode, -5);
wmmhello's avatar
wmmhello 已提交
18
  printf("msg:%d->%s", ret.retCode, ret.retMsg);
wmmhello's avatar
wmmhello 已提交
19

wmmhello's avatar
wmmhello 已提交
20 21
  bool readResult = taosReadGlobalCfg();  // load file config, debugFlag not take effect
  ASSERT_TRUE(readResult);
wmmhello's avatar
wmmhello 已提交
22 23
  int32_t checkResult = taosCheckGlobalCfg();
  ASSERT_EQ(checkResult, 0);
wmmhello's avatar
wmmhello 已提交
24 25 26

  SGlobalCfg *cfg = taosGetConfigOption("debugFlag");
  ASSERT_EQ(cfg->cfgStatus, TAOS_CFG_CSTATUS_OPTION);
wmmhello's avatar
wmmhello 已提交
27
  int32_t result = *(int32_t *)cfg->ptr;
wmmhello's avatar
wmmhello 已提交
28
  ASSERT_EQ(result, 131);
wmmhello's avatar
wmmhello 已提交
29
}
wmmhello's avatar
wmmhello 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43

TEST(testCase, set_config_test2) {
  const char *config = "{\"numOfCommitThreads\":\"10\"}";
  taos_set_config(config);

  bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect
  ASSERT_TRUE(readResult);
  int32_t checkResult = taosCheckGlobalCfg();
  ASSERT_EQ(checkResult, 0);

  SGlobalCfg *cfg = taosGetConfigOption("numOfCommitThreads");
  int32_t result = *(int32_t*)cfg->ptr;
  ASSERT_NE(result, 10);    // numOfCommitThreads not type of TSDB_CFG_CTYPE_B_CLIENT
}
wmmhello's avatar
wmmhello 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

TEST(testCase, set_config_test3) {
  const char *config = "{\"numOfCoitThreads\":\"10\", \"esdfa\":\"10\"}";
  setConfRet ret = taos_set_config(config);
  ASSERT_EQ(ret.retCode, -1);
  printf("msg:%d->%s", ret.retCode, ret.retMsg);
}

TEST(testCase, set_config_test4) {
  const char *config = "{null}";
  setConfRet ret = taos_set_config(config);
  ASSERT_EQ(ret.retCode, -4);
  printf("msg:%d->%s", ret.retCode, ret.retMsg);
}

TEST(testCase, set_config_test5) {
wmmhello's avatar
wmmhello 已提交
60
  const char *config = "\"ddd\"";
wmmhello's avatar
wmmhello 已提交
61 62 63 64
  setConfRet ret = taos_set_config(config);
  ASSERT_EQ(ret.retCode, -3);
  printf("msg:%d->%s", ret.retCode, ret.retMsg);
}