-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
merge host info from kvstore #550
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,56 @@ TEST(ActiveHostsManTest, NormalTest) { | |
} | ||
} | ||
|
||
TEST(ActiveHostsManTest, NormalTest2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should give it more meaningful test name like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
fs::TempDir rootPath("/tmp/ActiveHostsMergeTest.XXXXXX"); | ||
std::unique_ptr<kvstore::KVStore> kv(TestUtils::initKV(rootPath.path())); | ||
{ | ||
std::vector<kvstore::KV> data; | ||
for (auto i = 0; i < 3; i++) { | ||
data.emplace_back(MetaServiceUtils::hostKey(0, i), | ||
MetaServiceUtils::hostValOnline()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alignment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
} | ||
kv->asyncMultiPut(kDefaultSpaceId, kDefaultPartId, std::move(data), | ||
[] (kvstore::ResultCode code) { | ||
CHECK_EQ(code, kvstore::ResultCode::SUCCEEDED); | ||
}); | ||
} | ||
|
||
int onlineNum = 0; | ||
int offlineNum = 0; | ||
const auto& prefix = MetaServiceUtils::hostPrefix(); | ||
std::unique_ptr<kvstore::KVIterator> iter; | ||
kv->prefix(kDefaultSpaceId, kDefaultPartId, prefix, &iter); | ||
while (iter->valid()) { | ||
if (iter->val() == MetaServiceUtils::hostValOnline()) { | ||
++onlineNum; | ||
} else { | ||
++offlineNum; | ||
} | ||
iter->next(); | ||
} | ||
ASSERT_EQ(3, onlineNum); | ||
ASSERT_EQ(0, offlineNum); | ||
|
||
ActiveHostsMan ahMan(1, 1, kv.get()); | ||
sleep(3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sleep(intervalSeconds + 1) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
onlineNum = 0; | ||
offlineNum = 0; | ||
kv->prefix(kDefaultSpaceId, kDefaultPartId, prefix, &iter); | ||
while (iter->valid()) { | ||
auto host = MetaServiceUtils::parseHostKey(iter->key()); | ||
LOG(INFO) << "ip: " << host.ip << ", port: " << host.port << ", status: " << iter->val(); | ||
if (iter->val() == MetaServiceUtils::hostValOnline()) { | ||
++onlineNum; | ||
} else { | ||
++offlineNum; | ||
} | ||
iter->next(); | ||
} | ||
ASSERT_EQ(0, onlineNum); | ||
ASSERT_EQ(3, offlineNum); | ||
} | ||
|
||
} // namespace meta | ||
} // namespace nebula | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alignment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed