test_config.cpp 55.8 KB
Newer Older
1
// Copyright (C) 2019-2020 Zilliz. All rights reserved.
J
jinhai 已提交
2
//
3 4
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
J
jinhai 已提交
5
//
6 7 8 9 10
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.
J
jinhai 已提交
11

12
#include <cmath>
13 14 15 16
#include <limits>

#include <fiu-control.h>
#include <fiu-local.h>
S
starlord 已提交
17
#include <gtest/gtest-death-test.h>
Y
youny626 已提交
18
#include <gtest/gtest.h>
19

20
#include "config/Config.h"
Y
yudong.cai 已提交
21
#include "config/YamlConfigMgr.h"
S
starlord 已提交
22
#include "server/utils.h"
Y
youny626 已提交
23
#include "utils/CommonUtil.h"
Z
Zhiru Zhu 已提交
24
#include "utils/StringHelpFunctions.h"
Y
youny626 已提交
25
#include "utils/ValidationUtil.h"
G
groot 已提交
26

G
groot 已提交
27 28
namespace {

S
starlord 已提交
29
static constexpr uint64_t KB = 1024;
S
starlord 已提交
30 31
static constexpr uint64_t MB = KB * 1024;
static constexpr uint64_t GB = MB * 1024;
S
starlord 已提交
32

Y
youny626 已提交
33
}  // namespace
G
groot 已提交
34

C
Cai Yudong 已提交
35 36
namespace ms = milvus::server;

S
starlord 已提交
37
TEST_F(ConfigTest, CONFIG_TEST) {
S
starlord 已提交
38
    milvus::server::ConfigMgr* config_mgr = milvus::server::YamlConfigMgr::GetInstance();
G
groot 已提交
39

Y
yudong.cai 已提交
40 41
    milvus::Status s = config_mgr->LoadConfigFile("");
    ASSERT_FALSE(s.ok());
G
groot 已提交
42

S
starlord 已提交
43
    std::string config_path(CONFIG_PATH);
S
starlord 已提交
44
    s = config_mgr->LoadConfigFile(config_path + INVALID_CONFIG_FILE);
Y
yudong.cai 已提交
45
    ASSERT_FALSE(s.ok());
G
groot 已提交
46

S
starlord 已提交
47
    s = config_mgr->LoadConfigFile(config_path + VALID_CONFIG_FILE);
Y
yudong.cai 已提交
48
    ASSERT_TRUE(s.ok());
G
groot 已提交
49

G
groot 已提交
50
    config_mgr->Print();
S
shengjh 已提交
51
    config_mgr->DumpString();
G
groot 已提交
52

S
starlord 已提交
53 54
    milvus::server::ConfigNode& root_config = config_mgr->GetRootNode();
    milvus::server::ConfigNode& server_config = root_config.GetChild("server_config");
S
starlord 已提交
55
    milvus::server::ConfigNode invalid_config = root_config.GetChild("invalid_config");
S
shengjh 已提交
56 57 58 59 60 61 62 63 64

    const auto& im_config_mgr = *static_cast<milvus::server::YamlConfigMgr*>(config_mgr);
    const milvus::server::ConfigNode& im_root_config = im_config_mgr.GetRootNode();
    const milvus::server::ConfigNode& im_invalid_config = im_root_config.GetChild("invalid_config");
    const milvus::server::ConfigNode& im_not_exit_config = im_root_config.GetChild("not_exit_config");
    ASSERT_EQ(im_not_exit_config.GetConfig().size(), 0);
    ASSERT_EQ(im_root_config.DumpString(), root_config.DumpString());
    ASSERT_EQ(im_invalid_config.DumpString(), invalid_config.DumpString());

S
starlord 已提交
65 66 67
    auto valus = invalid_config.GetSequence("not_exist");
    float ff = invalid_config.GetFloatValue("not_exist", 3.0);
    ASSERT_EQ(ff, 3.0);
S
shengjh 已提交
68 69 70 71 72 73 74 75
    double not_exit_double = server_config.GetDoubleValue("not_exit", 3.0);
    ASSERT_EQ(not_exit_double, 3.0);
    int64_t not_exit_int64 = server_config.GetInt64Value("not_exit", 3);
    ASSERT_EQ(not_exit_int64, 3);
    int64_t not_exit_int32 = server_config.GetInt32Value("not_exit", 3);
    ASSERT_EQ(not_exit_int32, 3);
    bool not_exit_bool = server_config.GetBoolValue("not_exit", false);
    ASSERT_FALSE(not_exit_bool);
G
groot 已提交
76 77 78 79

    std::string address = server_config.GetValue("address");
    ASSERT_TRUE(!address.empty());
    int64_t port = server_config.GetInt64Value("port");
S
starlord 已提交
80
    ASSERT_NE(port, 0);
G
groot 已提交
81

G
groot 已提交
82 83
    server_config.SetValue("float_test", "2.5");
    double dbl = server_config.GetDoubleValue("float_test");
84
    ASSERT_LE(std::fabs(dbl - 2.5), std::numeric_limits<double>::epsilon());
G
groot 已提交
85
    float flt = server_config.GetFloatValue("float_test");
86
    ASSERT_LE(std::fabs(flt - 2.5), std::numeric_limits<float>::epsilon());
G
groot 已提交
87 88 89 90 91 92 93 94 95 96

    server_config.SetValue("bool_test", "true");
    bool blt = server_config.GetBoolValue("bool_test");
    ASSERT_TRUE(blt);

    server_config.SetValue("int_test", "34");
    int32_t it32 = server_config.GetInt32Value("int_test");
    ASSERT_EQ(it32, 34);
    int64_t it64 = server_config.GetInt64Value("int_test");
    ASSERT_EQ(it64, 34);
G
groot 已提交
97

S
starlord 已提交
98
    milvus::server::ConfigNode fake;
G
groot 已提交
99 100
    server_config.AddChild("fake", fake);
    fake = server_config.GetChild("fake");
S
starlord 已提交
101
    milvus::server::ConfigNodeArr arr;
G
groot 已提交
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
    server_config.GetChildren(arr);
    ASSERT_EQ(arr.size(), 1UL);

    server_config.ClearChildren();
    auto children = server_config.GetChildren();
    ASSERT_TRUE(children.empty());

    server_config.ClearConfig();
    auto configs = server_config.GetConfig();
    ASSERT_TRUE(configs.empty());

    server_config.AddSequenceItem("seq", "aaa");
    server_config.AddSequenceItem("seq", "bbb");
    auto seq = server_config.GetSequence("seq");
    ASSERT_EQ(seq.size(), 2UL);

S
shengjh 已提交
118 119
    server_config.SetValue("fake", "fake");
    server_config.AddChild("fake", fake);
S
starlord 已提交
120
    milvus::server::ConfigNode combine;
G
groot 已提交
121 122 123 124 125 126
    combine.Combine(server_config);

    combine.PrintAll();
    std::string all = combine.DumpString();
    ASSERT_TRUE(!all.empty());

G
groot 已提交
127 128 129 130 131
    server_config.ClearSequences();
    auto seqs = server_config.GetSequences();
    ASSERT_TRUE(seqs.empty());
}

