fix json configuration remove
This commit is contained in:
parent
5a02a4c750
commit
28c22939ce
@ -8,7 +8,16 @@ bool Configuration::Has(const Slice &key) const {
|
||||
return GetRaw(key, &value);
|
||||
}
|
||||
|
||||
void Configuration::Remove(const Slice &key) {}
|
||||
void Configuration::Remove(const Slice &key) {
|
||||
UniqueLock<tile::Mutex> lock(mutex_);
|
||||
if (events_enabled_) {
|
||||
OnRemoving(key);
|
||||
}
|
||||
RemoveRaw(key);
|
||||
if (events_enabled_) {
|
||||
OnRemoved(key);
|
||||
}
|
||||
}
|
||||
|
||||
void Configuration::EnableEvents(bool enable) { events_enabled_ = enable; }
|
||||
bool Configuration::EventsEnabled() const { return events_enabled_; }
|
||||
|
@ -47,7 +47,7 @@ void JSONConfiguration::RemoveRaw(const Slice &key) {
|
||||
if (!FindStart(key, &last_part, &root)) {
|
||||
return;
|
||||
}
|
||||
root->removeMember(last_part.ToString());
|
||||
root->removeMember(last_part);
|
||||
}
|
||||
std::string JSONConfiguration::Dump() const {
|
||||
Configuration::ScopedLock _(*this);
|
||||
@ -82,8 +82,11 @@ bool JSONConfiguration::SetRaw(const Slice &key, const Slice &value) {
|
||||
}
|
||||
|
||||
Configuration::Keys JSONConfiguration::Enumerate(const Slice &range) const {
|
||||
Configuration::ScopedLock _(*this);
|
||||
Configuration::Keys key_set;
|
||||
std::string prefix = range;
|
||||
if (!prefix.empty()) {
|
||||
prefix += ".";
|
||||
}
|
||||
|
||||
auto keys = Split(range, '.');
|
||||
auto root = object_;
|
||||
@ -100,7 +103,7 @@ Configuration::Keys JSONConfiguration::Enumerate(const Slice &range) const {
|
||||
}
|
||||
|
||||
for (const auto &key : root.getMemberNames()) {
|
||||
key_set.push_back(key);
|
||||
key_set.push_back(prefix + key);
|
||||
}
|
||||
return key_set;
|
||||
}
|
||||
|
@ -73,4 +73,26 @@ TEST(JSONConfiguration, LayeredSet) {
|
||||
ASSERT_FALSE(*config.GetBool("key5.key52")) << config.Dump();
|
||||
}
|
||||
|
||||
TEST(json_configuration, Enumerate) {
|
||||
JSONConfiguration config;
|
||||
std::istringstream istr(kJsonConfig);
|
||||
ASSERT_TRUE(config.load(istr));
|
||||
auto keys = config.keys("");
|
||||
ASSERT_EQ(5, keys.size());
|
||||
ASSERT_EQ("key1", keys[0]);
|
||||
ASSERT_EQ("key2", keys[1]);
|
||||
ASSERT_EQ("key3", keys[2]);
|
||||
ASSERT_EQ("key4", keys[3]);
|
||||
ASSERT_EQ("key5", keys[4]);
|
||||
|
||||
keys = config.keys("key5");
|
||||
ASSERT_EQ(2, keys.size());
|
||||
ASSERT_EQ("key5.key51", keys[0]);
|
||||
ASSERT_EQ("key5.key52", keys[1]);
|
||||
|
||||
config.Remove("key5.key51");
|
||||
keys = config.keys("key5");
|
||||
ASSERT_EQ("key5.key52", keys[0]);
|
||||
}
|
||||
|
||||
} // namespace tile
|
||||
|
Loading…
Reference in New Issue
Block a user