提交 7965b4c7 编写于 作者: wmmhello's avatar wmmhello

[TD-5992] add test case

上级 48281dbf
...@@ -454,7 +454,7 @@ static int taos_set_config_imp(const char *config){ ...@@ -454,7 +454,7 @@ static int taos_set_config_imp(const char *config){
int size = cJSON_GetArraySize(root); int size = cJSON_GetArraySize(root);
for(int i = 0; i < size; i++){ for(int i = 0; i < size; i++){
cJSON *item = cJSON_GetArrayItem(root, i); cJSON *item = cJSON_GetArrayItem(root, i);
if(item && !taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION)){ if(item && !taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION, TSDB_CFG_CTYPE_B_CLIENT)){
ret = -2; ret = -2;
} }
} }
......
...@@ -5,21 +5,35 @@ ...@@ -5,21 +5,35 @@
#include "tglobal.h" #include "tglobal.h"
#include "tconfig.h" #include "tconfig.h"
/* test parse time function */ /* test set config function */
TEST(testCase, set_config_test) { TEST(testCase, set_config_test1) {
const char *config = "{\"debugFlag\":\"131\"}"; const char *config = "{\"debugFlag\":\"131\"}";
taos_set_config(config); taos_set_config(config);
const char *config2 = "{\"debugFlag\":\"199\"}"; const char *config2 = "{\"debugFlag\":\"199\"}";
taos_set_config(config2); // not take effect taos_set_config(config2); // not take effect
bool readResult = taosReadGlobalCfg(); bool readResult = taosReadGlobalCfg(); // load file config, debugFlag not take effect
ASSERT_TRUE(readResult); // load file config, not take effect ASSERT_TRUE(readResult);
int32_t checkResult = taosCheckGlobalCfg(); int32_t checkResult = taosCheckGlobalCfg();
ASSERT_EQ(checkResult, 0); ASSERT_EQ(checkResult, 0);
SGlobalCfg *cfg = taosGetConfigOption("debugFlag"); SGlobalCfg *cfg = taosGetConfigOption("debugFlag");
ASSERT_EQ(cfg->cfgStatus, TAOS_CFG_CSTATUS_OPTION); ASSERT_EQ(cfg->cfgStatus, TAOS_CFG_CSTATUS_OPTION);
int32_t result = *(int32_t*)cfg->ptr; int32_t result = *(int32_t *)cfg->ptr;
ASSERT_EQ(result, 131); ASSERT_EQ(result, 131);
} }
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
}
...@@ -89,7 +89,7 @@ void taosDumpGlobalCfg(); ...@@ -89,7 +89,7 @@ void taosDumpGlobalCfg();
void taosInitConfigOption(SGlobalCfg cfg); void taosInitConfigOption(SGlobalCfg cfg);
SGlobalCfg * taosGetConfigOption(const char *option); SGlobalCfg * taosGetConfigOption(const char *option);
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus); bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, int8_t cfgStatus, int8_t sourceType);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -294,11 +294,12 @@ SGlobalCfg *taosGetConfigOption(const char *option) { ...@@ -294,11 +294,12 @@ SGlobalCfg *taosGetConfigOption(const char *option) {
} }
bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3, bool taosReadConfigOption(const char *option, char *value, char *value2, char *value3,
int8_t cfgStatus) { int8_t cfgStatus, int8_t sourceType) {
bool ret = false; bool ret = false;
for (int i = 0; i < tsGlobalConfigNum; ++i) { for (int i = 0; i < tsGlobalConfigNum; ++i) {
SGlobalCfg *cfg = tsGlobalConfig + i; SGlobalCfg *cfg = tsGlobalConfig + i;
if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue;
if (sourceType != 0 && !(sourceType & TSDB_CFG_CTYPE_B_CLIENT)) continue;
if (strcasecmp(cfg->option, option) != 0) continue; if (strcasecmp(cfg->option, option) != 0) continue;
switch (cfg->valType) { switch (cfg->valType) {
...@@ -479,7 +480,7 @@ bool taosReadGlobalCfg() { ...@@ -479,7 +480,7 @@ bool taosReadGlobalCfg() {
if (vlen3 != 0) value3[vlen3] = 0; if (vlen3 != 0) value3[vlen3] = 0;
} }
taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE); taosReadConfigOption(option, value, value2, value3, TAOS_CFG_CSTATUS_FILE, 0);
} }
fclose(fp); fclose(fp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册