Z
Zhiru Zhu 已提交
132 133 134 135 136 137 138 139 140
TEST_F(ConfigTest, SERVER_CONFIG_VALID_TEST) {
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    std::string str_val;
    int64_t int64_val;
    float float_val;
    bool bool_val;

    /* server config */
    std::string server_addr = "192.168.1.155";
C
Cai Yudong 已提交
141 142
    ASSERT_TRUE(config.SetServerConfigAddress(server_addr).ok());
    ASSERT_TRUE(config.GetServerConfigAddress(str_val).ok());
Z
Zhiru Zhu 已提交
143 144 145
    ASSERT_TRUE(str_val == server_addr);

    std::string server_port = "12345";
C
Cai Yudong 已提交
146 147
    ASSERT_TRUE(config.SetServerConfigPort(server_port).ok());
    ASSERT_TRUE(config.GetServerConfigPort(str_val).ok());
Z
Zhiru Zhu 已提交
148 149
    ASSERT_TRUE(str_val == server_port);

B
BossZou 已提交
150 151 152 153 154
    std::string web_port = "19999";
    ASSERT_TRUE(config.SetServerConfigWebPort(web_port).ok());
    ASSERT_TRUE(config.GetServerConfigWebPort(str_val).ok());
    ASSERT_TRUE(str_val == web_port);

Z
Zhiru Zhu 已提交
155
    std::string server_mode = "cluster_readonly";
C
Cai Yudong 已提交
156 157
    ASSERT_TRUE(config.SetServerConfigDeployMode(server_mode).ok());
    ASSERT_TRUE(config.GetServerConfigDeployMode(str_val).ok());
Z
Zhiru Zhu 已提交
158 159 160
    ASSERT_TRUE(str_val == server_mode);

    std::string server_time_zone = "UTC+6";
C
Cai Yudong 已提交
161 162
    ASSERT_TRUE(config.SetServerConfigTimeZone(server_time_zone).ok());
    ASSERT_TRUE(config.GetServerConfigTimeZone(str_val).ok());
Z
Zhiru Zhu 已提交
163 164 165 166
    ASSERT_TRUE(str_val == server_time_zone);

    /* db config */
    std::string db_backend_url = "mysql://root:123456@127.0.0.1:19530/milvus";
C
Cai Yudong 已提交
167 168
    ASSERT_TRUE(config.SetDBConfigBackendUrl(db_backend_url).ok());
    ASSERT_TRUE(config.GetDBConfigBackendUrl(str_val).ok());
Z
Zhiru Zhu 已提交
169 170
    ASSERT_TRUE(str_val == db_backend_url);

Y
yudong.cai 已提交
171
    int64_t db_archive_disk_threshold = 100;
C
Cai Yudong 已提交
172 173
    ASSERT_TRUE(config.SetDBConfigArchiveDiskThreshold(std::to_string(db_archive_disk_threshold)).ok());
    ASSERT_TRUE(config.GetDBConfigArchiveDiskThreshold(int64_val).ok());
Y
yudong.cai 已提交
174
    ASSERT_TRUE(int64_val == db_archive_disk_threshold);
Z
Zhiru Zhu 已提交
175

Y
yudong.cai 已提交
176
    int64_t db_archive_days_threshold = 365;
C
Cai Yudong 已提交
177 178
    ASSERT_TRUE(config.SetDBConfigArchiveDaysThreshold(std::to_string(db_archive_days_threshold)).ok());
    ASSERT_TRUE(config.GetDBConfigArchiveDaysThreshold(int64_val).ok());
Y
yudong.cai 已提交
179
    ASSERT_TRUE(int64_val == db_archive_days_threshold);
Z
Zhiru Zhu 已提交
180

181 182 183 184 185
    int64_t db_auto_flush_interval = 1;
    ASSERT_TRUE(config.SetDBConfigAutoFlushInterval(std::to_string(db_auto_flush_interval)).ok());
    ASSERT_TRUE(config.GetDBConfigAutoFlushInterval(int64_val).ok());
    ASSERT_TRUE(int64_val == db_auto_flush_interval);

C
Cai Yudong 已提交
186
    /* storage config */
187 188 189 190 191 192 193 194 195 196
    std::string storage_primary_path = "/home/zilliz";
    ASSERT_TRUE(config.SetStorageConfigPrimaryPath(storage_primary_path).ok());
    ASSERT_TRUE(config.GetStorageConfigPrimaryPath(str_val).ok());
    ASSERT_TRUE(str_val == storage_primary_path);

    std::string storage_secondary_path = "/home/zilliz";
    ASSERT_TRUE(config.SetStorageConfigSecondaryPath(storage_secondary_path).ok());
    ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok());
    ASSERT_TRUE(str_val == storage_secondary_path);

197 198 199 200 201 202 203 204 205 206
    storage_secondary_path = "/home/zilliz,/tmp/milvus";
    ASSERT_TRUE(config.SetStorageConfigSecondaryPath(storage_secondary_path).ok());
    ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok());
    ASSERT_TRUE(str_val == storage_secondary_path);

    storage_secondary_path = "";
    ASSERT_TRUE(config.SetStorageConfigSecondaryPath(storage_secondary_path).ok());
    ASSERT_TRUE(config.GetStorageConfigSecondaryPath(str_val).ok());
    ASSERT_TRUE(str_val == storage_secondary_path);

C
Cai Yudong 已提交
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
//    bool storage_s3_enable = true;
//    ASSERT_TRUE(config.SetStorageConfigS3Enable(std::to_string(storage_s3_enable)).ok());
//    ASSERT_TRUE(config.GetStorageConfigS3Enable(bool_val).ok());
//    ASSERT_TRUE(bool_val == storage_s3_enable);
//
//    std::string storage_s3_addr = "192.168.1.100";
//    ASSERT_TRUE(config.SetStorageConfigS3Address(storage_s3_addr).ok());
//    ASSERT_TRUE(config.GetStorageConfigS3Address(str_val).ok());
//    ASSERT_TRUE(str_val == storage_s3_addr);
//
//    std::string storage_s3_port = "12345";
//    ASSERT_TRUE(config.SetStorageConfigS3Port(storage_s3_port).ok());
//    ASSERT_TRUE(config.GetStorageConfigS3Port(str_val).ok());
//    ASSERT_TRUE(str_val == storage_s3_port);
//
//    std::string storage_s3_access_key = "minioadmin";
//    ASSERT_TRUE(config.SetStorageConfigS3AccessKey(storage_s3_access_key).ok());
//    ASSERT_TRUE(config.GetStorageConfigS3AccessKey(str_val).ok());
//    ASSERT_TRUE(str_val == storage_s3_access_key);
//
//    std::string storage_s3_secret_key = "minioadmin";
//    ASSERT_TRUE(config.SetStorageConfigS3SecretKey(storage_s3_secret_key).ok());
//    ASSERT_TRUE(config.GetStorageConfigS3SecretKey(str_val).ok());
//    ASSERT_TRUE(str_val == storage_s3_secret_key);
//
//    std::string storage_s3_bucket = "s3bucket";
//    ASSERT_TRUE(config.SetStorageConfigS3Bucket(storage_s3_bucket).ok());
//    ASSERT_TRUE(config.GetStorageConfigS3Bucket(str_val).ok());
//    ASSERT_TRUE(str_val == storage_s3_bucket);
C
Cai Yudong 已提交
236

Z
Zhiru Zhu 已提交
237 238
    /* metric config */
    bool metric_enable_monitor = false;
C
Cai Yudong 已提交
239 240
    ASSERT_TRUE(config.SetMetricConfigEnableMonitor(std::to_string(metric_enable_monitor)).ok());
    ASSERT_TRUE(config.GetMetricConfigEnableMonitor(bool_val).ok());
Z
Zhiru Zhu 已提交
241 242
    ASSERT_TRUE(bool_val == metric_enable_monitor);

C
Cai Yudong 已提交
243 244 245 246
    std::string metric_address = "192.168.0.2";
    ASSERT_TRUE(config.SetMetricConfigAddress(metric_address).ok());
    ASSERT_TRUE(config.GetMetricConfigAddress(str_val).ok());
    ASSERT_TRUE(str_val == metric_address);
Z
Zhiru Zhu 已提交
247

C
Cai Yudong 已提交
248 249 250 251
    std::string metric_port = "2222";
    ASSERT_TRUE(config.SetMetricConfigPort(metric_port).ok());
    ASSERT_TRUE(config.GetMetricConfigPort(str_val).ok());
    ASSERT_TRUE(str_val == metric_port);
Z
Zhiru Zhu 已提交
252 253

    /* cache config */
Y
yukun 已提交
254
    int64_t cache_cpu_cache_capacity = 1;
C
Cai Yudong 已提交
255 256
    ASSERT_TRUE(config.SetCacheConfigCpuCacheCapacity(std::to_string(cache_cpu_cache_capacity)).ok());
    ASSERT_TRUE(config.GetCacheConfigCpuCacheCapacity(int64_val).ok());
Z
Zhiru Zhu 已提交
257 258 259
    ASSERT_TRUE(int64_val == cache_cpu_cache_capacity);

    float cache_cpu_cache_threshold = 0.1;
C
Cai Yudong 已提交
260 261
    ASSERT_TRUE(config.SetCacheConfigCpuCacheThreshold(std::to_string(cache_cpu_cache_threshold)).ok());
    ASSERT_TRUE(config.GetCacheConfigCpuCacheThreshold(float_val).ok());
Z
Zhiru Zhu 已提交
262 263
    ASSERT_TRUE(float_val == cache_cpu_cache_threshold);

264 265 266 267 268
    int64_t cache_insert_buffer_size = 2;
    ASSERT_TRUE(config.SetCacheConfigInsertBufferSize(std::to_string(cache_insert_buffer_size)).ok());
    ASSERT_TRUE(config.GetCacheConfigInsertBufferSize(int64_val).ok());
    ASSERT_TRUE(int64_val == cache_insert_buffer_size);

Z
Zhiru Zhu 已提交
269
    bool cache_insert_data = true;
C
Cai Yudong 已提交
270 271
    ASSERT_TRUE(config.SetCacheConfigCacheInsertData(std::to_string(cache_insert_data)).ok());
    ASSERT_TRUE(config.GetCacheConfigCacheInsertData(bool_val).ok());
Z
Zhiru Zhu 已提交
272 273 274
    ASSERT_TRUE(bool_val == cache_insert_data);

    /* engine config */
Y
yudong.cai 已提交
275
    int64_t engine_use_blas_threshold = 50;
C
Cai Yudong 已提交
276 277
    ASSERT_TRUE(config.SetEngineConfigUseBlasThreshold(std::to_string(engine_use_blas_threshold)).ok());
    ASSERT_TRUE(config.GetEngineConfigUseBlasThreshold(int64_val).ok());
Y
yudong.cai 已提交
278
    ASSERT_TRUE(int64_val == engine_use_blas_threshold);
Z
Zhiru Zhu 已提交
279

Y
yukun 已提交
280
    int64_t engine_omp_thread_num = 1;
C
Cai Yudong 已提交
281 282
    ASSERT_TRUE(config.SetEngineConfigOmpThreadNum(std::to_string(engine_omp_thread_num)).ok());
    ASSERT_TRUE(config.GetEngineConfigOmpThreadNum(int64_val).ok());
Y
yudong.cai 已提交
283
    ASSERT_TRUE(int64_val == engine_omp_thread_num);
Z
Zhiru Zhu 已提交
284

F
feisiyicl 已提交
285 286 287 288
    std::string engine_simd_type = "sse";
    ASSERT_TRUE(config.SetEngineConfigSimdType(engine_simd_type).ok());
    ASSERT_TRUE(config.GetEngineConfigSimdType(str_val).ok());
    ASSERT_TRUE(str_val == engine_simd_type);
C
Cai Yudong 已提交
289

G
groot 已提交
290
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
291
    int64_t engine_gpu_search_threshold = 800;
C
Cai Yudong 已提交
292 293
    ASSERT_TRUE(config.SetEngineConfigGpuSearchThreshold(std::to_string(engine_gpu_search_threshold)).ok());
    ASSERT_TRUE(config.GetEngineConfigGpuSearchThreshold(int64_val).ok());
Y
yudong.cai 已提交
294
    ASSERT_TRUE(int64_val == engine_gpu_search_threshold);
C
Cai Yudong 已提交
295
#endif
Z
Zhiru Zhu 已提交
296

Y
yudong.cai 已提交
297
    /* gpu resource config */
C
Cai Yudong 已提交
298
#ifdef MILVUS_GPU_VERSION
Y
yudong.cai 已提交
299
    bool resource_enable_gpu = true;
C
Cai Yudong 已提交
300 301
    ASSERT_TRUE(config.SetGpuResourceConfigEnable(std::to_string(resource_enable_gpu)).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigEnable(bool_val).ok());
Y
yudong.cai 已提交
302
    ASSERT_TRUE(bool_val == resource_enable_gpu);
Z
Zhiru Zhu 已提交
303

Y
yudong.cai 已提交
304
    int64_t gpu_cache_capacity = 1;
C
Cai Yudong 已提交
305 306
    ASSERT_TRUE(config.SetGpuResourceConfigCacheCapacity(std::to_string(gpu_cache_capacity)).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigCacheCapacity(int64_val).ok());
Y
yudong.cai 已提交
307 308 309
    ASSERT_TRUE(int64_val == gpu_cache_capacity);

    float gpu_cache_threshold = 0.2;
C
Cai Yudong 已提交
310 311
    ASSERT_TRUE(config.SetGpuResourceConfigCacheThreshold(std::to_string(gpu_cache_threshold)).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigCacheThreshold(float_val).ok());
Y
yudong.cai 已提交
312 313 314
    ASSERT_TRUE(float_val == gpu_cache_threshold);

    std::vector<std::string> search_resources = {"gpu0"};
Y
yudong.cai 已提交
315
    std::vector<int64_t> search_res_vec;
316
    std::string search_res_str;
Z
Zhiru Zhu 已提交
317
    milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
Y
yudong.cai 已提交
318
        search_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, search_res_str);
C
Cai Yudong 已提交
319 320
    ASSERT_TRUE(config.SetGpuResourceConfigSearchResources(search_res_str).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigSearchResources(search_res_vec).ok());
Z
Zhiru Zhu 已提交
321
    for (size_t i = 0; i < search_resources.size(); i++) {
Y
yudong.cai 已提交
322
        ASSERT_TRUE(std::stoll(search_resources[i].substr(3)) == search_res_vec[i]);
Z
Zhiru Zhu 已提交
323 324
    }

Y
yudong.cai 已提交
325
    std::vector<std::string> build_index_resources = {"gpu0"};
Y
yudong.cai 已提交
326
    std::vector<int64_t> build_index_res_vec;
Y
yudong.cai 已提交
327
    std::string build_index_res_str;
328
    milvus::server::StringHelpFunctions::MergeStringWithDelimeter(
Y
yudong.cai 已提交
329
        build_index_resources, milvus::server::CONFIG_GPU_RESOURCE_DELIMITER, build_index_res_str);
C
Cai Yudong 已提交
330 331
    ASSERT_TRUE(config.SetGpuResourceConfigBuildIndexResources(build_index_res_str).ok());
    ASSERT_TRUE(config.GetGpuResourceConfigBuildIndexResources(build_index_res_vec).ok());
Y
yudong.cai 已提交
332
    for (size_t i = 0; i < build_index_resources.size(); i++) {
Y
yudong.cai 已提交
333
        ASSERT_TRUE(std::stoll(build_index_resources[i].substr(3)) == build_index_res_vec[i]);
334
    }
Y
yudong.cai 已提交
335
#endif
J
Jin Hai 已提交
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356

    /* wal config */
    bool wal_enable = false;
    ASSERT_TRUE(config.SetWalConfigEnable(std::to_string(wal_enable)).ok());
    ASSERT_TRUE(config.GetWalConfigEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == wal_enable);

    bool wal_recovery_ignore = true;
    ASSERT_TRUE(config.SetWalConfigRecoveryErrorIgnore(std::to_string(wal_recovery_ignore)).ok());
    ASSERT_TRUE(config.GetWalConfigRecoveryErrorIgnore(bool_val).ok());
    ASSERT_TRUE(bool_val == wal_recovery_ignore);

    int64_t wal_buffer_size = 128;
    ASSERT_TRUE(config.SetWalConfigBufferSize(std::to_string(wal_buffer_size)).ok());
    ASSERT_TRUE(config.GetWalConfigBufferSize(int64_val).ok());
    ASSERT_TRUE(int64_val == wal_buffer_size);

    std::string wal_path = "/tmp/aaa/wal";
    ASSERT_TRUE(config.SetWalConfigWalPath(wal_path).ok());
    ASSERT_TRUE(config.GetWalConfigWalPath(str_val).ok());
    ASSERT_TRUE(str_val == wal_path);
C
Cai Yudong 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402

    /* logs config */
    bool logs_trace_enable = false;
    ASSERT_TRUE(config.SetLogsTraceEnable(std::to_string(logs_trace_enable)).ok());
    ASSERT_TRUE(config.GetLogsTraceEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == logs_trace_enable);

    bool logs_debug_enable = false;
    ASSERT_TRUE(config.SetLogsDebugEnable(std::to_string(logs_debug_enable)).ok());
    ASSERT_TRUE(config.GetLogsDebugEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == logs_debug_enable);

    bool logs_info_enable = false;
    ASSERT_TRUE(config.SetLogsTraceEnable(std::to_string(logs_info_enable)).ok());
    ASSERT_TRUE(config.GetLogsTraceEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == logs_info_enable);

    bool logs_warning_enable = false;
    ASSERT_TRUE(config.SetLogsDebugEnable(std::to_string(logs_warning_enable)).ok());
    ASSERT_TRUE(config.GetLogsDebugEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == logs_warning_enable);

    bool logs_error_enable = false;
    ASSERT_TRUE(config.SetLogsTraceEnable(std::to_string(logs_error_enable)).ok());
    ASSERT_TRUE(config.GetLogsTraceEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == logs_error_enable);

    bool logs_fatal_enable = false;
    ASSERT_TRUE(config.SetLogsDebugEnable(std::to_string(logs_fatal_enable)).ok());
    ASSERT_TRUE(config.GetLogsDebugEnable(bool_val).ok());
    ASSERT_TRUE(bool_val == logs_fatal_enable);

    std::string logs_path = "/tmp/aaa/logs";
    ASSERT_TRUE(config.SetLogsPath(logs_path).ok());
    ASSERT_TRUE(config.GetLogsPath(str_val).ok());
    ASSERT_TRUE(str_val == logs_path);

    int64_t logs_max_log_file_size = 1000;
    ASSERT_TRUE(config.SetLogsMaxLogFileSize(std::to_string(logs_max_log_file_size)).ok());
    ASSERT_TRUE(config.GetLogsMaxLogFileSize(int64_val).ok());
    ASSERT_TRUE(int64_val == logs_max_log_file_size);

    int64_t logs_log_rotate_num = 100;
    ASSERT_TRUE(config.SetLogsLogRotateNum(std::to_string(logs_log_rotate_num)).ok());
    ASSERT_TRUE(config.GetLogsLogRotateNum(int64_val).ok());
    ASSERT_TRUE(int64_val == logs_log_rotate_num);
Z
Zhiru Zhu 已提交
403 404
}

405 406
std::string
gen_get_command(const std::string& parent_node, const std::string& child_node) {
407
    std::string cmd = "get_config " + parent_node + ms::CONFIG_NODE_DELIMITER + child_node;
C
Cai Yudong 已提交
408 409 410
    return cmd;
}

411 412
std::string
gen_set_command(const std::string& parent_node, const std::string& child_node, const std::string& value) {
413
    std::string cmd = "set_config " + parent_node + ms::CONFIG_NODE_DELIMITER + child_node + " " + value;
C
Cai Yudong 已提交
414 415 416 417
    return cmd;
}

TEST_F(ConfigTest, SERVER_CONFIG_CLI_TEST) {
C
Cai Yudong 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
    std::string conf_file = std::string(CONFIG_PATH) + VALID_CONFIG_FILE;
    milvus::server::Config& config = milvus::server::Config::GetInstance();

    auto s = config.LoadConfigFile(conf_file);
    ASSERT_TRUE(s.ok()) << s.message();
    s = config.ResetDefaultConfig();
    ASSERT_TRUE(s.ok());

    std::string get_cmd, set_cmd;
    std::string result, dummy;

    s = config.ProcessConfigCli(result, "get_config *");
    ASSERT_TRUE(s.ok());

    /* server config */
    std::string server_addr = "192.168.1.155";
    get_cmd = gen_get_command(ms::CONFIG_SERVER, ms::CONFIG_SERVER_ADDRESS);
    set_cmd = gen_set_command(ms::CONFIG_SERVER, ms::CONFIG_SERVER_ADDRESS, server_addr);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

    /* db config */
    std::string db_backend_url = "sqlite://milvus:zilliz@:/";
    get_cmd = gen_get_command(ms::CONFIG_DB, ms::CONFIG_DB_BACKEND_URL);
    set_cmd = gen_set_command(ms::CONFIG_DB, ms::CONFIG_DB_BACKEND_URL, db_backend_url);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

    /* metric config */
    std::string metric_enable_monitor = "false";
    get_cmd = gen_get_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR);
    set_cmd = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, metric_enable_monitor);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

    /* storage config */
    std::string storage_primary_path = "/tmp/milvus1";
    get_cmd = gen_get_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_PRIMARY_PATH);
    set_cmd = gen_set_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_PRIMARY_PATH, storage_primary_path);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

    /* cache config */
    std::string cache_cpu_cache_capacity = "1";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_CAPACITY);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_CAPACITY, cache_cpu_cache_capacity);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == cache_cpu_cache_capacity);

    std::string cache_cpu_cache_threshold = "0.1";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CPU_CACHE_THRESHOLD, cache_cpu_cache_threshold);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == cache_cpu_cache_threshold);

    std::string cache_insert_buffer_size = "1";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE, cache_insert_buffer_size);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == cache_insert_buffer_size);

    std::string cache_insert_data = "true";
    get_cmd = gen_get_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CACHE_INSERT_DATA);
    set_cmd = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_CACHE_INSERT_DATA, cache_insert_data);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == cache_insert_data);

    /* engine config */
    std::string engine_use_blas_threshold = "50";
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_USE_BLAS_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_USE_BLAS_THRESHOLD, engine_use_blas_threshold);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_use_blas_threshold);

    std::string engine_omp_thread_num = "1";
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_OMP_THREAD_NUM);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_OMP_THREAD_NUM, engine_omp_thread_num);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_omp_thread_num);

    std::string engine_simd_type = "sse";
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_SIMD_TYPE);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_SIMD_TYPE, engine_simd_type);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_simd_type);

