Skip to content

Commit a222214

Browse files
committed
TST: add config set and get test case
1 parent 608ae77 commit a222214

2 files changed

Lines changed: 66 additions & 8 deletions

File tree

src/redis_cmd.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class CommandConfig : public Commander {
209209
} else if (args_.size() == 4 && sub_command == "set") {
210210
Status s = config->Set(svr, args_[2], args_[3]);
211211
if (!s.IsOK()) {
212-
*output = Redis::Error("ERR "+s.Msg());
212+
*output = Redis::Error("CONFIG SET '"+args_[2]+"' error: "+s.Msg());
213213
} else {
214214
*output = Redis::SimpleString("OK");
215215
}

tests/config_test.cc

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,94 @@
44
#include <vector>
55
#include <gtest/gtest.h>
66

7-
TEST(Config, Profiling) {
7+
TEST(Config, GetAndSet) {
88
const char *path = "test.conf";
99
Config config;
10-
Server srv(nullptr, &config);
1110

1211
config.Load(path);
13-
std::map<std::string, std::string> cases = {
12+
std::map<std::string, std::string> mutable_cases = {
13+
{"timeout" , "1000"},
14+
{"maxclients" , "2000"},
15+
{"max-backup-to-keep" , "32"},
16+
{"max-backup-keep-hours" , "4000"},
17+
{"requirepass" , "mytest_requirepass"},
18+
{"masterauth" , "mytest_masterauth"},
19+
{"compact-cron" , "1 2 3 4 5"},
20+
{"bgsave-cron" , "5 4 3 2 1"},
21+
{"max-io-mb" , "5000"},
22+
{"max-db-size" , "6000"},
23+
{"max-replication-mb" , "7000"},
24+
{"slave-serve-stale-data" , "no"},
25+
{"slave-read-only" , "no"},
26+
{"slave-priority" , "101"},
27+
{"slowlog-log-slower-than" , "1234"},
28+
{"slowlog-max-len" , "123"},
1429
{"profiling-sample-ratio" , "50"},
1530
{"profiling-sample-record-max-len" , "1"},
1631
{"profiling-sample-record-threshold-ms" , "50"},
1732
{"profiling-sample-commands" , "get,set"},
33+
34+
{"rocksdb.compression" , "no"},
35+
{"rocksdb.max_open_files" , "1234"},
36+
{"rocksdb.write_buffer_size" , "1234"},
37+
{"rocksdb.max_write_buffer_number" , "1"},
38+
{"rocksdb.max_background_compactions" , "2"},
39+
{"rocksdb.max_sub_compactions" , "3"},
40+
{"rocksdb.delayed_write_rate" , "1234"},
41+
{"rocksdb.stats_dump_period_sec" , "600"},
42+
{"rocksdb.compaction_readahead_size" , "1024"},
43+
{"rocksdb.level0_slowdown_writes_trigger" , "50"},
1844
};
1945
std::vector<std::string> values;
20-
for (const auto &iter : cases) {
21-
config.Set(&srv, iter.first, iter.second);
46+
for (const auto &iter : mutable_cases) {
47+
auto s = config.Set(nullptr, iter.first, iter.second);
48+
ASSERT_TRUE(s.IsOK());
2249
config.Get(iter.first, &values);
50+
ASSERT_TRUE(s.IsOK());
2351
ASSERT_EQ(values.size(), 2);
2452
EXPECT_EQ(values[0], iter.first);
2553
EXPECT_EQ(values[1], iter.second);
2654
}
2755
ASSERT_TRUE(config.Rewrite().IsOK());
2856
config.Load(path);
29-
for (const auto &iter : cases) {
30-
config.Set(&srv, iter.first, iter.second);
57+
for (const auto &iter : mutable_cases) {
58+
auto s = config.Set(nullptr, iter.first, iter.second);
59+
ASSERT_TRUE(s.IsOK());
3160
config.Get(iter.first, &values);
3261
ASSERT_EQ(values.size(), 2);
3362
EXPECT_EQ(values[0], iter.first);
3463
EXPECT_EQ(values[1], iter.second);
3564
}
3665
unlink(path);
66+
67+
std::map<std::string, std::string> immutable_cases = {
68+
{"daemonize", "yes"},
69+
{"bind", "0.0.0.0"},
70+
{"repl-bind", "0.0.0.0"},
71+
{"workers", "8"},
72+
{"repl-workers", "8"},
73+
{"tcp-backlog", "500"},
74+
{"codis-enabled", "yes"},
75+
{"slaveof", "no one"},
76+
{"db-name", "test_dbname"},
77+
{"dir", "test_dir"},
78+
{"backup-dir", "test_dir/backup"},
79+
{"pidfile", "test.pid"},
80+
{"supervised", "no"},
81+
{"rocksdb.block_size", "1234"},
82+
{"rocksdb.target_file_size_base", "100"},
83+
{"rocksdb.max_background_flushes", "16"},
84+
{"rocksdb.wal_ttl_seconds", "10000"},
85+
{"rocksdb.wal_size_limit_mb", "16"},
86+
{"rocksdb.enable_pipelined_write", "no"},
87+
{"rocksdb.cache_index_and_filter_blocks", "no"},
88+
{"rocksdb.metadata_block_cache_size", "100"},
89+
{"rocksdb.subkey_block_cache_size", "100"},
90+
};
91+
for (const auto &iter : immutable_cases) {
92+
auto s = config.Set(nullptr, iter.first, iter.second);
93+
ASSERT_FALSE(s.IsOK());
94+
}
3795
}
3896

3997
TEST(Namespace, Add) {

0 commit comments

Comments
 (0)