#ifdef MILVUS_GPU_VERSION
    std::string engine_gpu_search_threshold = "800";
    get_cmd = gen_get_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_GPU_SEARCH_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_ENGINE, ms::CONFIG_ENGINE_GPU_SEARCH_THRESHOLD, engine_gpu_search_threshold);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == engine_gpu_search_threshold);
#endif

    /* gpu resource config */
#ifdef MILVUS_GPU_VERSION
    std::string resource_enable_gpu = "true";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_ENABLE);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_ENABLE, resource_enable_gpu);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == resource_enable_gpu);

    std::string gpu_cache_capacity = "1";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_CAPACITY);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_CAPACITY, gpu_cache_capacity);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == gpu_cache_capacity);

    std::string gpu_cache_threshold = "0.2";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_THRESHOLD);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_CACHE_THRESHOLD, gpu_cache_threshold);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == gpu_cache_threshold);

    std::string search_resources = "gpu0";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_SEARCH_RESOURCES);
    set_cmd = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_SEARCH_RESOURCES, search_resources);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == search_resources);

    std::string build_index_resources = "gpu0";
    get_cmd = gen_get_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES);
    set_cmd =
      gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, build_index_resources);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
    ASSERT_TRUE(result == build_index_resources);
#endif

    /* wal config */
    std::string wal_path = "/tmp/aaa/wal";
    get_cmd = gen_get_command(ms::CONFIG_WAL, ms::CONFIG_WAL_WAL_PATH);
    set_cmd = gen_set_command(ms::CONFIG_WAL, ms::CONFIG_WAL_WAL_PATH, wal_path);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());

    /* logs config */
    std::string logs_path = "/tmp/aaa/logs";
    get_cmd = gen_get_command(ms::CONFIG_LOGS, ms::CONFIG_LOGS_PATH);
    set_cmd = gen_set_command(ms::CONFIG_LOGS, ms::CONFIG_LOGS_PATH, logs_path);
    s = config.ProcessConfigCli(dummy, set_cmd);
    ASSERT_TRUE(s.ok());
    s = config.ProcessConfigCli(result, get_cmd);
    ASSERT_TRUE(s.ok());
C
Cai Yudong 已提交
610 611
}

Z
Zhiru Zhu 已提交
612 613 614 615 616
TEST_F(ConfigTest, SERVER_CONFIG_INVALID_TEST) {
    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s;

C
Cai Yudong 已提交
617
    ASSERT_FALSE(config.LoadConfigFile("").ok());
Z
Zhiru Zhu 已提交
618

C
Cai Yudong 已提交
619 620
    ASSERT_FALSE(config.LoadConfigFile(config_path + INVALID_CONFIG_FILE).ok());
    ASSERT_FALSE(config.LoadConfigFile(config_path + "dummy.yaml").ok());
Z
Zhiru Zhu 已提交
621 622

    /* server config */
C
Cai Yudong 已提交
623 624
    ASSERT_FALSE(config.SetServerConfigAddress("0.0.0").ok());
    ASSERT_FALSE(config.SetServerConfigAddress("0.0.0.256").ok());
Z
Zhiru Zhu 已提交
625

C
Cai Yudong 已提交
626 627
    ASSERT_FALSE(config.SetServerConfigPort("a").ok());
    ASSERT_FALSE(config.SetServerConfigPort("99999").ok());
Z
Zhiru Zhu 已提交
628

B
BossZou 已提交
629 630 631 632
    ASSERT_FALSE(config.SetServerConfigWebPort("a").ok());
    ASSERT_FALSE(config.SetServerConfigWebPort("99999").ok());
    ASSERT_FALSE(config.SetServerConfigWebPort("-1").ok());

C
Cai Yudong 已提交
633
    ASSERT_FALSE(config.SetServerConfigDeployMode("cluster").ok());
Z
Zhiru Zhu 已提交
634

C
Cai Yudong 已提交
635 636 637
    ASSERT_FALSE(config.SetServerConfigTimeZone("GM").ok());
    ASSERT_FALSE(config.SetServerConfigTimeZone("GMT8").ok());
    ASSERT_FALSE(config.SetServerConfigTimeZone("UTCA").ok());
Z
Zhiru Zhu 已提交
638 639

    /* db config */
C
Cai Yudong 已提交
640 641 642
    ASSERT_FALSE(config.SetDBConfigBackendUrl("http://www.google.com").ok());
    ASSERT_FALSE(config.SetDBConfigBackendUrl("sqlite://:@:").ok());
    ASSERT_FALSE(config.SetDBConfigBackendUrl("mysql://root:123456@127.0.0.1/milvus").ok());
Z
Zhiru Zhu 已提交
643

C
Cai Yudong 已提交
644
    ASSERT_FALSE(config.SetDBConfigArchiveDiskThreshold("0x10").ok());
Z
Zhiru Zhu 已提交
645

C
Cai Yudong 已提交
646
    ASSERT_FALSE(config.SetDBConfigArchiveDaysThreshold("0x10").ok());
Z
Zhiru Zhu 已提交
647

648 649
    ASSERT_FALSE(config.SetDBConfigAutoFlushInterval("0.1").ok());

C
Cai Yudong 已提交
650
    /* storage config */
651
    ASSERT_FALSE(config.SetStorageConfigPrimaryPath("").ok());
652 653 654 655
    ASSERT_FALSE(config.SetStorageConfigPrimaryPath("./milvus").ok());
    ASSERT_FALSE(config.SetStorageConfigPrimaryPath("../milvus").ok());
    ASSERT_FALSE(config.SetStorageConfigPrimaryPath("/**milvus").ok());
    ASSERT_FALSE(config.SetStorageConfigPrimaryPath("/milvus--/path").ok());
656

657 658
    ASSERT_FALSE(config.SetStorageConfigSecondaryPath("../milvus,./zilliz").ok());
    ASSERT_FALSE(config.SetStorageConfigSecondaryPath("/home/^^__^^,/zilliz").ok());
659

C
Cai Yudong 已提交
660 661 662 663 664 665 666 667 668 669 670 671
//    ASSERT_FALSE(config.SetStorageConfigS3Enable("10").ok());
//
//    ASSERT_FALSE(config.SetStorageConfigS3Address("127.0.0").ok());
//
//    ASSERT_FALSE(config.SetStorageConfigS3Port("100").ok());
//    ASSERT_FALSE(config.SetStorageConfigS3Port("100000").ok());
//
//    ASSERT_FALSE(config.SetStorageConfigS3AccessKey("").ok());
//
//    ASSERT_FALSE(config.SetStorageConfigS3SecretKey("").ok());
//
//    ASSERT_FALSE(config.SetStorageConfigS3Bucket("").ok());
Z
Zhiru Zhu 已提交
672 673

    /* metric config */
C
Cai Yudong 已提交
674
    ASSERT_FALSE(config.SetMetricConfigEnableMonitor("Y").ok());
Z
Zhiru Zhu 已提交
675

C
Cai Yudong 已提交
676
    ASSERT_FALSE(config.SetMetricConfigAddress("127.0.0").ok());
677

C
Cai Yudong 已提交
678
    ASSERT_FALSE(config.SetMetricConfigPort("0xff").ok());
Z
Zhiru Zhu 已提交
679 680

    /* cache config */
C
Cai Yudong 已提交
681 682 683
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("a").ok());
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("0").ok());
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("2048").ok());
684
    ASSERT_FALSE(config.SetCacheConfigCpuCacheCapacity("-1").ok());
Z
Zhiru Zhu 已提交
685

C
Cai Yudong 已提交
686 687
    ASSERT_FALSE(config.SetCacheConfigCpuCacheThreshold("a").ok());
    ASSERT_FALSE(config.SetCacheConfigCpuCacheThreshold("1.0").ok());
688 689 690 691 692 693
    ASSERT_FALSE(config.SetCacheConfigCpuCacheThreshold("-0.1").ok());

    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("a").ok());
    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("0").ok());
    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("2048").ok());
    ASSERT_FALSE(config.SetCacheConfigInsertBufferSize("-1").ok());
Z
Zhiru Zhu 已提交
694

C
Cai Yudong 已提交
695
    ASSERT_FALSE(config.SetCacheConfigCacheInsertData("N").ok());
Z
Zhiru Zhu 已提交
696 697

    /* engine config */
C
Cai Yudong 已提交
698
    ASSERT_FALSE(config.SetEngineConfigUseBlasThreshold("0xff").ok());
Z
Zhiru Zhu 已提交
699

C
Cai Yudong 已提交
700 701
    ASSERT_FALSE(config.SetEngineConfigOmpThreadNum("a").ok());
    ASSERT_FALSE(config.SetEngineConfigOmpThreadNum("10000").ok());
702
    ASSERT_FALSE(config.SetEngineConfigOmpThreadNum("-10").ok());
Z
Zhiru Zhu 已提交
703

F
feisiyicl 已提交
704
    ASSERT_FALSE(config.SetEngineConfigSimdType("None").ok());
C
Cai Yudong 已提交
705

G
groot 已提交
706
#ifdef MILVUS_GPU_VERSION
C
Cai Yudong 已提交
707 708
    ASSERT_FALSE(config.SetEngineConfigGpuSearchThreshold("-1").ok());
#endif
Z
Zhiru Zhu 已提交
709

G
groot 已提交
710
    /* gpu resource config */
C
Cai Yudong 已提交
711 712
#ifdef MILVUS_GPU_VERSION
    ASSERT_FALSE(config.SetGpuResourceConfigEnable("ok").ok());
Z
Zhiru Zhu 已提交
713

C
Cai Yudong 已提交
714 715
    ASSERT_FALSE(config.SetGpuResourceConfigCacheCapacity("a").ok());
    ASSERT_FALSE(config.SetGpuResourceConfigCacheCapacity("128").ok());
716
    ASSERT_FALSE(config.SetGpuResourceConfigCacheCapacity("-1").ok());
Z
Zhiru Zhu 已提交
717

C
Cai Yudong 已提交
718 719
    ASSERT_FALSE(config.SetGpuResourceConfigCacheThreshold("a").ok());
    ASSERT_FALSE(config.SetGpuResourceConfigCacheThreshold("1.0").ok());
720
    ASSERT_FALSE(config.SetGpuResourceConfigCacheThreshold("-0.1").ok());
Z
Zhiru Zhu 已提交
721

C
Cai Yudong 已提交
722
    ASSERT_FALSE(config.SetGpuResourceConfigSearchResources("gpu10").ok());
B
BossZou 已提交
723
    ASSERT_FALSE(config.SetGpuResourceConfigSearchResources("gpu0, gpu0").ok());
724

C
Cai Yudong 已提交
725 726
    ASSERT_FALSE(config.SetGpuResourceConfigBuildIndexResources("gup2").ok());
    ASSERT_FALSE(config.SetGpuResourceConfigBuildIndexResources("gpu16").ok());
B
BossZou 已提交
727
    ASSERT_FALSE(config.SetGpuResourceConfigBuildIndexResources("gpu0, gpu0, gpu1").ok());
Y
yudong.cai 已提交
728
#endif
J
Jin Hai 已提交
729 730 731 732 733 734

    /* wal config */
    ASSERT_FALSE(config.SetWalConfigWalPath("hello/world").ok());
    ASSERT_FALSE(config.SetWalConfigWalPath("").ok());
    ASSERT_FALSE(config.SetWalConfigBufferSize("-1").ok());
    ASSERT_FALSE(config.SetWalConfigBufferSize("a").ok());
C
Cai Yudong 已提交
735 736 737 738 739 740 741 742 743 744 745 746 747

    /* wal config */
    ASSERT_FALSE(config.SetLogsTraceEnable("invalid").ok());
    ASSERT_FALSE(config.SetLogsDebugEnable("invalid").ok());
    ASSERT_FALSE(config.SetLogsInfoEnable("invalid").ok());
    ASSERT_FALSE(config.SetLogsWarningEnable("invalid").ok());
    ASSERT_FALSE(config.SetLogsErrorEnable("invalid").ok());
    ASSERT_FALSE(config.SetLogsFatalEnable("invalid").ok());
    ASSERT_FALSE(config.SetLogsPath("").ok());
    ASSERT_FALSE(config.SetLogsMaxLogFileSize("-1").ok());
    ASSERT_FALSE(config.SetLogsMaxLogFileSize("511").ok());
    ASSERT_FALSE(config.SetLogsLogRotateNum("-1").ok());
    ASSERT_FALSE(config.SetLogsLogRotateNum("1025").ok());
Z
Zhiru Zhu 已提交
748 749
}

S
starlord 已提交
750
TEST_F(ConfigTest, SERVER_CONFIG_TEST) {
S
starlord 已提交
751
    std::string config_path(CONFIG_PATH);
S
starlord 已提交
752
    milvus::server::Config& config = milvus::server::Config::GetInstance();
G
groot 已提交
753

C
Cai Yudong 已提交
754 755 756
    ASSERT_TRUE(config.LoadConfigFile(config_path + VALID_CONFIG_FILE).ok());

    ASSERT_TRUE(config.ValidateConfig().ok());
S
starlord 已提交
757

758 759 760
    std::string config_json_str;
    config.GetConfigJsonStr(config_json_str);
    std::cout << config_json_str << std::endl;
Y
yudong.cai 已提交
761

C
Cai Yudong 已提交
762
    ASSERT_TRUE(config.ResetDefaultConfig().ok());
S
starlord 已提交
763
}
S
shengjh 已提交
764 765 766 767 768 769 770 771 772

TEST_F(ConfigTest, SERVER_CONFIG_VALID_FAIL_TEST) {
    fiu_init(0);

    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s = config.LoadConfigFile(config_path + VALID_CONFIG_FILE);
    ASSERT_TRUE(s.ok());

Y
yudong.cai 已提交
773 774 775 776
    fiu_enable("check_config_version_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_version_fail");
S
shengjh 已提交
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863

    /* server config */
    fiu_enable("check_config_address_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_address_fail");

    fiu_enable("check_config_port_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_port_fail");

    fiu_enable("check_config_deploy_mode_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_deploy_mode_fail");

    fiu_enable("check_config_time_zone_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_time_zone_fail");

    /* db config */
    fiu_enable("check_config_primary_path_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_primary_path_fail");

    fiu_enable("check_config_secondary_path_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_secondary_path_fail");

    fiu_enable("check_config_backend_url_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_backend_url_fail");

    fiu_enable("check_config_archive_disk_threshold_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_archive_disk_threshold_fail");

    fiu_enable("check_config_archive_days_threshold_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_archive_days_threshold_fail");

    fiu_enable("check_config_insert_buffer_size_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_insert_buffer_size_fail");

    /* metric config */

    fiu_enable("check_config_enable_monitor_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_enable_monitor_fail");

    /* cache config */
    fiu_enable("check_config_cpu_cache_capacity_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_cpu_cache_capacity_fail");

    fiu_enable("check_config_cpu_cache_threshold_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_cpu_cache_threshold_fail");

    fiu_enable("check_config_cache_insert_data_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_cache_insert_data_fail");

    /* engine config */
    fiu_enable("check_config_use_blas_threshold_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_use_blas_threshold_fail");

    fiu_enable("check_config_omp_thread_num_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_omp_thread_num_fail");

F
feisiyicl 已提交
864 865 866 867 868
    fiu_enable("check_config_simd_type_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_simd_type_fail");

S
shengjh 已提交
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950
#ifdef MILVUS_GPU_VERSION
    fiu_enable("check_config_gpu_search_threshold_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_search_threshold_fail");

    fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_enable_fail");

    fiu_enable("check_gpu_resource_config_cache_capacity_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_gpu_resource_config_cache_capacity_fail");

    fiu_enable("check_config_gpu_resource_cache_threshold_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_cache_threshold_fail");

    fiu_enable("check_gpu_resource_config_search_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_gpu_resource_config_search_fail");

    fiu_enable("check_gpu_resource_config_build_index_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_gpu_resource_config_build_index_fail");
#endif

    fiu_enable("get_config_json_config_path_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("get_config_json_config_path_fail");

    s = config.ValidateConfig();
    ASSERT_TRUE(s.ok());

#ifdef MILVUS_GPU_VERSION
    std::vector<int64_t> empty_value;
    fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0);
    empty_value.clear();
    s = config.GetGpuResourceConfigBuildIndexResources(empty_value);
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_enable_fail");

    fiu_enable("get_gpu_config_build_index_resources.disable_gpu_resource_fail", 1, NULL, 0);
    empty_value.clear();
    s = config.GetGpuResourceConfigBuildIndexResources(empty_value);
    ASSERT_FALSE(s.ok());
    fiu_disable("get_gpu_config_build_index_resources.disable_gpu_resource_fail");

    fiu_enable("get_gpu_config_search_resources.disable_gpu_resource_fail", 1, NULL, 0);
    empty_value.clear();
    s = config.GetGpuResourceConfigSearchResources(empty_value);
    ASSERT_FALSE(s.ok());
    fiu_disable("get_gpu_config_search_resources.disable_gpu_resource_fail");

    fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0);
    empty_value.clear();
    s = config.GetGpuResourceConfigSearchResources(empty_value);
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_enable_fail");

    int64_t value;
    fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0);
    s = config.GetGpuResourceConfigCacheCapacity(value);
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_enable_fail");

    fiu_enable("Config.GetGpuResourceConfigCacheCapacity.diable_gpu_resource", 1, NULL, 0);
    s = config.GetGpuResourceConfigCacheCapacity(value);
    ASSERT_FALSE(s.ok());
    fiu_disable("Config.GetGpuResourceConfigCacheCapacity.diable_gpu_resource");

    fiu_enable("ValidationUtil.GetGpuMemory.return_error", 1, NULL, 0);
    s = config.GetGpuResourceConfigCacheCapacity(value);
    ASSERT_FALSE(s.ok());
    fiu_disable("ValidationUtil.GetGpuMemory.return_error");

T
Tinkerrr 已提交
951 952 953 954
    // fiu_enable("check_config_insert_buffer_size_fail", 1, NULL, 0);
    // s = config.GetCacheConfigCpuCacheCapacity(value);
    // ASSERT_FALSE(s.ok());
    // fiu_disable("check_config_insert_buffer_size_fail");
S
shengjh 已提交
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971

    fiu_enable("Config.CheckCacheConfigCpuCacheCapacity.large_insert_buffer", 1, NULL, 0);
    s = config.GetCacheConfigCpuCacheCapacity(value);
    ASSERT_FALSE(s.ok());
    fiu_disable("Config.CheckCacheConfigCpuCacheCapacity.large_insert_buffer");

    float f_value;
    fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0);
    s = config.GetGpuResourceConfigCacheThreshold(f_value);
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_enable_fail");

    fiu_enable("Config.GetGpuResourceConfigCacheThreshold.diable_gpu_resource", 1, NULL, 0);
    s = config.GetGpuResourceConfigCacheThreshold(f_value);
    ASSERT_FALSE(s.ok());
    fiu_disable("Config.GetGpuResourceConfigCacheThreshold.diable_gpu_resource");
#endif
J
Jin Hai 已提交
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992

    /* wal config */
    fiu_enable("check_config_wal_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_wal_enable_fail");

    fiu_enable("check_config_wal_recovery_error_ignore_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_wal_recovery_error_ignore_fail");

    fiu_enable("check_config_wal_buffer_size_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_wal_buffer_size_fail");

    fiu_enable("check_wal_path_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_wal_path_fail");
C
Cai Yudong 已提交
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038

    /* logs config */
    fiu_enable("check_logs_trace_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_trace_enable_fail");

    fiu_enable("check_logs_debug_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_debug_enable_fail");

    fiu_enable("check_logs_info_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_info_enable_fail");

    fiu_enable("check_logs_warning_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_warning_enable_fail");

    fiu_enable("check_logs_error_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_error_enable_fail");

    fiu_enable("check_logs_fatal_enable_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_fatal_enable_fail");

    fiu_enable("check_logs_path_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_path_fail");

    fiu_enable("check_logs_max_log_file_size_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_max_log_file_size_fail");

    fiu_enable("check_logs_log_rotate_num_fail", 1, NULL, 0);
    s = config.ValidateConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_log_rotate_num_fail");
S
shengjh 已提交
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
}

TEST_F(ConfigTest, SERVER_CONFIG_RESET_DEFAULT_CONFIG_FAIL_TEST) {
    fiu_init(0);

    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s = config.LoadConfigFile(config_path + VALID_CONFIG_FILE);
    ASSERT_TRUE(s.ok());

    s = config.ValidateConfig();
    ASSERT_TRUE(s.ok());

    /* server config */
    fiu_enable("check_config_address_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_address_fail");

    fiu_enable("check_config_port_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_port_fail");

    fiu_enable("check_config_deploy_mode_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_deploy_mode_fail");

    fiu_enable("check_config_time_zone_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_time_zone_fail");

    /* db config */
    fiu_enable("check_config_primary_path_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_primary_path_fail");

    fiu_enable("check_config_secondary_path_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_secondary_path_fail");

    fiu_enable("check_config_backend_url_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_backend_url_fail");

1089
    fiu_enable("check_config_preload_collection_fail", 1, NULL, 0);
1090 1091
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
1092
    fiu_disable("check_config_preload_collection_fail");
1093

S
shengjh 已提交
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103
    fiu_enable("check_config_archive_disk_threshold_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_archive_disk_threshold_fail");

    fiu_enable("check_config_archive_days_threshold_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_archive_days_threshold_fail");

1104 1105 1106 1107 1108
    fiu_enable("check_config_auto_flush_interval_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_auto_flush_interval_fail");

S
shengjh 已提交
1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
    fiu_enable("check_config_insert_buffer_size_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_insert_buffer_size_fail");

    /* metric config */

    fiu_enable("check_config_enable_monitor_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_enable_monitor_fail");

    /* cache config */
    fiu_enable("check_config_cpu_cache_capacity_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_cpu_cache_capacity_fail");

    fiu_enable("check_config_cpu_cache_threshold_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_cpu_cache_threshold_fail");

    fiu_enable("check_config_cache_insert_data_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_cache_insert_data_fail");

    /* engine config */
    fiu_enable("check_config_use_blas_threshold_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_use_blas_threshold_fail");

    fiu_enable("check_config_omp_thread_num_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_omp_thread_num_fail");

F
feisiyicl 已提交
1148 1149 1150 1151 1152
    fiu_enable("check_config_simd_type_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_simd_type_fail");

S
shengjh 已提交
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
#ifdef MILVUS_GPU_VERSION
    fiu_enable("check_config_gpu_search_threshold_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_search_threshold_fail");

    fiu_enable("check_config_gpu_resource_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_enable_fail");

    fiu_enable("check_gpu_resource_config_cache_capacity_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_gpu_resource_config_cache_capacity_fail");

    fiu_enable("check_config_gpu_resource_cache_threshold_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_gpu_resource_cache_threshold_fail");

    fiu_enable("check_gpu_resource_config_search_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_gpu_resource_config_search_fail");

    fiu_enable("check_gpu_resource_config_build_index_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_gpu_resource_config_build_index_fail");
#endif

    s = config.ResetDefaultConfig();
    ASSERT_TRUE(s.ok());
J
Jin Hai 已提交
1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207

    /* wal config */
    fiu_enable("check_config_wal_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_wal_enable_fail");

    fiu_enable("check_config_wal_recovery_error_ignore_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_wal_recovery_error_ignore_fail");

    fiu_enable("check_config_wal_buffer_size_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_config_wal_buffer_size_fail");

    fiu_enable("check_wal_path_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_wal_path_fail");
C
Cai Yudong 已提交
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253

    /* logs config */
    fiu_enable("check_logs_trace_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_trace_enable_fail");

    fiu_enable("check_logs_debug_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_debug_enable_fail");

    fiu_enable("check_logs_info_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_info_enable_fail");

    fiu_enable("check_logs_warning_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_warning_enable_fail");

    fiu_enable("check_logs_error_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_error_enable_fail");

    fiu_enable("check_logs_fatal_enable_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_fatal_enable_fail");

    fiu_enable("check_logs_path_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_path_fail");

    fiu_enable("check_logs_max_log_file_size_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_max_log_file_size_fail");

    fiu_enable("check_logs_log_rotate_num_fail", 1, NULL, 0);
    s = config.ResetDefaultConfig();
    ASSERT_FALSE(s.ok());
    fiu_disable("check_logs_log_rotate_num_fail");
S
shengjh 已提交
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
}

TEST_F(ConfigTest, SERVER_CONFIG_OTHER_CONFIGS_FAIL_TEST) {
    fiu_init(0);

    std::string config_path(CONFIG_PATH);
    milvus::server::Config& config = milvus::server::Config::GetInstance();
    milvus::Status s;

    std::string get_cmd, set_cmd;
    std::string result, dummy;

    s = config.ProcessConfigCli(result, "get_config");
    ASSERT_FALSE(s.ok());

    s = config.ProcessConfigCli(result, "get_config");
    ASSERT_FALSE(s.ok());

    s = config.ProcessConfigCli(result, "get_config 1");
    ASSERT_FALSE(s.ok());

    s = config.ProcessConfigCli(result, "get_config 1.1");
    ASSERT_FALSE(s.ok());

    std::string build_index_resources = "gpu0";

    set_cmd =
        gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, build_index_resources);
    std::cout << set_cmd << std::endl;

    s = config.ProcessConfigCli(dummy, set_cmd + " invalid");
    ASSERT_FALSE(s.ok());

    s = config.ProcessConfigCli(dummy, "set_config gpu_resource_config.build_index_resources.sss gpu0");
    ASSERT_FALSE(s.ok());

    s = config.ProcessConfigCli(dummy, "set_config gpu_resource_config_invalid.build_index_resources_invalid gpu0");
    ASSERT_FALSE(s.ok());

    s = config.ProcessConfigCli(dummy, "invalid_config gpu_resource_config.build_index_resources.sss gpu0");
    ASSERT_FALSE(s.ok());

#ifndef MILVUS_GPU_VERSION
1297 1298 1299
    s = config.ProcessConfigCli(
        dummy,
        gen_set_command(ms::CONFIG_TRACING, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, build_index_resources));
S
shengjh 已提交
1300 1301 1302
    ASSERT_FALSE(s.ok());
#endif
}
1303 1304 1305

TEST_F(ConfigTest, SERVER_CONFIG_UPDATE_TEST) {
    std::string conf_file = std::string(CONFIG_PATH) + VALID_CONFIG_FILE;
1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
    std::string yaml_value;
    std::string reply_set, reply_get;
    std::string cmd_set, cmd_get;

    auto lambda = [&conf_file](const std::string& key, const std::string& child_key,
        const std::string& default_value, std::string& value) {
        auto * ymgr = milvus::server::YamlConfigMgr::GetInstance();
        auto status = ymgr->LoadConfigFile(conf_file);

        if (status.ok())
            value = ymgr->GetRootNode().GetChild(key).GetValue(child_key, default_value);

        return status;
    };

1321 1322 1323 1324 1325
    milvus::server::Config& config = milvus::server::Config::GetInstance();

    auto status = config.LoadConfigFile(conf_file);
    ASSERT_TRUE(status.ok()) << status.message();

1326
    /* validate if setting config store in files */
1327
    // test numeric config value
1328 1329
    cmd_set = gen_set_command(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE, "2");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
1330

1331 1332 1333
    ASSERT_TRUE(lambda(ms::CONFIG_CACHE, ms::CONFIG_CACHE_INSERT_BUFFER_SIZE,
        ms::CONFIG_CACHE_INSERT_BUFFER_SIZE_DEFAULT, yaml_value).ok());
    ASSERT_EQ("2", yaml_value);
1334

1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
    // test boolean config value
    cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "True");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR,
        ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok());
    ASSERT_EQ("true", yaml_value);

    cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "On");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR,
        ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok());
    ASSERT_EQ("true", yaml_value);

    cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "False");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR,
        ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok());
    ASSERT_EQ("false", yaml_value);

    cmd_set = gen_set_command(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR, "Off");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_METRIC, ms::CONFIG_METRIC_ENABLE_MONITOR,
        ms::CONFIG_METRIC_ENABLE_MONITOR_DEFAULT, yaml_value).ok());
    ASSERT_EQ("false", yaml_value);
1359 1360

    // test path
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
    cmd_set = gen_set_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_PRIMARY_PATH, "/tmp/milvus_config_unittest");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_PRIMARY_PATH,
        ms::CONFIG_STORAGE_PRIMARY_PATH_DEFAULT, yaml_value).ok());
    ASSERT_EQ("/tmp/milvus_config_unittest", yaml_value);

    cmd_set = gen_set_command(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_SECONDARY_PATH, "/home/zilliz,/home/milvus");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_STORAGE, ms::CONFIG_STORAGE_SECONDARY_PATH,
        ms::CONFIG_STORAGE_SECONDARY_PATH_DEFAULT, yaml_value).ok());
    ASSERT_EQ("/home/zilliz,/home/milvus", yaml_value);
1372 1373

#ifdef MILVUS_GPU_VERSION
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
    cmd_set = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, "gpu0");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES,
        ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT, yaml_value).ok());
    ASSERT_EQ("gpu0", yaml_value);

    cmd_set = gen_set_command(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES, "GPU0");
    ASSERT_TRUE(config.ProcessConfigCli(reply_set, cmd_set).ok());
    ASSERT_TRUE(lambda(ms::CONFIG_GPU_RESOURCE, ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES,
        ms::CONFIG_GPU_RESOURCE_BUILD_INDEX_RESOURCES_DEFAULT, yaml_value).ok());
    ASSERT_EQ("gpu0", yaml_value);
1385 1386
#endif
}